blob: 44dbc15523fcee41bb920a8ab48c1058fa77fadc [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070026import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.Dialog;
29import android.app.SearchManager;
30import android.app.StatusBarManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070031import android.appwidget.AppWidgetManager;
32import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080034import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070035import android.content.ClipData;
36import android.content.ClipDescription;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040037import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080038import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
40import android.content.DialogInterface;
41import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070042import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070043import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070044import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070046import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070048import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080049import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070050import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070051import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040052import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070053import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020055import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080056import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070057import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040058import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080059import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070060import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080061import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.text.Selection;
63import android.text.SpannableStringBuilder;
64import android.text.TextUtils;
65import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070066import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080067import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080068import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.view.KeyEvent;
70import android.view.LayoutInflater;
71import android.view.Menu;
72import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070073import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080074import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.View;
Adam Cohen860f4c52011-01-27 20:16:13 -080076import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070077import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080078import android.view.accessibility.AccessibilityEvent;
Adam Cohenf16e5712011-01-13 13:31:45 -080079import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070081import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070083import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070084import android.widget.TextView;
85import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070086
Adam Cohendf2cc412011-04-27 16:56:57 -070087import com.android.common.Search;
88import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070089import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080090
Adam Cohenc0dcf592011-06-01 15:30:43 -070091import java.io.DataInputStream;
92import java.io.DataOutputStream;
93import java.io.FileNotFoundException;
94import java.io.IOException;
95import java.util.ArrayList;
96import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -070097
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098/**
99 * Default launcher application.
100 */
Michael Jurka946ad472010-07-09 18:05:18 -0700101public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700102 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
103 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800104 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700105 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
Joe Onorato9c1289c2009-08-17 11:03:03 -0400107 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400108 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700109
Winson Chung70d72102011-08-12 11:24:35 -0700110 private static final int MENU_GROUP_WALLPAPER = 1;
111 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
112 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700113 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
114 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
116 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700117 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118 private static final int REQUEST_PICK_APPLICATION = 6;
119 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700120 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700121 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
123 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
124
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800125 static final int SCREEN_COUNT = 5;
126 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127
Joe Onorato7c312c12009-08-13 21:36:53 -0700128 static final int DIALOG_CREATE_SHORTCUT = 1;
129 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
Romain Guy98d01652009-06-30 16:21:04 -0700131 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 // Type: int
134 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700135 // Type: int
136 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700138 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
139 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
141 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700142 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700144 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145 // Type: boolean
146 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
147 // Type: long
148 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
149
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700150 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
151
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700152 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700153 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700154 private State mState = State.WORKSPACE;
155 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700156
Joe Onorato9c1289c2009-08-17 11:03:03 -0400157 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700158 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
159 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung82f55532011-08-09 14:14:23 -0700160 private static final int DISMISS_CLING_DURATION = 300;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800163 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800165 private final BroadcastReceiver mCloseSystemDialogsReceiver
166 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800167 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
168
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 private LayoutInflater mInflater;
170
Joe Onorato00acb122009-08-04 16:04:30 -0400171 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700173
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700174 private AppWidgetManager mAppWidgetManager;
175 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700176
Winson Chung3d503fb2011-07-13 17:25:49 -0700177 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700178 private int[] mTmpAddItemCellCoordinates = new int[2];
179
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 private FolderInfo mFolderInfo;
181
Winson Chung3d503fb2011-07-13 17:25:49 -0700182 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800183 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700184
Winson Chungf0ea4d32011-06-06 14:27:16 -0700185 private SearchDropTargetBar mSearchDeleteBar;
186 private AppsCustomizeTabHost mAppsCustomizeTabHost;
187 private AppsCustomizePagedView mAppsCustomizeContent;
188 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 private Bundle mSavedState;
191
192 private SpannableStringBuilder mDefaultKeySsb = null;
193
Joe Onorato9c1289c2009-08-17 11:03:03 -0400194 private boolean mWorkspaceLoading = true;
195
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800196 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197 private boolean mRestoring;
198 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700199 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200
201 private Bundle mSavedInstanceState;
202
Joe Onorato9c1289c2009-08-17 11:03:03 -0400203 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800204 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800205 private boolean mUserPresent = true;
206 private boolean mVisible = false;
207 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400208
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700209 private static LocaleConfiguration sLocaleConfiguration = null;
210
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700211 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700212
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700213 private Intent mAppMarketIntent = null;
214
Adam Cohended9f8d2010-11-03 13:25:16 -0700215 // Related to the auto-advancing of widgets
216 private final int ADVANCE_MSG = 1;
217 private final int mAdvanceInterval = 20000;
218 private final int mAdvanceStagger = 250;
219 private long mAutoAdvanceSentTime;
220 private long mAutoAdvanceTimeLeft = -1;
221 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
222 new HashMap<View, AppWidgetProviderInfo>();
223
Winson Chung400438b2011-01-16 17:53:48 -0800224 // Determines how long to wait after a rotation before restoring the screen orientation to
225 // match the sensor state.
226 private final int mRestoreScreenOrientationDelay = 500;
227
Michael Jurka4ef207b2010-11-29 17:05:45 -0800228 // External icons saved in case of resource changes, orientation, etc.
Michael Jurkae7bf83b2010-12-14 18:02:21 -0800229 private static Drawable.ConstantState sGlobalSearchIcon;
230 private static Drawable.ConstantState sVoiceSearchIcon;
231 private static Drawable.ConstantState sAppMarketIcon;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800232
Adam Cohen2801caf2011-05-13 20:57:39 -0700233 private DragLayer mDragLayer;
234
Michael Jurkaddd62e92011-02-16 17:49:14 -0800235 private BubbleTextView mWaitingForResume;
236
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800237 private static ArrayList<PendingAddArguments> sPendingAddList
238 = new ArrayList<PendingAddArguments>();
239
240 private static class PendingAddArguments {
241 int requestCode;
242 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700243 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800244 int screen;
245 int cellX;
246 int cellY;
247 }
248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 @Override
250 protected void onCreate(Bundle savedInstanceState) {
251 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800252 LauncherApplication app = ((LauncherApplication)getApplication());
253 mModel = app.setLauncher(this);
254 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400255 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700257
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700258 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
260 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700261
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200263 android.os.Debug.startMethodTracing(
264 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 }
266
267 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 setContentView(R.layout.launcher);
269 setupViews();
Winson Chung82f55532011-08-09 14:14:23 -0700270 enableClingsIfNecessary();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800272 registerContentObservers();
273
Joe Onorato7c312c12009-08-13 21:36:53 -0700274 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700275
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 mSavedState = savedInstanceState;
277 restoreState(mSavedState);
278
Winson Chunga12a2502010-12-20 14:41:35 -0800279 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700280 if (mAppsCustomizeContent != null) {
281 mAppsCustomizeContent.onPackagesUpdated();
282 }
Winson Chunga12a2502010-12-20 14:41:35 -0800283
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 if (PROFILE_STARTUP) {
285 android.os.Debug.stopMethodTracing();
286 }
287
288 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 }
291
Michael Jurkac57b7a82011-08-09 22:02:20 -0700292 if (!mModel.isAllAppsLoaded()) {
293 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
294 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
295 }
296
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297 // For handling default keys
298 mDefaultKeySsb = new SpannableStringBuilder();
299 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800300
301 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
302 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
304 // If we have a saved version of these external icons, we load them up immediately
Winson Chungf0ea4d32011-06-06 14:27:16 -0700305 if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) {
306 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100307 updateGlobalSearchIcon();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700308 }
309 if (sGlobalSearchIcon != null) {
310 updateGlobalSearchIcon(sGlobalSearchIcon);
311 }
312 if (sVoiceSearchIcon != null) {
313 updateVoiceSearchIcon(sVoiceSearchIcon);
314 }
315 if (sAppMarketIcon != null) {
316 updateAppMarketIcon(sAppMarketIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800318 }
Romain Guycbb89e42009-06-08 15:52:54 -0700319
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800320 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700321 if (sLocaleConfiguration == null) {
322 new AsyncTask<Void, Void, LocaleConfiguration>() {
323 @Override
324 protected LocaleConfiguration doInBackground(Void... unused) {
325 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
326 readConfiguration(Launcher.this, localeConfiguration);
327 return localeConfiguration;
328 }
329
330 @Override
331 protected void onPostExecute(LocaleConfiguration result) {
332 sLocaleConfiguration = result;
333 checkForLocaleChange(); // recursive, but now with a locale configuration
334 }
335 }.execute();
336 return;
337 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700338
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800339 final Configuration configuration = getResources().getConfiguration();
340
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700341 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 final String locale = configuration.locale.toString();
343
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700344 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 final int mcc = configuration.mcc;
346
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700347 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348 final int mnc = configuration.mnc;
349
Romain Guy84f296c2009-11-04 15:00:44 -0800350 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351
Romain Guy84f296c2009-11-04 15:00:44 -0800352 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700353 sLocaleConfiguration.locale = locale;
354 sLocaleConfiguration.mcc = mcc;
355 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700356
Joe Onorato0589f0f2010-02-08 13:44:00 -0800357 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700358
359 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
360 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700361 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700362 public void run() {
363 writeConfiguration(Launcher.this, localeConfiguration);
364 }
365 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700366 }
367 }
368
369 private static class LocaleConfiguration {
370 public String locale;
371 public int mcc = -1;
372 public int mnc = -1;
373 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700374
Romain Guy98d01652009-06-30 16:21:04 -0700375 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
376 DataInputStream in = null;
377 try {
378 in = new DataInputStream(context.openFileInput(PREFERENCES));
379 configuration.locale = in.readUTF();
380 configuration.mcc = in.readInt();
381 configuration.mnc = in.readInt();
382 } catch (FileNotFoundException e) {
383 // Ignore
384 } catch (IOException e) {
385 // Ignore
386 } finally {
387 if (in != null) {
388 try {
389 in.close();
390 } catch (IOException e) {
391 // Ignore
392 }
393 }
394 }
395 }
396
397 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
398 DataOutputStream out = null;
399 try {
400 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
401 out.writeUTF(configuration.locale);
402 out.writeInt(configuration.mcc);
403 out.writeInt(configuration.mnc);
404 out.flush();
405 } catch (FileNotFoundException e) {
406 // Ignore
407 } catch (IOException e) {
408 //noinspection ResultOfMethodCallIgnored
409 context.getFileStreamPath(PREFERENCES).delete();
410 } finally {
411 if (out != null) {
412 try {
413 out.close();
414 } catch (IOException e) {
415 // Ignore
416 }
417 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 }
419 }
420
Adam Cohen716b51e2011-06-30 12:09:54 -0700421 public DragLayer getDragLayer() {
422 return mDragLayer;
423 }
424
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 static int getScreen() {
426 synchronized (sLock) {
427 return sScreen;
428 }
429 }
430
431 static void setScreen(int screen) {
432 synchronized (sLock) {
433 sScreen = screen;
434 }
435 }
436
Winson Chung557d6ed2011-07-08 15:34:52 -0700437 /**
438 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
439 * a configuration step, this allows the proper animations to run after other transitions.
440 */
441 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700442 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800443 switch (args.requestCode) {
444 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700445 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
446 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800447 break;
448 case REQUEST_PICK_SHORTCUT:
449 processShortcut(args.intent);
450 break;
451 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700452 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
453 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700454 result = true;
455 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800456 case REQUEST_PICK_APPWIDGET:
457 addAppWidgetFromPick(args.intent);
458 break;
459 case REQUEST_CREATE_APPWIDGET:
460 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700461 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700462 result = true;
463 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800464 case REQUEST_PICK_WALLPAPER:
465 // We just wanted the activity result here so we can clear mWaitingForResult
466 break;
467 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700468 // In any situation where we have a multi-step drop, we should reset the add info only after
469 // we complete the drop
470 resetAddInfo();
471 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800472 }
473
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800475 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700476 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700477 mWaitingForResult = false;
478
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800479 // The pattern used here is that a user PICKs a specific application,
480 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700481
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800482 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
483 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700484 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800485 final PendingAddArguments args = new PendingAddArguments();
486 args.requestCode = requestCode;
487 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700488 args.container = mPendingAddInfo.container;
489 args.screen = mPendingAddInfo.screen;
490 args.cellX = mPendingAddInfo.cellX;
491 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800492
493 // If the loader is still running, defer the add until it is done.
494 if (isWorkspaceLocked()) {
495 sPendingAddList.add(args);
496 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700497 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 }
Romain Guy18042c82009-11-06 11:44:55 -0800499 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700500 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
501 if (data != null) {
502 // Clean up the appWidgetId if we canceled
503 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
504 if (appWidgetId != -1) {
505 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
506 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800507 }
508 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700509
510 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700511 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800512 }
513
514 @Override
515 protected void onResume() {
516 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800517 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700518 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400519 mWorkspaceLoading = true;
520 mModel.startLoader(this, true);
521 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700522 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800523 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800524 if (mWaitingForResume != null) {
525 mWaitingForResume.setStayPressed(false);
526 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700527 // When we resume Launcher, a different Activity might be responsible for the app
528 // market intent, so refresh the icon
529 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 }
531
532 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700533 protected void onPause() {
534 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700535 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800536 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700537 }
Romain Guycbb89e42009-06-08 15:52:54 -0700538
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700539 @Override
540 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400541 // Flag the loader to stop early before switching
542 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700543 if (mAppsCustomizeContent != null) {
544 mAppsCustomizeContent.surrender();
545 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800546 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700547 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700548
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800549 // We can't hide the IME if it was forced open. So don't bother
550 /*
551 @Override
552 public void onWindowFocusChanged(boolean hasFocus) {
553 super.onWindowFocusChanged(hasFocus);
554
555 if (hasFocus) {
556 final InputMethodManager inputManager = (InputMethodManager)
557 getSystemService(Context.INPUT_METHOD_SERVICE);
558 WindowManager.LayoutParams lp = getWindow().getAttributes();
559 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
560 android.os.Handler()) {
561 protected void onReceiveResult(int resultCode, Bundle resultData) {
562 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
563 }
564 });
565 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
566 }
567 }
568 */
569
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570 private boolean acceptFilter() {
571 final InputMethodManager inputManager = (InputMethodManager)
572 getSystemService(Context.INPUT_METHOD_SERVICE);
573 return !inputManager.isFullscreenMode();
574 }
575
576 @Override
577 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700578 final int uniChar = event.getUnicodeChar();
579 final boolean handled = super.onKeyDown(keyCode, event);
580 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
581 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
583 keyCode, event);
584 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700585 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700586 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700587 // showSearchDialog()
588 // If there are multiple keystrokes before the search dialog takes focus,
589 // onSearchRequested() will be called for every keystroke,
590 // but it is idempotent, so it's fine.
591 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 }
593 }
594
Joe Onorato8a9625e2010-01-28 15:55:35 -0800595 // Eat the long press event so the keyboard doesn't come up.
596 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
597 return true;
598 }
599
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 return handled;
601 }
602
Karl Rosaen138a0412009-04-23 19:00:21 -0700603 private String getTypedText() {
604 return mDefaultKeySsb.toString();
605 }
606
607 private void clearTypedText() {
608 mDefaultKeySsb.clear();
609 mDefaultKeySsb.clearSpans();
610 Selection.setSelection(mDefaultKeySsb, 0);
611 }
612
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800613 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700614 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
615 * State
616 */
617 private static State intToState(int stateOrdinal) {
618 State state = State.WORKSPACE;
619 final State[] stateValues = State.values();
620 for (int i = 0; i < stateValues.length; i++) {
621 if (stateValues[i].ordinal() == stateOrdinal) {
622 state = stateValues[i];
623 break;
624 }
625 }
626 return state;
627 }
628
629 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 * Restores the previous state, if it exists.
631 *
632 * @param savedState The previous state.
633 */
634 private void restoreState(Bundle savedState) {
635 if (savedState == null) {
636 return;
637 }
638
Michael Jurka883f55b2010-10-21 15:47:14 -0700639 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700640 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800641 showAllApps(false);
642 }
643
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800644 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
645 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700646 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800647 }
648
Winson Chung3d503fb2011-07-13 17:25:49 -0700649 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
650 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700651
Winson Chung3d503fb2011-07-13 17:25:49 -0700652 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
653 mPendingAddInfo.container = pendingAddContainer;
654 mPendingAddInfo.screen = pendingAddScreen;
655 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
656 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 mRestoring = true;
658 }
659
660 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
661 if (renameFolder) {
662 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700663 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800664 mRestoring = true;
665 }
Winson Chunga12a2502010-12-20 14:41:35 -0800666
Winson Chung785d2eb2011-04-14 16:08:02 -0700667
668 // Restore the AppsCustomize tab
669 if (mAppsCustomizeTabHost != null) {
670 String curTab = savedState.getString("apps_customize_currentTab");
671 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700672 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700673 mAppsCustomizeContent.setContentType(
674 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
675 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700676 mAppsCustomizeContent.loadAssociatedPages(
677 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700678 }
679
Winson Chung5afbf7b2011-07-25 11:53:08 -0700680 int currentIndex = savedState.getInt("apps_customize_currentIndex");
681 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700682 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 }
684
685 /**
686 * Finds all the views we need and configure them properly.
687 */
688 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700689 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400690
Winson Chung4c98d922011-05-31 16:50:48 -0700691 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
692 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693
Winson Chung4c98d922011-05-31 16:50:48 -0700694 // Setup the drag layer
695 mDragLayer.setup(this, dragController);
696
Winson Chung3d503fb2011-07-13 17:25:49 -0700697 // Setup the hotseat
698 mHotseat = (Hotseat) findViewById(R.id.hotseat);
699 if (mHotseat != null) {
700 mHotseat.setup(this);
701 }
702
Winson Chung4c98d922011-05-31 16:50:48 -0700703 // Setup the workspace
704 mWorkspace.setHapticFeedbackEnabled(false);
705 mWorkspace.setOnLongClickListener(this);
706 mWorkspace.setup(this, dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700707 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700708
Winson Chungf0ea4d32011-06-06 14:27:16 -0700709 // Get the search/delete bar
710 mSearchDeleteBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700711
Winson Chungf0ea4d32011-06-06 14:27:16 -0700712 // Setup AppsCustomize
713 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
714 findViewById(R.id.apps_customize_pane);
715 mAppsCustomizeContent = (AppsCustomizePagedView)
716 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
717 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400718
Romain Guy1fbc1c82009-11-09 20:43:08 -0800719
Winson Chung4c98d922011-05-31 16:50:48 -0700720
Winson Chung3d503fb2011-07-13 17:25:49 -0700721 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700722 dragController.setDragScoller(mWorkspace);
723 dragController.setScrollView(mDragLayer);
724 dragController.setMoveTarget(mWorkspace);
725 dragController.addDropTarget(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700726 if (mSearchDeleteBar != null) {
727 mSearchDeleteBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800728 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800729 }
730
Romain Guy8a73c512009-11-09 19:19:59 -0800731
Winson Chungaafa03c2010-06-11 17:34:16 -0700732
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800733 /**
734 * Creates a view representing a shortcut.
735 *
736 * @param info The data structure describing the shortcut.
737 *
738 * @return A View inflated from R.layout.application.
739 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800740 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800741 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700742 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800743 }
744
745 /**
746 * Creates a view representing a shortcut inflated from the specified resource.
747 *
748 * @param layoutResId The id of the XML layout used to create the shortcut.
749 * @param parent The group the shortcut belongs to.
750 * @param info The data structure describing the shortcut.
751 *
752 * @return A View inflated from layoutResId.
753 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800754 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800755 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
756 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 return favorite;
759 }
760
761 /**
762 * Add an application shortcut to the workspace.
763 *
764 * @param data The intent describing the application.
765 * @param cellInfo The position on screen where to create the shortcut.
766 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700767 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700768 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700769 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700770
Adam Cohenfbba09b2011-07-18 21:43:05 -0700771 // First we check if we already know the exact location where we want to add this item.
772 if (cellX >= 0 && cellY >= 0) {
773 cellXY[0] = cellX;
774 cellXY[1] = cellY;
775 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700776 showOutOfSpaceMessage();
777 return;
778 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800779
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800780 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800781
Romain Guy73b979d2009-06-09 12:57:21 -0700782 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800783 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800784 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800785 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700786 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700787 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800788 } else {
789 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800790 }
791 }
Romain Guycbb89e42009-06-08 15:52:54 -0700792
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800793 /**
794 * Add a shortcut to the workspace.
795 *
796 * @param data The intent describing the shortcut.
797 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800798 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700799 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
800 int cellY) {
801 int[] cellXY = mTmpAddItemCellCoordinates;
802 int[] touchXY = mPendingAddInfo.dropPos;
803 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700804
Michael Jurkad3ef3062010-11-23 16:23:58 -0800805 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700806
Adam Cohen558baaf2011-08-15 15:22:57 -0700807 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
808 final View view = createShortcut(info);
809
Adam Cohenfbba09b2011-07-18 21:43:05 -0700810 // First we check if we already know the exact location where we want to add this item.
811 if (cellX >= 0 && cellY >= 0) {
812 cellXY[0] = cellX;
813 cellXY[1] = cellY;
814 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700815
816 // If appropriate, either create a folder or add to an existing folder
817 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
818 true, null,null)) {
819 return;
820 }
821 DragObject dragObject = new DragObject();
822 dragObject.dragInfo = info;
823 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
824 return;
825 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700826 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800827 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700828 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800829 foundCellSpan = (result != null);
830 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700831 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800832 }
833
834 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700835 showOutOfSpaceMessage();
836 return;
837 }
838
Adam Cohen558baaf2011-08-15 15:22:57 -0700839 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840
841 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700842 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
843 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 }
845 }
846
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700848 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700850 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700851 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800852 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700853 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700854 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700855
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700856 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700857 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700858
859 // We want to account for the extra amount of padding that we are adding to the widget
860 // to ensure that it gets the full amount of space that it has requested
861 Resources r = getResources();
862 int requiredWidth = appWidgetInfo.minWidth +
863 r.getDimensionPixelSize(R.dimen.app_widget_padding_left) +
864 r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
865 int requiredHeight = appWidgetInfo.minHeight +
866 r.getDimensionPixelSize(R.dimen.app_widget_padding_top) +
867 r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
868 int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700869
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800870 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700871 // We have saved the position to which the widget was dragged-- this really only matters
872 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700873 int[] cellXY = mTmpAddItemCellCoordinates;
874 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700875 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700876 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
877 cellXY[0] = mPendingAddInfo.cellX;
878 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700879 foundCellSpan = true;
880 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700881 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700882 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700883 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800884 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700885 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700886 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700887 }
888
Michael Jurka0280c3b2010-09-17 15:00:07 -0700889 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800890 if (appWidgetId != -1) {
891 // Deleting an app widget ID is a void call but writes to disk before returning
892 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800893 new Thread("deleteAppWidgetId") {
894 public void run() {
895 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
896 }
897 }.start();
898 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700899 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800900 return;
901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700903 // Build Launcher-specific widget info and save to database
904 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700905 launcherInfo.spanX = spanXY[0];
906 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700907
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700909 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800910
911 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800912 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700913 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700914
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700915 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700917
Winson Chung3d503fb2011-07-13 17:25:49 -0700918 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400919 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700920
921 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 }
923 }
Romain Guycbb89e42009-06-08 15:52:54 -0700924
Adam Cohended9f8d2010-11-03 13:25:16 -0700925 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
926 @Override
927 public void onReceive(Context context, Intent intent) {
928 final String action = intent.getAction();
929 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
930 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700931 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700932 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -0700933
Winson Chungc100e8e2011-08-09 16:02:43 -0700934 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -0700935 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -0700936 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
937 mAppsCustomizeTabHost.reset();
938 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -0700939 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700940 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
941 mUserPresent = true;
942 updateRunning();
943 }
944 }
945 };
946
947 @Override
948 public void onAttachedToWindow() {
949 super.onAttachedToWindow();
950
951 // Listen for broadcasts related to user-presence
952 final IntentFilter filter = new IntentFilter();
953 filter.addAction(Intent.ACTION_SCREEN_OFF);
954 filter.addAction(Intent.ACTION_USER_PRESENT);
955 registerReceiver(mReceiver, filter);
956
Adam Cohend113e0c2010-11-11 10:48:05 -0800957 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -0700958 mVisible = true;
959 }
960
961 @Override
962 public void onDetachedFromWindow() {
963 super.onDetachedFromWindow();
964 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700965 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700966
Adam Cohend113e0c2010-11-11 10:48:05 -0800967 if (mAttached) {
968 unregisterReceiver(mReceiver);
969 mAttached = false;
970 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700971 updateRunning();
972 }
973
974 public void onWindowVisibilityChanged(int visibility) {
975 mVisible = visibility == View.VISIBLE;
976 updateRunning();
977 }
978
979 private void sendAdvanceMessage(long delay) {
980 mHandler.removeMessages(ADVANCE_MSG);
981 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
982 mHandler.sendMessageDelayed(msg, delay);
983 mAutoAdvanceSentTime = System.currentTimeMillis();
984 }
985
986 private void updateRunning() {
987 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
988 if (autoAdvanceRunning != mAutoAdvanceRunning) {
989 mAutoAdvanceRunning = autoAdvanceRunning;
990 if (autoAdvanceRunning) {
991 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
992 sendAdvanceMessage(delay);
993 } else {
994 if (!mWidgetsToAdvance.isEmpty()) {
995 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
996 (System.currentTimeMillis() - mAutoAdvanceSentTime));
997 }
998 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -0800999 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001000 }
1001 }
1002 }
1003
1004 private final Handler mHandler = new Handler() {
1005 @Override
1006 public void handleMessage(Message msg) {
1007 if (msg.what == ADVANCE_MSG) {
1008 int i = 0;
1009 for (View key: mWidgetsToAdvance.keySet()) {
1010 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1011 final int delay = mAdvanceStagger * i;
1012 if (v instanceof Advanceable) {
1013 postDelayed(new Runnable() {
1014 public void run() {
1015 ((Advanceable) v).advance();
1016 }
1017 }, delay);
1018 }
1019 i++;
1020 }
1021 sendAdvanceMessage(mAdvanceInterval);
1022 }
1023 }
1024 };
1025
1026 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001027 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001028 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1029 if (v instanceof Advanceable) {
1030 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001031 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001032 updateRunning();
1033 }
1034 }
1035
1036 void removeWidgetToAutoAdvance(View hostView) {
1037 if (mWidgetsToAdvance.containsKey(hostView)) {
1038 mWidgetsToAdvance.remove(hostView);
1039 updateRunning();
1040 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001041 }
1042
Joe Onorato9c1289c2009-08-17 11:03:03 -04001043 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001044 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001045 launcherInfo.hostView = null;
1046 }
1047
Adam Cohended9f8d2010-11-03 13:25:16 -07001048 void showOutOfSpaceMessage() {
1049 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1050 }
1051
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001052 public LauncherAppWidgetHost getAppWidgetHost() {
1053 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 }
Romain Guycbb89e42009-06-08 15:52:54 -07001055
Winson Chunga9abd0e2010-10-27 17:18:37 -07001056 public LauncherModel getModel() {
1057 return mModel;
1058 }
1059
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001060 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001061 getWindow().closeAllPanels();
1062
1063 try {
1064 dismissDialog(DIALOG_CREATE_SHORTCUT);
1065 // Unlock the workspace if the dialog was showing
1066 } catch (Exception e) {
1067 // An exception is thrown if the dialog is not visible, which is fine
1068 }
1069
1070 try {
1071 dismissDialog(DIALOG_RENAME_FOLDER);
1072 // Unlock the workspace if the dialog was showing
1073 } catch (Exception e) {
1074 // An exception is thrown if the dialog is not visible, which is fine
1075 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001076
1077 // Whatever we were doing is hereby canceled.
1078 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001079 }
1080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 @Override
1082 protected void onNewIntent(Intent intent) {
1083 super.onNewIntent(intent);
1084
1085 // Close the menu
1086 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001087 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001088 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001089
Adam Cohen95bb8002011-07-03 23:40:28 -07001090 closeFolder();
1091
Joe Onorato14f122b2009-11-19 14:06:36 -08001092 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1093 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001094
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001095 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001096 mWorkspace.exitWidgetResizeMode();
Patrick Dubroya0aa0122011-02-24 11:42:23 -08001097 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001098 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001099 }
Winson Chungde1af762011-07-21 16:44:07 -07001100 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001101 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001102
Joe Onorato3a8820b2009-11-10 15:06:42 -08001103 final View v = getWindow().peekDecorView();
1104 if (v != null && v.getWindowToken() != null) {
1105 InputMethodManager imm = (InputMethodManager)getSystemService(
1106 INPUT_METHOD_SERVICE);
1107 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001109
Michael Jurka35aa14d2011-07-07 17:01:08 -07001110 // Reset AllApps to its initial state
Winson Chungc100e8e2011-08-09 16:02:43 -07001111 if (mAppsCustomizeTabHost != null) {
1112 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001113 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001114 }
1115 }
1116
1117 @Override
1118 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1119 // Do not call super here
1120 mSavedInstanceState = savedInstanceState;
1121 }
1122
1123 @Override
1124 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001125 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001126 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127
Michael Jurka883f55b2010-10-21 15:47:14 -07001128 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001129 // We close any open folder since it will not be re-opened, and we need to make sure
1130 // this state is reflected.
1131 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132
Winson Chung3d503fb2011-07-13 17:25:49 -07001133 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1134 mWaitingForResult) {
1135 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1136 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1137 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1138 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 }
1140
1141 if (mFolderInfo != null && mWaitingForResult) {
1142 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1143 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1144 }
Michael Jurka946ad472010-07-09 18:05:18 -07001145
Winson Chung785d2eb2011-04-14 16:08:02 -07001146 // Save the current AppsCustomize tab
1147 if (mAppsCustomizeTabHost != null) {
1148 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1149 if (currentTabTag != null) {
1150 outState.putString("apps_customize_currentTab", currentTabTag);
1151 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001152 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1153 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001154 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001155 }
1156
1157 @Override
1158 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001160
Winson Chunge7a03942011-08-05 15:05:12 -07001161 // Remove all pending runnables
1162 mHandler.removeMessages(ADVANCE_MSG);
1163 mHandler.removeMessages(0);
1164
Winson Chungcd2b0142011-06-08 16:02:26 -07001165 // Stop callbacks from LauncherModel
1166 LauncherApplication app = ((LauncherApplication) getApplication());
1167 mModel.stopLoader();
1168 app.setLauncher(null);
1169
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001170 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001171 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001172 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001173 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001174 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001175 mAppWidgetHost = null;
1176
1177 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178
1179 TextKeyListener.getInstance().release();
1180
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001183
1184 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001185 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001186
1187 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1188 mWorkspace.removeAllViews();
1189 mWorkspace = null;
1190 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001191
1192 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193 }
1194
Adam Cohena9cf38f2011-05-02 15:36:58 -07001195 public DragController getDragController() {
1196 return mDragController;
1197 }
1198
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001199 @Override
1200 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001201 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 super.startActivityForResult(intent, requestCode);
1203 }
1204
Winson Chung70d72102011-08-12 11:24:35 -07001205 /**
1206 * Indicates that we want global search for this activity by setting the globalSearch
1207 * argument for {@link #startSearch} to true.
1208 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001210 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001212
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001213 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001214
Karl Rosaen138a0412009-04-23 19:00:21 -07001215 if (initialQuery == null) {
1216 // Use any text typed in the launcher as the initial query
1217 initialQuery = getTypedText();
1218 clearTypedText();
1219 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 if (appSearchData == null) {
1221 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001222 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223 }
Romain Guycbb89e42009-06-08 15:52:54 -07001224
Karl Rosaen138a0412009-04-23 19:00:21 -07001225 final SearchManager searchManager =
1226 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001227 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001228 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 }
1230
Winson Chung70d72102011-08-12 11:24:35 -07001231 @Override
1232 public boolean onCreateOptionsMenu(Menu menu) {
1233 if (isWorkspaceLocked()) {
1234 return false;
1235 }
1236
1237 super.onCreateOptionsMenu(menu);
Winson Chung236d4312011-08-22 15:12:27 -07001238 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1239 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1240 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Winson Chung70d72102011-08-12 11:24:35 -07001241 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1242 .setIcon(android.R.drawable.ic_menu_gallery)
1243 .setAlphabeticShortcut('W');
1244 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1245 .setIcon(android.R.drawable.ic_menu_manage)
1246 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001247 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1248 .setIcon(android.R.drawable.ic_menu_preferences)
1249 .setIntent(settings)
1250 .setAlphabeticShortcut('P');
Winson Chung70d72102011-08-12 11:24:35 -07001251 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1252 .setIcon(android.R.drawable.ic_menu_help)
1253 .setAlphabeticShortcut('H');
1254 return true;
1255 }
1256
1257 @Override
1258 public boolean onPrepareOptionsMenu(Menu menu) {
1259 super.onPrepareOptionsMenu(menu);
1260
1261 if (mAppsCustomizeTabHost.isTransitioning()) {
1262 return false;
1263 }
1264 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1265 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1266
1267 return true;
1268 }
1269
1270 @Override
1271 public boolean onOptionsItemSelected(MenuItem item) {
1272 switch (item.getItemId()) {
1273 case MENU_WALLPAPER_SETTINGS:
1274 startWallpaper();
1275 return true;
1276 case MENU_MANAGE_APPS:
1277 manageApps();
1278 return true;
1279 case MENU_HELP:
1280 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help_url))));
1281 return true;
1282 }
1283
1284 return super.onOptionsItemSelected(item);
1285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001287 @Override
1288 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001289 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001290 // Use a custom animation for launching search
1291 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001292 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001293 }
1294
Joe Onorato9c1289c2009-08-17 11:03:03 -04001295 public boolean isWorkspaceLocked() {
1296 return mWorkspaceLoading || mWaitingForResult;
1297 }
1298
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 private void addItems() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001300 showWorkspace(true);
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301 showAddDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 }
1303
Michael Jurka0280c3b2010-09-17 15:00:07 -07001304 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001305 mPendingAddInfo.container = ItemInfo.NO_ID;
1306 mPendingAddInfo.screen = -1;
1307 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1308 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1309 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001310 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001311
Winson Chung7ad01412010-09-27 11:33:03 -07001312 private void manageApps() {
1313 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1314 }
1315
Michael Jurkaaf442092010-06-10 17:01:57 -07001316 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001317 // TODO: catch bad widget exception when sent
1318 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001319 // TODO: Is this log message meaningful?
1320 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001321 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001322 }
1323
Winson Chung55cef262010-10-28 14:14:18 -07001324 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001325 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326
Bjorn Bringert7984c942009-12-09 15:38:25 +00001327 if (appWidget.configure != null) {
1328 // Launch over to configure widget, if needed
1329 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1330 intent.setComponent(appWidget.configure);
1331 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001332 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001333 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1334 intent.putExtra(
1335 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1336 info.mimeType);
1337
1338 final String mimeType = info.mimeType;
1339 final ClipData clipData = (ClipData) info.configurationData;
1340 final ClipDescription clipDesc = clipData.getDescription();
1341 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1342 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001343 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001344 final CharSequence stringData = item.getText();
1345 final Uri uriData = item.getUri();
1346 final Intent intentData = item.getIntent();
1347 final String key =
1348 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1349 if (uriData != null) {
1350 intent.putExtra(key, uriData);
1351 } else if (intentData != null) {
1352 intent.putExtra(key, intentData);
1353 } else if (stringData != null) {
1354 intent.putExtra(key, stringData);
1355 }
1356 break;
1357 }
1358 }
1359 }
Winson Chung55cef262010-10-28 14:14:18 -07001360 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001361
Romain Guy8e633c52010-03-04 12:51:36 -08001362 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001364 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001365 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001366
1367 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001368 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 }
1370 }
Romain Guycbb89e42009-06-08 15:52:54 -07001371
Adam Cohenfbba09b2011-07-18 21:43:05 -07001372 /**
1373 * Process a shortcut drop.
1374 *
1375 * @param componentName The name of the component
1376 * @param screen The screen where it should be added
1377 * @param cell The cell it should be added to, optional
1378 * @param position The location on the screen where it was dropped, optional
1379 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1381 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001382 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001383 mPendingAddInfo.container = container;
1384 mPendingAddInfo.screen = screen;
1385 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001386
1387 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001388 mPendingAddInfo.cellX = cell[0];
1389 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001390 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001391
1392 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1393 createShortcutIntent.setComponent(componentName);
1394 processShortcut(createShortcutIntent);
1395 }
1396
Adam Cohenfbba09b2011-07-18 21:43:05 -07001397 /**
1398 * Process a widget drop.
1399 *
1400 * @param info The PendingAppWidgetInfo of the widget being added.
1401 * @param screen The screen where it should be added
1402 * @param cell The cell it should be added to, optional
1403 * @param position The location on the screen where it was dropped, optional
1404 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001405 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1406 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001407 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001408 mPendingAddInfo.container = info.container = container;
1409 mPendingAddInfo.screen = info.screen = screen;
1410 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001411 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001412 mPendingAddInfo.cellX = cell[0];
1413 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001414 }
1415
1416 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1417 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1418 addAppWidgetImpl(appWidgetId, info);
1419 }
1420
Joe Onoratodeb98af2010-02-19 14:59:39 -08001421 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001422 // Handle case where user selected "Applications"
1423 String applicationName = getResources().getString(R.string.group_applications);
1424 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001425
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001426 if (applicationName != null && applicationName.equals(shortcutName)) {
1427 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1428 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001429
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001430 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1431 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001432 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001433 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001434 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001435 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001436 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001437 }
1438
Winson Chung24ab2f12010-09-16 14:10:47 -07001439 void processWallpaper(Intent intent) {
1440 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1441 }
1442
Winson Chung3d503fb2011-07-13 17:25:49 -07001443 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1444 int cellY) {
Adam Cohend0445262011-07-04 23:53:22 -07001445 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 folderInfo.title = getText(R.string.folder_name);
1447
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001449 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1450 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001451 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452
1453 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001454 FolderIcon newFolder =
1455 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1456 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1457 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001458 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 }
Romain Guycbb89e42009-06-08 15:52:54 -07001460
Joe Onorato9c1289c2009-08-17 11:03:03 -04001461 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001462 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001463 }
1464
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001465 private void showNotifications() {
1466 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1467 if (statusBar != null) {
1468 statusBar.expand();
1469 }
1470 }
1471
1472 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001473 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001475 Intent chooser = Intent.createChooser(pickWallpaper,
1476 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001477 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1478 // Removed in Eclair MR1
1479// WallpaperManager wm = (WallpaperManager)
1480// getSystemService(Context.WALLPAPER_SERVICE);
1481// WallpaperInfo wi = wm.getWallpaperInfo();
1482// if (wi != null && wi.getSettingsActivity() != null) {
1483// LabeledIntent li = new LabeledIntent(getPackageName(),
1484// R.string.configure_wallpaper, 0);
1485// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1486// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1487// }
Mike Clerona0618e42009-10-22 13:55:21 -07001488 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
1490
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001491 /**
1492 * Registers various content observers. The current implementation registers
1493 * only a favorites observer to keep track of the favorites applications.
1494 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001495 private void registerContentObservers() {
1496 ContentResolver resolver = getContentResolver();
1497 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1498 true, mWidgetObserver);
1499 }
1500
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 @Override
1502 public boolean dispatchKeyEvent(KeyEvent event) {
1503 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1504 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001506 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001507 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001508 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001509 dumpState();
1510 return true;
1511 }
1512 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001513 }
1514 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1515 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001516 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 return true;
1518 }
1519 }
1520
1521 return super.dispatchKeyEvent(event);
1522 }
1523
Joe Onorato88ec0992009-11-19 13:16:06 -08001524 @Override
1525 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001526 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001527 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001528 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001529 Folder openFolder = mWorkspace.getOpenFolder();
1530 if (openFolder.isEditingName()) {
1531 openFolder.dismissEditingName();
1532 } else {
1533 closeFolder();
1534 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001535 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001536 mWorkspace.exitWidgetResizeMode();
1537
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001538 // Back button is a no-op here, but give at least some feedback for the button press
1539 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001540 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001541 }
1542
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001544 * Re-listen when widgets are reset.
1545 */
1546 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001547 if (mAppWidgetHost != null) {
1548 mAppWidgetHost.startListening();
1549 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001550 }
1551
1552 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001553 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1554 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001556 private void unbindWorkspaceAndHotseatItems() {
Adam Cohen4eac29a2011-07-11 17:53:37 -07001557 LauncherModel.unbindWorkspaceItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001559
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 /**
1561 * Launches the intent referred by the clicked shortcut.
1562 *
1563 * @param v The view representing the clicked shortcut.
1564 */
1565 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001566 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1567 // view has detached (it's possible for this to happen if the view is removed mid touch).
1568 if (v.getWindowToken() == null) {
1569 return;
1570 }
1571
1572 if (mWorkspace.isSwitchingState()) {
1573 return;
1574 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001575
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001577 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001578 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001579 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001580 int[] pos = new int[2];
1581 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001582 intent.setSourceBounds(new Rect(pos[0], pos[1],
1583 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001584 boolean success = startActivitySafely(intent, tag);
1585
1586 if (success && v instanceof BubbleTextView) {
1587 mWaitingForResume = (BubbleTextView) v;
1588 mWaitingForResume.setStayPressed(true);
1589 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001590 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001591 if (v instanceof FolderIcon) {
1592 FolderIcon fi = (FolderIcon) v;
1593 handleFolderClick(fi);
1594 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001595 } else if (v == mAllAppsButton) {
1596 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001597 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001598 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001599 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001600 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 }
1602 }
1603
Michael Jurka0e260592010-06-30 17:07:39 -07001604 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001605 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001606 // clicking anywhere on the workspace causes the customization drawer to slide down
1607 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001608 return false;
1609 }
1610
Michael Jurkaaf442092010-06-10 17:01:57 -07001611 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001612 * Event handler for the search button
1613 *
1614 * @param v The view that was clicked.
1615 */
1616 public void onClickSearchButton(View v) {
Amith Yamasania135ba82011-08-09 17:42:01 -07001617 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001618 }
1619
1620 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001621 * Event handler for the voice button
1622 *
1623 * @param v The view that was clicked.
1624 */
1625 public void onClickVoiceButton(View v) {
1626 startVoiceSearch();
1627 }
1628
1629 private void startVoiceSearch() {
1630 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1631 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1632 startActivity(intent);
1633 }
1634
1635 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001636 * Event handler for the "grid" button that appears on the home screen, which
1637 * enters all apps mode.
1638 *
1639 * @param v The view that was clicked.
1640 */
1641 public void onClickAllAppsButton(View v) {
1642 showAllApps(true);
1643 }
1644
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001645 public void onClickAppMarketButton(View v) {
1646 if (mAppMarketIntent != null) {
1647 startActivitySafely(mAppMarketIntent, "app market");
1648 }
1649 }
1650
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001651 void startApplicationDetailsActivity(ComponentName componentName) {
1652 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001653 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1654 Uri.fromParts("package", packageName, null));
1655 startActivity(intent);
1656 }
1657
Patrick Dubroy5539af72010-09-07 15:22:01 -07001658 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1659 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1660 // System applications cannot be installed. For now, show a toast explaining that.
1661 // We may give them the option of disabling apps this way.
1662 int messageId = R.string.uninstall_system_app_text;
1663 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1664 } else {
1665 String packageName = appInfo.componentName.getPackageName();
1666 String className = appInfo.componentName.getClassName();
1667 Intent intent = new Intent(
1668 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1669 startActivity(intent);
1670 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001671 }
1672
Michael Jurkaddd62e92011-02-16 17:49:14 -08001673 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1675 try {
1676 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001677 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001678 } catch (ActivityNotFoundException e) {
1679 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001680 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 } catch (SecurityException e) {
1682 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001683 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001685 "or use the exported attribute for this activity. "
1686 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001687 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001688 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001690
Romain Guy8e633c52010-03-04 12:51:36 -08001691 void startActivityForResultSafely(Intent intent, int requestCode) {
1692 try {
1693 startActivityForResult(intent, requestCode);
1694 } catch (ActivityNotFoundException e) {
1695 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1696 } catch (SecurityException e) {
1697 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1698 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1699 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1700 "or use the exported attribute for this activity.", e);
1701 }
1702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703
Adam Cohena9cf38f2011-05-02 15:36:58 -07001704 private void handleFolderClick(FolderIcon folderIcon) {
1705 final FolderInfo info = folderIcon.mInfo;
1706 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 // Close any open folder
1708 closeFolder();
1709 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001710 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 } else {
1712 // Find the open folder...
Adam Cohena9cf38f2011-05-02 15:36:58 -07001713 Folder openFolder = mWorkspace.getFolderForTag(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 int folderScreen;
1715 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001716 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 // .. and close it
1718 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001719 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 // Close any folder open on the current screen
1721 closeFolder();
1722 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001723 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 }
1725 }
1726 }
1727 }
1728
Adam Cohen2801caf2011-05-13 20:57:39 -07001729 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001730 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001731 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1732 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1733 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1734
Adam Cohenc51934b2011-07-26 21:07:43 -07001735 FolderInfo info = (FolderInfo) fi.getTag();
1736 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1737 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001738 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1739 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001740 }
1741
Adam Cohen2801caf2011-05-13 20:57:39 -07001742 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1743 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1744 oa.start();
1745 }
1746
1747 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001748 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001749 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1750 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1751 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1752
Adam Cohenc51934b2011-07-26 21:07:43 -07001753 FolderInfo info = (FolderInfo) fi.getTag();
1754 CellLayout cl = null;
1755 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1756 cl = (CellLayout) fi.getParent().getParent();
1757 }
1758
1759 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001760 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1761 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001762 oa.addListener(new AnimatorListenerAdapter() {
1763 @Override
1764 public void onAnimationEnd(Animator animation) {
1765 if (layout != null) {
1766 layout.clearFolderLeaveBehind();
1767 }
1768 }
1769 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001770 oa.start();
1771 }
1772
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001773 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001774 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 * is animated relative to the specified View. If the View is null, no animation
1776 * is played.
1777 *
1778 * @param folderInfo The FolderInfo describing the folder to open.
1779 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001780 public void openFolder(FolderIcon folderIcon) {
1781 Folder folder = folderIcon.mFolder;
1782 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783
Adam Cohen2801caf2011-05-13 20:57:39 -07001784 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001785 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786
Adam Cohen4554ee12011-08-03 16:13:21 -07001787 // Just verify that the folder hasn't already been added to the DragLayer.
1788 // There was a one-off crash where the folder had a parent already.
1789 if (folder.getParent() == null) {
1790 mDragLayer.addView(folder);
1791 mDragController.addDropTarget((DropTarget) folder);
1792 } else {
1793 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1794 folder.getParent() + ").");
1795 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001796 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001797 }
1798
1799 public void closeFolder() {
1800 Folder folder = mWorkspace.getOpenFolder();
1801 if (folder != null) {
1802 closeFolder(folder);
1803 }
1804 }
1805
1806 void closeFolder(Folder folder) {
1807 folder.getInfo().opened = false;
1808
1809 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1810 if (parent != null) {
1811 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1812 shrinkAndFadeInFolderIcon(fi);
1813 }
1814 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 }
1816
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001818 if (mState != State.WORKSPACE) {
1819 return false;
1820 }
1821
Joe Onorato9c1289c2009-08-17 11:03:03 -04001822 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 return false;
1824 }
1825
1826 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001827 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 }
1829
Michael Jurka0280c3b2010-09-17 15:00:07 -07001830 resetAddInfo();
1831 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001833 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 return true;
1835 }
1836
Winson Chung3d503fb2011-07-13 17:25:49 -07001837 // The hotseat touch handling does not go through Workspace, and we always allow long press
1838 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001839 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001840 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1841 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001842 if (itemUnderLongClick == null) {
1843 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001844 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1845 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001846 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001848 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001850 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001851 }
1852 }
1853 }
1854 return true;
1855 }
1856
Winson Chung3d503fb2011-07-13 17:25:49 -07001857 boolean isHotseatLayout(View layout) {
1858 return mHotseat != null && layout != null &&
1859 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1860 }
1861 Hotseat getHotseat() {
1862 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001863 }
1864
Winson Chung3d503fb2011-07-13 17:25:49 -07001865 /**
1866 * Returns the CellLayout of the specified container at the specified screen.
1867 */
1868 CellLayout getCellLayout(long container, int screen) {
1869 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1870 if (mHotseat != null) {
1871 return mHotseat.getLayout();
1872 } else {
1873 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001874 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001875 } else {
1876 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001877 }
1878 }
1879
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 Workspace getWorkspace() {
1881 return mWorkspace;
1882 }
1883
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 @Override
1885 protected Dialog onCreateDialog(int id) {
1886 switch (id) {
1887 case DIALOG_CREATE_SHORTCUT:
1888 return new CreateShortcut().createDialog();
1889 case DIALOG_RENAME_FOLDER:
1890 return new RenameFolder().createDialog();
1891 }
1892
1893 return super.onCreateDialog(id);
1894 }
1895
1896 @Override
1897 protected void onPrepareDialog(int id, Dialog dialog) {
1898 switch (id) {
1899 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 break;
1901 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001902 if (mFolderInfo != null) {
1903 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1904 final CharSequence text = mFolderInfo.title;
1905 input.setText(text);
1906 input.setSelection(0, text.length());
1907 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 break;
1909 }
1910 }
1911
1912 void showRenameDialog(FolderInfo info) {
1913 mFolderInfo = info;
1914 mWaitingForResult = true;
1915 showDialog(DIALOG_RENAME_FOLDER);
1916 }
1917
Adam Cohenfbba09b2011-07-18 21:43:05 -07001918 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001919 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001920 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1921 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 mWaitingForResult = true;
1923 showDialog(DIALOG_CREATE_SHORTCUT);
1924 }
1925
1926 private class RenameFolder {
1927 private EditText mInput;
1928
1929 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1931 mInput = (EditText) layout.findViewById(R.id.folder_name);
1932
1933 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1934 builder.setIcon(0);
1935 builder.setTitle(getString(R.string.rename_folder_title));
1936 builder.setCancelable(true);
1937 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1938 public void onCancel(DialogInterface dialog) {
1939 cleanup();
1940 }
1941 });
1942 builder.setNegativeButton(getString(R.string.cancel_action),
1943 new Dialog.OnClickListener() {
1944 public void onClick(DialogInterface dialog, int which) {
1945 cleanup();
1946 }
1947 }
1948 );
1949 builder.setPositiveButton(getString(R.string.rename_action),
1950 new Dialog.OnClickListener() {
1951 public void onClick(DialogInterface dialog, int which) {
1952 changeFolderName();
1953 }
1954 }
1955 );
1956 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001957
1958 final AlertDialog dialog = builder.create();
1959 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1960 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001961 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001962 mInput.requestFocus();
1963 InputMethodManager inputManager = (InputMethodManager)
1964 getSystemService(Context.INPUT_METHOD_SERVICE);
1965 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001966 }
1967 });
1968
1969 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001970 }
1971
1972 private void changeFolderName() {
1973 final String name = mInput.getText().toString();
1974 if (!TextUtils.isEmpty(name)) {
1975 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001976 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977 mFolderInfo.title = name;
1978 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1979
Joe Onorato9c1289c2009-08-17 11:03:03 -04001980 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001981 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001982 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 } else {
1984 final FolderIcon folderIcon = (FolderIcon)
1985 mWorkspace.getViewForTag(mFolderInfo);
1986 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001987 // TODO: At some point we'll probably want some version of setting
1988 // the text for a folder icon.
1989 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 getWorkspace().requestLayout();
1991 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001992 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001993 mWorkspaceLoading = true;
1994 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 }
1996 }
1997 }
1998 cleanup();
1999 }
2000
2001 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 dismissDialog(DIALOG_RENAME_FOLDER);
2003 mWaitingForResult = false;
2004 mFolderInfo = null;
2005 }
2006 }
2007
Daniel Sandler843e8602010-06-07 14:59:01 -04002008 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2009 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002010 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002011 }
2012
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002013 // AllAppsView.Watcher
2014 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002015 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002016 mWorkspace.setVisibility(View.GONE);
2017 }
2018 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002019
2020 /**
2021 * Helper method for the cameraZoomIn/cameraZoomOut animations
2022 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002023 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002024 * @param scaleFactor The scale factor used for the zoom
2025 */
2026 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2027 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002028
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002029 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002030 // Set pivotY so that at the starting zoom factor, the view is partially
2031 // visible. Modifying initialHeightFactor changes how much of the view is
2032 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002033 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002034 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002035 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002036 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002037 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002038 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002039 }
2040 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002041
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002042 /**
2043 * Zoom the camera out from the workspace to reveal 'toView'.
2044 * Assumes that the view to show is anchored at either the very top or very bottom
2045 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002046 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002047 */
Winson Chungc07918d2011-07-01 15:35:26 -07002048 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002049 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002050
Winson Chungf0ea4d32011-06-06 14:27:16 -07002051 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2052 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2053 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2054 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002055
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002056 setPivotsForZoom(toView, toState, scale);
2057
Michael Jurkad74c9842011-07-10 12:44:21 -07002058 // Shrink workspaces away if going to AppsCustomize from workspace
2059 mWorkspace.shrink(Workspace.State.SMALL, animated);
Winson Chung4afe9b32011-07-27 17:46:20 -07002060 hideHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002061
2062 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002063 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002064 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002065 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2066 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002067 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002068 toView.setFastScaleX(a * scale + b * 1f);
2069 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002070 }
2071 });
Adam Cohen61033d32010-11-15 18:29:44 -08002072
Winson Chungf0ea4d32011-06-06 14:27:16 -07002073 toView.setVisibility(View.VISIBLE);
2074 toView.setFastAlpha(0f);
2075 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2076 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2077 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2078 public void onAnimationUpdate(float a, float b) {
2079 // don't need to invalidate because we do so above
2080 toView.setFastAlpha(a * 0f + b * 1f);
2081 }
2082 });
2083 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002084
Michael Jurkaabded662011-03-04 12:06:57 -08002085 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002086 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002087 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002088 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002089 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002090 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002091 // Prepare the position
2092 toView.setTranslationX(0.0f);
2093 toView.setTranslationY(0.0f);
2094 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002095 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002096 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002097 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002098 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002099 // If we don't set the final scale values here, if this animation is cancelled
2100 // it will have the wrong scale value and subsequent cameraPan animations will
2101 // not fix that
2102 toView.setScaleX(1.0f);
2103 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002104 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002105 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002106 }
Winson Chung32174c82011-07-19 15:47:55 -07002107
2108 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2109 // Hide the workspace scrollbar
2110 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002111 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002112 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002113 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002114 });
2115
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002116 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002117 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002118
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002119 if (mStateAnimation != null) mStateAnimation.cancel();
2120 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002121 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002122 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002123 } else {
2124 toView.setTranslationX(0.0f);
2125 toView.setTranslationY(0.0f);
2126 toView.setScaleX(1.0f);
2127 toView.setScaleY(1.0f);
2128 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002129 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002130 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002131 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2132 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002133
Winson Chungc07918d2011-07-01 15:35:26 -07002134 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2135 // Hide the workspace scrollbar
2136 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002137 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002138 }
Michael Jurkaabded662011-03-04 12:06:57 -08002139 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002140 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002141 }
2142
2143 /**
2144 * Zoom the camera back into the workspace, hiding 'fromView'.
2145 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002146 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002147 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002148 */
Winson Chungc07918d2011-07-01 15:35:26 -07002149 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002150 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002151
Winson Chungf0ea4d32011-06-06 14:27:16 -07002152 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2153 final float scaleFactor = (float)
2154 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2155 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002156
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002157 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002158
Michael Jurkad3ef3062010-11-23 16:23:58 -08002159 if (!springLoaded) {
2160 mWorkspace.unshrink(animated);
2161 }
Winson Chung4afe9b32011-07-27 17:46:20 -07002162 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002163 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002164 if (mStateAnimation != null) mStateAnimation.cancel();
2165 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002166
Michael Jurka742574b2011-02-02 23:51:01 -08002167 final float oldScaleX = fromView.getScaleX();
2168 final float oldScaleY = fromView.getScaleY();
2169
2170 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2171 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002172 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2173 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002174 ((View)fromView.getParent()).fastInvalidate();
2175 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2176 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2177 }
2178 });
Michael Jurkaabded662011-03-04 12:06:57 -08002179 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002180 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002181 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002182 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2183 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002184 // don't need to invalidate because we do so above
2185 fromView.setFastAlpha(a * 1f + b * 0f);
2186 }
2187 });
Michael Jurkaabded662011-03-04 12:06:57 -08002188 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002189 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002190 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002191 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002192 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002193 public void onAnimationStart(android.animation.Animator animation) {
2194 if (!springLoaded) {
2195 mWorkspace.showDockDivider(false);
2196 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002197 mWorkspace.showScrollingIndicator(false);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002198 }
2199 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002200 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002201 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002202 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002203 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002204 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002205 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002206 }
2207 });
2208
Winson Chungf0ea4d32011-06-06 14:27:16 -07002209 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002210 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002211 } else {
2212 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002213 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002214 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2215 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002216
Winson Chungc07918d2011-07-01 15:35:26 -07002217 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002218 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002219 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002220 mWorkspace.flashScrollingIndicator();
2221 }
Michael Jurkaabded662011-03-04 12:06:57 -08002222 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002223 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002224 }
2225
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002226 void showWorkspace(boolean animated) {
2227 showWorkspace(animated, null);
2228 }
2229
2230 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002231 if (layout != null) {
2232 // always animated, but that's ok since we never specify a layout and
2233 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002234 mWorkspace.unshrink(layout);
2235 } else {
2236 mWorkspace.unshrink(animated);
2237 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002238 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002239 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002240 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002241
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002242 // Change the state *after* we've called all the transition code
2243 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002244
Winson Chung5fb63472011-02-02 17:03:37 -08002245 // Resume the auto-advance of widgets
2246 mUserPresent = true;
2247 updateRunning();
2248
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002249 // send an accessibility event to announce the context change
2250 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002251 }
2252
Michael Jurkad3ef3062010-11-23 16:23:58 -08002253 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002254 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002255 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002256 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002257 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002258 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002259 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002260 }
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002261 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chunge7a03942011-08-05 15:05:12 -07002262 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002263 @Override
2264 public void run() {
2265 exitSpringLoadedDragMode();
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002266
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002267 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002268 // Before we show workspace, hide all apps again because
2269 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2270 // clean up our state transition functions
2271 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002272 showWorkspace(true);
2273 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002274 }
2275 }, (extendedDelay ?
2276 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2277 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2278 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002279 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002280 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002281 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002282 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2283 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002284 }
2285 // Otherwise, we are not in spring loaded mode, so don't do anything.
2286 }
2287
Adam Cohenfc53cd22011-07-20 15:45:11 -07002288 public boolean isAllAppsCustomizeOpen() {
2289 return mState == State.APPS_CUSTOMIZE;
2290 }
2291
Winson Chungf0ea4d32011-06-06 14:27:16 -07002292 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002293 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002294 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002295 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002296 if (!LauncherApplication.isScreenLarge()) {
2297 if (animated) {
2298 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002299 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002300 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002301 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002302 }
2303 }
2304 }
2305
2306 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002307 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002308 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002309 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002310 if (!LauncherApplication.isScreenLarge()) {
2311 if (animated) {
2312 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002313 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002314 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002315 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002316 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002317 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002318 }
2319
Winson Chung785d2eb2011-04-14 16:08:02 -07002320 void showAllApps(boolean animated) {
2321 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002322
Winson Chungf0ea4d32011-06-06 14:27:16 -07002323 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2324 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002325
Winson Chung3d503fb2011-07-13 17:25:49 -07002326 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002327 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002328
Winson Chungf0ea4d32011-06-06 14:27:16 -07002329 // Change the state *after* we've called all the transition code
2330 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002331
2332 // Pause the auto-advance of widgets until we are out of AllApps
2333 mUserPresent = false;
2334 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002335 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002336
2337 // Send an accessibility event to announce the context change
2338 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2339 }
2340
Joe Onoratob2061212009-11-24 16:13:54 -05002341 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002342 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002343 * - Home from workspace
2344 * - from center screen
2345 * - from other screens
2346 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002347 * - from center screen
2348 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002349 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002350 * - from center screen
2351 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002352 * - Launch app from workspace and quit
2353 * - with back
2354 * - with home
2355 * - Launch app from all apps and quit
2356 * - with back
2357 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002358 * - Go to a screen that's not the default, then all
2359 * apps, and launch and app, and go back
2360 * - with back
2361 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002362 * - On workspace, long press power and go back
2363 * - with back
2364 * - with home
2365 * - On all apps, long press power and go back
2366 * - with back
2367 * - with home
2368 * - On workspace, power off
2369 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002370 * - Launch an app and turn off the screen while in that app
2371 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002372 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002373 * - From all apps
2374 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002375 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2376 * - From all apps
2377 * - From the center workspace
2378 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002379 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002380 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002381 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2382 mWorkspace.setVisibility(View.VISIBLE);
2383 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002384
Winson Chung3d503fb2011-07-13 17:25:49 -07002385 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002386 mSearchDeleteBar.showSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002387
Winson Chungf0ea4d32011-06-06 14:27:16 -07002388 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002389 if (mAllAppsButton != null) {
2390 mAllAppsButton.requestFocus();
2391 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002392 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002393 }
2394
Joe Onorato7c312c12009-08-13 21:36:53 -07002395 void lockAllApps() {
2396 // TODO
2397 }
2398
2399 void unlockAllApps() {
2400 // TODO
2401 }
2402
Patrick Dubroy5f445422011-02-18 14:35:21 -08002403 /**
2404 * Add an item from all apps or customize onto the given workspace screen.
2405 * If layout is null, add to the current screen.
2406 */
2407 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002408 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2409 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002410 } else {
2411 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002412 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002413 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002414
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002415 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002416 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002417 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002418 // Look for the toolbar icon specified in the activity meta-data
2419 Bundle metaData = packageManager.getActivityInfo(
2420 activityName, PackageManager.GET_META_DATA).metaData;
2421 if (metaData != null) {
2422 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2423 if (iconResId != 0) {
2424 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002425 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002426 }
2427 }
2428 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002429 // This can happen if the activity defines an invalid drawable
2430 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2431 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002432 } catch (Resources.NotFoundException nfe) {
2433 // This can happen if the activity defines an invalid drawable
2434 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2435 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002436 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002437 return null;
2438 }
2439
2440 // if successful in getting icon, return it; otherwise, set button to use default drawable
2441 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2442 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2443 TextView button = (TextView) findViewById(buttonId);
2444 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2445
2446 // If we were unable to find the icon via the meta-data, use a generic one
2447 if (toolbarIcon == null) {
2448 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2449 return null;
2450 } else {
2451 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2452 return toolbarIcon.getConstantState();
2453 }
2454 }
2455
2456 // if successful in getting icon, return it; otherwise, set button to use default drawable
2457 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2458 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2459 ImageView button = (ImageView) findViewById(buttonId);
2460 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2461
Michael Jurka19e0fc52011-07-22 18:00:21 -07002462 if (button != null) {
2463 // If we were unable to find the icon via the meta-data, use a
2464 // generic one
2465 if (toolbarIcon == null) {
2466 button.setImageResource(fallbackDrawableId);
2467 } else {
2468 button.setImageDrawable(toolbarIcon);
2469 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002470 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002471
2472 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2473
Michael Jurka0423dcf2010-10-05 14:56:18 -07002474 }
2475
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002476 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2477 TextView button = (TextView) findViewById(buttonId);
2478 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2479 }
2480
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002481 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002482 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002483 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002484 }
2485
Michael Jurka0423dcf2010-10-05 14:56:18 -07002486 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002487 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2488 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002489
Winson Chung1cad91e2011-05-25 17:41:01 -07002490 final SearchManager searchManager =
2491 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2492 ComponentName activityName = searchManager.getGlobalSearchActivity();
2493 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002494 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002495 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002496 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002497 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002498 } else {
2499 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002500 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002501 }
2502 }
2503
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002504 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002505 updateButtonWithDrawable(R.id.search_button, d);
2506 }
2507
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002508 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002509 final View searchDivider = findViewById(R.id.search_divider);
2510 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002511
Winson Chung1cad91e2011-05-25 17:41:01 -07002512 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2513 ComponentName activityName = intent.resolveActivity(getPackageManager());
2514 if (activityName != null) {
2515 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002516 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2517 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002518 voiceButton.setVisibility(View.VISIBLE);
2519 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002520 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002521 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002522 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002523 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002524
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002525 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002526 updateButtonWithDrawable(R.id.voice_button, d);
2527 }
2528
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002529 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002530 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002531 */
2532 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002533 final View marketButton = findViewById(R.id.market_button);
2534 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2535 // Find the app market activity by resolving an intent.
2536 // (If multiple app markets are installed, it will return the ResolverActivity.)
2537 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002538 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002539 mAppMarketIntent = intent;
2540 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002541 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002542 marketButton.setVisibility(View.VISIBLE);
2543 } else {
2544 // We should hide and disable the view so that we don't try and restore the visibility
2545 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2546 marketButton.setVisibility(View.GONE);
2547 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002548 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002549 }
2550
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002551 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002552 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002553 }
2554
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002555 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002556 * Displays the shortcut creation dialog and launches, if necessary, the
2557 * appropriate activity.
2558 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002559 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002560 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2561 DialogInterface.OnShowListener {
2562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002563 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002564
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002565 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002567
Winson Chung55b65502011-05-26 12:03:43 -07002568 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2569 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002570 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002571
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 AlertDialog dialog = builder.create();
2573 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002574 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002575 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002576
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002577 return dialog;
2578 }
2579
2580 public void onCancel(DialogInterface dialog) {
2581 mWaitingForResult = false;
2582 cleanup();
2583 }
2584
Romain Guycbb89e42009-06-08 15:52:54 -07002585 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002586 mWaitingForResult = false;
2587 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002588 }
2589
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002590 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002591 try {
2592 dismissDialog(DIALOG_CREATE_SHORTCUT);
2593 } catch (Exception e) {
2594 // An exception is thrown if the dialog is not visible, which is fine
2595 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002596 }
2597
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002598 /**
2599 * Handle the action clicked in the "Add to home" dialog.
2600 */
2601 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002602 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002603
Winson Chung55b65502011-05-26 12:03:43 -07002604 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2605 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002606 case AddAdapter.ITEM_APPLICATION: {
2607 if (mAppsCustomizeTabHost != null) {
2608 mAppsCustomizeTabHost.selectAppsTab();
2609 }
2610 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002611 break;
2612 }
Winson Chung55b65502011-05-26 12:03:43 -07002613 case AddAdapter.ITEM_APPWIDGET: {
2614 if (mAppsCustomizeTabHost != null) {
2615 mAppsCustomizeTabHost.selectWidgetsTab();
2616 }
2617 showAllApps(true);
2618 break;
2619 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002620 case AddAdapter.ITEM_WALLPAPER: {
2621 startWallpaper();
2622 break;
2623 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002624 }
2625 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002626
2627 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002628 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002630 }
2631
2632 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002633 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002634 */
2635 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2636 @Override
2637 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002638 closeSystemDialogs();
2639 }
2640 }
2641
2642 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002643 * Receives notifications whenever the appwidgets are reset.
2644 */
2645 private class AppWidgetResetObserver extends ContentObserver {
2646 public AppWidgetResetObserver() {
2647 super(new Handler());
2648 }
2649
2650 @Override
2651 public void onChange(boolean selfChange) {
2652 onAppWidgetReset();
2653 }
2654 }
2655
2656 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002657 * If the activity is currently paused, signal that we need to re-run the loader
2658 * in onResume.
2659 *
2660 * This needs to be called from incoming places where resources might have been loaded
2661 * while we are paused. That is becaues the Configuration might be wrong
2662 * when we're not running, and if it comes back to what it was when we
2663 * were paused, we are not restarted.
2664 *
2665 * Implementation of the method from LauncherModel.Callbacks.
2666 *
2667 * @return true if we are currently paused. The caller might be able to
2668 * skip some work in that case since we will come back again.
2669 */
2670 public boolean setLoadOnResume() {
2671 if (mPaused) {
2672 Log.i(TAG, "setLoadOnResume");
2673 mOnResumeNeedsLoad = true;
2674 return true;
2675 } else {
2676 return false;
2677 }
2678 }
2679
2680 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002681 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002682 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002683 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002684 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002685 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002686 } else {
2687 return SCREEN_COUNT / 2;
2688 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002689 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002690
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002691
Joe Onorato9c1289c2009-08-17 11:03:03 -04002692 /**
2693 * Refreshes the shortcuts shown on the workspace.
2694 *
2695 * Implementation of the method from LauncherModel.Callbacks.
2696 */
2697 public void startBinding() {
2698 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002699
2700 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002701 int count = workspace.getChildCount();
2702 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002703 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002704 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2705 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002706 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002707 if (mHotseat != null) {
2708 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002709 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002710
Adam Cohen4eac29a2011-07-11 17:53:37 -07002711 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002712 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 }
2714
2715 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002716 * Bind the items start-end from the list.
2717 *
2718 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002719 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002720 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002721 setLoadOnResume();
2722
Joe Onorato9c1289c2009-08-17 11:03:03 -04002723 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002724 for (int i=start; i<end; i++) {
2725 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002726
2727 // Short circuit if we are loading dock items for a configuration which has no dock
2728 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2729 mHotseat == null) {
2730 continue;
2731 }
2732
Joe Onorato9c1289c2009-08-17 11:03:03 -04002733 switch (item.itemType) {
2734 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2735 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002736 View shortcut = createShortcut((ShortcutInfo)item);
2737 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2738 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002739 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002740 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002741 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002742 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002743 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002744 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2745 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002746 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002748 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002749 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002750 }
2751
Joe Onorato9c1289c2009-08-17 11:03:03 -04002752 /**
2753 * Implementation of the method from LauncherModel.Callbacks.
2754 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002755 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002756 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002757 sFolders.clear();
2758 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002759 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002760
2761 /**
2762 * Add the views for a widget to the workspace.
2763 *
2764 * Implementation of the method from LauncherModel.Callbacks.
2765 */
2766 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002767 setLoadOnResume();
2768
Daniel Sandler843e8602010-06-07 14:59:01 -04002769 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2770 if (DEBUG_WIDGETS) {
2771 Log.d(TAG, "bindAppWidget: " + item);
2772 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002773 final Workspace workspace = mWorkspace;
2774
2775 final int appWidgetId = item.appWidgetId;
2776 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002777 if (DEBUG_WIDGETS) {
2778 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2779 }
2780
Joe Onorato9c1289c2009-08-17 11:03:03 -04002781 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2782
Joe Onorato9c1289c2009-08-17 11:03:03 -04002783 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2784 item.hostView.setTag(item);
2785
Winson Chung3d503fb2011-07-13 17:25:49 -07002786 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002787 item.cellY, item.spanX, item.spanY, false);
2788
Adam Cohended9f8d2010-11-03 13:25:16 -07002789 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2790
Joe Onorato9c1289c2009-08-17 11:03:03 -04002791 workspace.requestLayout();
2792
Daniel Sandler843e8602010-06-07 14:59:01 -04002793 if (DEBUG_WIDGETS) {
2794 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2795 + (SystemClock.uptimeMillis()-start) + "ms");
2796 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002797 }
2798
2799 /**
2800 * Callback saying that there aren't any more items to bind.
2801 *
2802 * Implementation of the method from LauncherModel.Callbacks.
2803 */
2804 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002805 setLoadOnResume();
2806
Joe Onorato9c1289c2009-08-17 11:03:03 -04002807 if (mSavedState != null) {
2808 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002809 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002810 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002811 mSavedState = null;
2812 }
2813
2814 if (mSavedInstanceState != null) {
2815 super.onRestoreInstanceState(mSavedInstanceState);
2816 mSavedInstanceState = null;
2817 }
2818
Joe Onorato9c1289c2009-08-17 11:03:03 -04002819 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002820
2821 // If we received the result of any pending adds while the loader was running (e.g. the
2822 // widget configuration forced an orientation change), process them now.
2823 for (int i = 0; i < sPendingAddList.size(); i++) {
2824 completeAdd(sPendingAddList.get(i));
2825 }
2826 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002827 }
2828
2829 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002830 * Updates the icons on the launcher that are affected by changes to the package list
2831 * on the device.
2832 */
2833 private void updateIconsAffectedByPackageManagerChanges() {
2834 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002835 updateVoiceSearchIcon();
2836 }
2837
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002838 @Override
2839 public void bindSearchablesChanged() {
2840 updateGlobalSearchIcon();
2841 }
2842
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002843 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002844 * Add the icons for all apps.
2845 *
2846 * Implementation of the method from LauncherModel.Callbacks.
2847 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07002848 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
2849 // Remove the progress bar entirely; we could also make it GONE
2850 // but better to remove it since we know it's not going to be used
2851 View progressBar = mAppsCustomizeTabHost.
2852 findViewById(R.id.apps_customize_progress_bar);
2853 if (progressBar != null) {
2854 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07002855 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07002856 // We just post the call to setApps so the user sees the progress bar
2857 // disappear-- otherwise, it just looks like the progress bar froze
2858 // which doesn't look great
2859 mAppsCustomizeTabHost.post(new Runnable() {
2860 public void run() {
2861 if (mAppsCustomizeContent != null) {
2862 mAppsCustomizeContent.setApps(apps);
2863 }
2864 }
2865 });
2866
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002867 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002868 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002869 }
2870
2871 /**
2872 * A package was installed.
2873 *
2874 * Implementation of the method from LauncherModel.Callbacks.
2875 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002876 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002877 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002878 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002879
Winson Chung785d2eb2011-04-14 16:08:02 -07002880 if (mAppsCustomizeContent != null) {
2881 mAppsCustomizeContent.addApps(apps);
2882 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002883 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002884 }
2885
2886 /**
2887 * A package was updated.
2888 *
2889 * Implementation of the method from LauncherModel.Callbacks.
2890 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002891 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002892 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002893 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002894 if (mWorkspace != null) {
2895 mWorkspace.updateShortcuts(apps);
2896 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002897
Winson Chung785d2eb2011-04-14 16:08:02 -07002898 if (mAppsCustomizeContent != null) {
2899 mAppsCustomizeContent.updateApps(apps);
2900 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002901 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002902 }
2903
2904 /**
2905 * A package was uninstalled.
2906 *
2907 * Implementation of the method from LauncherModel.Callbacks.
2908 */
Joe Onorato36115782010-06-17 13:28:48 -04002909 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002910 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002911 if (permanent) {
2912 mWorkspace.removeItems(apps);
2913 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002914
Winson Chung785d2eb2011-04-14 16:08:02 -07002915 if (mAppsCustomizeContent != null) {
2916 mAppsCustomizeContent.removeApps(apps);
2917 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002918 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002919 }
Joe Onoratobe386092009-11-17 17:32:16 -08002920
2921 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002922 * A number of packages were updated.
2923 */
2924 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002925
Winson Chung785d2eb2011-04-14 16:08:02 -07002926 if (mAppsCustomizeContent != null) {
2927 mAppsCustomizeContent.onPackagesUpdated();
2928 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002929 }
2930
Winson Chung400438b2011-01-16 17:53:48 -08002931 private int mapConfigurationOriActivityInfoOri(int configOri) {
2932 final Display d = getWindowManager().getDefaultDisplay();
2933 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2934 switch (d.getRotation()) {
2935 case Surface.ROTATION_0:
2936 case Surface.ROTATION_180:
2937 // We are currently in the same basic orientation as the natural orientation
2938 naturalOri = configOri;
2939 break;
2940 case Surface.ROTATION_90:
2941 case Surface.ROTATION_270:
2942 // We are currently in the other basic orientation to the natural orientation
2943 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2944 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2945 break;
2946 }
2947
2948 int[] oriMap = {
2949 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2950 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2951 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2952 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2953 };
2954 // Since the map starts at portrait, we need to offset if this device's natural orientation
2955 // is landscape.
2956 int indexOffset = 0;
2957 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2958 indexOffset = 1;
2959 }
2960 return oriMap[(d.getRotation() + indexOffset) % 4];
2961 }
2962 public void lockScreenOrientation() {
2963 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2964 .getConfiguration().orientation));
2965 }
2966 public void unlockScreenOrientation() {
2967 mHandler.postDelayed(new Runnable() {
2968 public void run() {
2969 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2970 }
2971 }, mRestoreScreenOrientationDelay);
2972 }
2973
Winson Chung82f55532011-08-09 14:14:23 -07002974 /* Cling related */
2975 private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed";
2976 private static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed";
2977 private void enableClingsIfNecessary() {
2978 // TEMPORARY: DISABLE CLINGS ON LARGE UI
2979 if (LauncherApplication.isScreenLarge()) return;
2980
2981 // Enable the clings only if they have not been dismissed before
2982 SharedPreferences prefs =
2983 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
2984 if (!prefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false)) {
2985 Cling cling = (Cling) findViewById(R.id.workspace_cling);
2986 cling.init(this);
2987 cling.setVisibility(View.VISIBLE);
2988 }
2989 if (!prefs.getBoolean(ALLAPPS_CLING_DISMISSED_KEY, false)) {
2990 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
2991 cling.init(this);
2992 cling.setVisibility(View.VISIBLE);
2993 }
2994 }
2995 private void dismissCling(final Cling cling, final String flag) {
2996 if (cling != null) {
2997 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
2998 anim.setDuration(DISMISS_CLING_DURATION);
2999 anim.addListener(new AnimatorListenerAdapter() {
3000 public void onAnimationEnd(Animator animation) {
3001 cling.setVisibility(View.GONE);
3002 cling.cleanup();
3003 SharedPreferences prefs =
3004 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3005 SharedPreferences.Editor editor = prefs.edit();
3006 editor.putBoolean(flag, true);
3007 editor.commit();
3008 };
3009 });
3010 anim.start();
3011 }
3012 }
3013 public void dismissWorkspaceCling(View v) {
3014 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3015 dismissCling(cling, WORKSPACE_CLING_DISMISSED_KEY);
3016 }
3017 public void dismissAllAppsCling(View v) {
3018 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
3019 dismissCling(cling, ALLAPPS_CLING_DISMISSED_KEY);
3020 }
3021
Winson Chung80baf5a2010-08-09 16:03:15 -07003022 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003023 * Prints out out state for debugging.
3024 */
3025 public void dumpState() {
3026 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003027 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003028 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3029 Log.d(TAG, "mRestoring=" + mRestoring);
3030 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3031 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003032 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003033 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003034
Winson Chung785d2eb2011-04-14 16:08:02 -07003035 if (mAppsCustomizeContent != null) {
3036 mAppsCustomizeContent.dumpState();
3037 }
Joe Onoratobe386092009-11-17 17:32:16 -08003038 Log.d(TAG, "END launcher2 dump state");
3039 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003040}
Michael Jurka2763be32011-02-24 11:19:57 -08003041
Michael Jurkaabded662011-03-04 12:06:57 -08003042interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07003043 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
3044 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003045}