blob: 055577aa4d7ca6efb82bfabc101108c087c5f01b [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
Winson Chung87acb482011-08-23 17:28:05 -07001063 /**
1064 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001065 try {
1066 dismissDialog(DIALOG_CREATE_SHORTCUT);
1067 // Unlock the workspace if the dialog was showing
1068 } catch (Exception e) {
1069 // An exception is thrown if the dialog is not visible, which is fine
1070 }
1071
1072 try {
1073 dismissDialog(DIALOG_RENAME_FOLDER);
1074 // Unlock the workspace if the dialog was showing
1075 } catch (Exception e) {
1076 // An exception is thrown if the dialog is not visible, which is fine
1077 }
Winson Chung87acb482011-08-23 17:28:05 -07001078 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001079
1080 // Whatever we were doing is hereby canceled.
1081 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001082 }
1083
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001084 @Override
1085 protected void onNewIntent(Intent intent) {
1086 super.onNewIntent(intent);
1087
1088 // Close the menu
1089 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001090 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001091 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001092
Adam Cohen95bb8002011-07-03 23:40:28 -07001093 closeFolder();
1094
Joe Onorato14f122b2009-11-19 14:06:36 -08001095 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1096 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001097
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001098 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001099 mWorkspace.exitWidgetResizeMode();
Patrick Dubroya0aa0122011-02-24 11:42:23 -08001100 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001101 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001102 }
Winson Chungde1af762011-07-21 16:44:07 -07001103 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001104 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001105
Joe Onorato3a8820b2009-11-10 15:06:42 -08001106 final View v = getWindow().peekDecorView();
1107 if (v != null && v.getWindowToken() != null) {
1108 InputMethodManager imm = (InputMethodManager)getSystemService(
1109 INPUT_METHOD_SERVICE);
1110 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001112
Michael Jurka35aa14d2011-07-07 17:01:08 -07001113 // Reset AllApps to its initial state
Winson Chungc100e8e2011-08-09 16:02:43 -07001114 if (mAppsCustomizeTabHost != null) {
1115 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 }
1118 }
1119
1120 @Override
1121 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1122 // Do not call super here
1123 mSavedInstanceState = savedInstanceState;
1124 }
1125
1126 @Override
1127 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001128 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001129 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130
Michael Jurka883f55b2010-10-21 15:47:14 -07001131 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001132 // We close any open folder since it will not be re-opened, and we need to make sure
1133 // this state is reflected.
1134 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001135
Winson Chung3d503fb2011-07-13 17:25:49 -07001136 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1137 mWaitingForResult) {
1138 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1139 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1140 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1141 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 }
1143
1144 if (mFolderInfo != null && mWaitingForResult) {
1145 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1146 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1147 }
Michael Jurka946ad472010-07-09 18:05:18 -07001148
Winson Chung785d2eb2011-04-14 16:08:02 -07001149 // Save the current AppsCustomize tab
1150 if (mAppsCustomizeTabHost != null) {
1151 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1152 if (currentTabTag != null) {
1153 outState.putString("apps_customize_currentTab", currentTabTag);
1154 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001155 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1156 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158 }
1159
1160 @Override
1161 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001163
Winson Chunge7a03942011-08-05 15:05:12 -07001164 // Remove all pending runnables
1165 mHandler.removeMessages(ADVANCE_MSG);
1166 mHandler.removeMessages(0);
1167
Winson Chungcd2b0142011-06-08 16:02:26 -07001168 // Stop callbacks from LauncherModel
1169 LauncherApplication app = ((LauncherApplication) getApplication());
1170 mModel.stopLoader();
1171 app.setLauncher(null);
1172
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001174 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001176 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001178 mAppWidgetHost = null;
1179
1180 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181
1182 TextKeyListener.getInstance().release();
1183
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001184
Winson Chung3d503fb2011-07-13 17:25:49 -07001185 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001186
1187 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001188 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001189
1190 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1191 mWorkspace.removeAllViews();
1192 mWorkspace = null;
1193 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001194
1195 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 }
1197
Adam Cohena9cf38f2011-05-02 15:36:58 -07001198 public DragController getDragController() {
1199 return mDragController;
1200 }
1201
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 @Override
1203 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001204 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 super.startActivityForResult(intent, requestCode);
1206 }
1207
Winson Chung70d72102011-08-12 11:24:35 -07001208 /**
1209 * Indicates that we want global search for this activity by setting the globalSearch
1210 * argument for {@link #startSearch} to true.
1211 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001213 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001215
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001216 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001217
Karl Rosaen138a0412009-04-23 19:00:21 -07001218 if (initialQuery == null) {
1219 // Use any text typed in the launcher as the initial query
1220 initialQuery = getTypedText();
1221 clearTypedText();
1222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223 if (appSearchData == null) {
1224 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001225 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 }
Romain Guycbb89e42009-06-08 15:52:54 -07001227
Karl Rosaen138a0412009-04-23 19:00:21 -07001228 final SearchManager searchManager =
1229 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001230 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001231 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 }
1233
Winson Chung70d72102011-08-12 11:24:35 -07001234 @Override
1235 public boolean onCreateOptionsMenu(Menu menu) {
1236 if (isWorkspaceLocked()) {
1237 return false;
1238 }
1239
1240 super.onCreateOptionsMenu(menu);
Winson Chung236d4312011-08-22 15:12:27 -07001241 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1242 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1243 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Winson Chung70d72102011-08-12 11:24:35 -07001244 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1245 .setIcon(android.R.drawable.ic_menu_gallery)
1246 .setAlphabeticShortcut('W');
1247 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1248 .setIcon(android.R.drawable.ic_menu_manage)
1249 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001250 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1251 .setIcon(android.R.drawable.ic_menu_preferences)
1252 .setIntent(settings)
1253 .setAlphabeticShortcut('P');
Winson Chung70d72102011-08-12 11:24:35 -07001254 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1255 .setIcon(android.R.drawable.ic_menu_help)
1256 .setAlphabeticShortcut('H');
1257 return true;
1258 }
1259
1260 @Override
1261 public boolean onPrepareOptionsMenu(Menu menu) {
1262 super.onPrepareOptionsMenu(menu);
1263
1264 if (mAppsCustomizeTabHost.isTransitioning()) {
1265 return false;
1266 }
1267 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1268 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1269
1270 return true;
1271 }
1272
1273 @Override
1274 public boolean onOptionsItemSelected(MenuItem item) {
1275 switch (item.getItemId()) {
1276 case MENU_WALLPAPER_SETTINGS:
1277 startWallpaper();
1278 return true;
1279 case MENU_MANAGE_APPS:
1280 manageApps();
1281 return true;
1282 case MENU_HELP:
1283 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help_url))));
1284 return true;
1285 }
1286
1287 return super.onOptionsItemSelected(item);
1288 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001290 @Override
1291 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001292 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001293 // Use a custom animation for launching search
1294 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001295 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001296 }
1297
Joe Onorato9c1289c2009-08-17 11:03:03 -04001298 public boolean isWorkspaceLocked() {
1299 return mWorkspaceLoading || mWaitingForResult;
1300 }
1301
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 private void addItems() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001303 showWorkspace(true);
Adam Cohenfbba09b2011-07-18 21:43:05 -07001304 showAddDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 }
1306
Michael Jurka0280c3b2010-09-17 15:00:07 -07001307 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001308 mPendingAddInfo.container = ItemInfo.NO_ID;
1309 mPendingAddInfo.screen = -1;
1310 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1311 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1312 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001313 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001314
Winson Chung7ad01412010-09-27 11:33:03 -07001315 private void manageApps() {
1316 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1317 }
1318
Michael Jurkaaf442092010-06-10 17:01:57 -07001319 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001320 // TODO: catch bad widget exception when sent
1321 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001322 // TODO: Is this log message meaningful?
1323 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001324 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001325 }
1326
Winson Chung55cef262010-10-28 14:14:18 -07001327 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001328 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329
Bjorn Bringert7984c942009-12-09 15:38:25 +00001330 if (appWidget.configure != null) {
1331 // Launch over to configure widget, if needed
1332 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1333 intent.setComponent(appWidget.configure);
1334 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001335 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001336 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1337 intent.putExtra(
1338 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1339 info.mimeType);
1340
1341 final String mimeType = info.mimeType;
1342 final ClipData clipData = (ClipData) info.configurationData;
1343 final ClipDescription clipDesc = clipData.getDescription();
1344 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1345 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001346 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001347 final CharSequence stringData = item.getText();
1348 final Uri uriData = item.getUri();
1349 final Intent intentData = item.getIntent();
1350 final String key =
1351 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1352 if (uriData != null) {
1353 intent.putExtra(key, uriData);
1354 } else if (intentData != null) {
1355 intent.putExtra(key, intentData);
1356 } else if (stringData != null) {
1357 intent.putExtra(key, stringData);
1358 }
1359 break;
1360 }
1361 }
1362 }
Winson Chung55cef262010-10-28 14:14:18 -07001363 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001364
Romain Guy8e633c52010-03-04 12:51:36 -08001365 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001367 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001368 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001369
1370 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001371 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 }
1373 }
Romain Guycbb89e42009-06-08 15:52:54 -07001374
Adam Cohenfbba09b2011-07-18 21:43:05 -07001375 /**
1376 * Process a shortcut drop.
1377 *
1378 * @param componentName The name of the component
1379 * @param screen The screen where it should be added
1380 * @param cell The cell it should be added to, optional
1381 * @param position The location on the screen where it was dropped, optional
1382 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001383 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1384 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001385 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001386 mPendingAddInfo.container = container;
1387 mPendingAddInfo.screen = screen;
1388 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001389
1390 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001391 mPendingAddInfo.cellX = cell[0];
1392 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001393 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001394
1395 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1396 createShortcutIntent.setComponent(componentName);
1397 processShortcut(createShortcutIntent);
1398 }
1399
Adam Cohenfbba09b2011-07-18 21:43:05 -07001400 /**
1401 * Process a widget drop.
1402 *
1403 * @param info The PendingAppWidgetInfo of the widget being added.
1404 * @param screen The screen where it should be added
1405 * @param cell The cell it should be added to, optional
1406 * @param position The location on the screen where it was dropped, optional
1407 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001408 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1409 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001410 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001411 mPendingAddInfo.container = info.container = container;
1412 mPendingAddInfo.screen = info.screen = screen;
1413 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001414 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001415 mPendingAddInfo.cellX = cell[0];
1416 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001417 }
1418
1419 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1420 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1421 addAppWidgetImpl(appWidgetId, info);
1422 }
1423
Joe Onoratodeb98af2010-02-19 14:59:39 -08001424 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001425 // Handle case where user selected "Applications"
1426 String applicationName = getResources().getString(R.string.group_applications);
1427 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001428
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001429 if (applicationName != null && applicationName.equals(shortcutName)) {
1430 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1431 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001432
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001433 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1434 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001435 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001436 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001437 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001438 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001439 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 }
1441
Winson Chung24ab2f12010-09-16 14:10:47 -07001442 void processWallpaper(Intent intent) {
1443 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1444 }
1445
Winson Chung3d503fb2011-07-13 17:25:49 -07001446 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1447 int cellY) {
Adam Cohend0445262011-07-04 23:53:22 -07001448 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001449 folderInfo.title = getText(R.string.folder_name);
1450
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001452 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1453 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001454 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455
1456 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001457 FolderIcon newFolder =
1458 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1459 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1460 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001461 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462 }
Romain Guycbb89e42009-06-08 15:52:54 -07001463
Joe Onorato9c1289c2009-08-17 11:03:03 -04001464 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001465 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001466 }
1467
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 private void showNotifications() {
1469 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1470 if (statusBar != null) {
1471 statusBar.expand();
1472 }
1473 }
1474
1475 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001476 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001477 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001478 Intent chooser = Intent.createChooser(pickWallpaper,
1479 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001480 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1481 // Removed in Eclair MR1
1482// WallpaperManager wm = (WallpaperManager)
1483// getSystemService(Context.WALLPAPER_SERVICE);
1484// WallpaperInfo wi = wm.getWallpaperInfo();
1485// if (wi != null && wi.getSettingsActivity() != null) {
1486// LabeledIntent li = new LabeledIntent(getPackageName(),
1487// R.string.configure_wallpaper, 0);
1488// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1489// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1490// }
Mike Clerona0618e42009-10-22 13:55:21 -07001491 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 }
1493
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001494 /**
1495 * Registers various content observers. The current implementation registers
1496 * only a favorites observer to keep track of the favorites applications.
1497 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001498 private void registerContentObservers() {
1499 ContentResolver resolver = getContentResolver();
1500 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1501 true, mWidgetObserver);
1502 }
1503
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 @Override
1505 public boolean dispatchKeyEvent(KeyEvent event) {
1506 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1507 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001509 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001510 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001511 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001512 dumpState();
1513 return true;
1514 }
1515 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001516 }
1517 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1518 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001519 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 return true;
1521 }
1522 }
1523
1524 return super.dispatchKeyEvent(event);
1525 }
1526
Joe Onorato88ec0992009-11-19 13:16:06 -08001527 @Override
1528 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001529 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001530 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001531 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001532 Folder openFolder = mWorkspace.getOpenFolder();
1533 if (openFolder.isEditingName()) {
1534 openFolder.dismissEditingName();
1535 } else {
1536 closeFolder();
1537 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001538 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001539 mWorkspace.exitWidgetResizeMode();
1540
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001541 // Back button is a no-op here, but give at least some feedback for the button press
1542 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001543 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001544 }
1545
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001547 * Re-listen when widgets are reset.
1548 */
1549 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001550 if (mAppWidgetHost != null) {
1551 mAppWidgetHost.startListening();
1552 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001553 }
1554
1555 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001556 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1557 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001559 private void unbindWorkspaceAndHotseatItems() {
Adam Cohen4eac29a2011-07-11 17:53:37 -07001560 LauncherModel.unbindWorkspaceItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 /**
1564 * Launches the intent referred by the clicked shortcut.
1565 *
1566 * @param v The view representing the clicked shortcut.
1567 */
1568 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001569 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1570 // view has detached (it's possible for this to happen if the view is removed mid touch).
1571 if (v.getWindowToken() == null) {
1572 return;
1573 }
1574
1575 if (mWorkspace.isSwitchingState()) {
1576 return;
1577 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001578
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001580 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001582 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001583 int[] pos = new int[2];
1584 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001585 intent.setSourceBounds(new Rect(pos[0], pos[1],
1586 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001587 boolean success = startActivitySafely(intent, tag);
1588
1589 if (success && v instanceof BubbleTextView) {
1590 mWaitingForResume = (BubbleTextView) v;
1591 mWaitingForResume.setStayPressed(true);
1592 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001594 if (v instanceof FolderIcon) {
1595 FolderIcon fi = (FolderIcon) v;
1596 handleFolderClick(fi);
1597 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001598 } else if (v == mAllAppsButton) {
1599 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001600 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001601 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001602 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001603 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 }
1605 }
1606
Michael Jurka0e260592010-06-30 17:07:39 -07001607 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001608 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001609 // clicking anywhere on the workspace causes the customization drawer to slide down
1610 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001611 return false;
1612 }
1613
Michael Jurkaaf442092010-06-10 17:01:57 -07001614 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001615 * Event handler for the search button
1616 *
1617 * @param v The view that was clicked.
1618 */
1619 public void onClickSearchButton(View v) {
Amith Yamasania135ba82011-08-09 17:42:01 -07001620 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001621 }
1622
1623 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001624 * Event handler for the voice button
1625 *
1626 * @param v The view that was clicked.
1627 */
1628 public void onClickVoiceButton(View v) {
1629 startVoiceSearch();
1630 }
1631
1632 private void startVoiceSearch() {
1633 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1634 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1635 startActivity(intent);
1636 }
1637
1638 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001639 * Event handler for the "grid" button that appears on the home screen, which
1640 * enters all apps mode.
1641 *
1642 * @param v The view that was clicked.
1643 */
1644 public void onClickAllAppsButton(View v) {
1645 showAllApps(true);
1646 }
1647
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001648 public void onClickAppMarketButton(View v) {
1649 if (mAppMarketIntent != null) {
1650 startActivitySafely(mAppMarketIntent, "app market");
1651 }
1652 }
1653
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001654 void startApplicationDetailsActivity(ComponentName componentName) {
1655 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001656 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1657 Uri.fromParts("package", packageName, null));
1658 startActivity(intent);
1659 }
1660
Patrick Dubroy5539af72010-09-07 15:22:01 -07001661 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1662 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1663 // System applications cannot be installed. For now, show a toast explaining that.
1664 // We may give them the option of disabling apps this way.
1665 int messageId = R.string.uninstall_system_app_text;
1666 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1667 } else {
1668 String packageName = appInfo.componentName.getPackageName();
1669 String className = appInfo.componentName.getClassName();
1670 Intent intent = new Intent(
1671 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1672 startActivity(intent);
1673 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001674 }
1675
Michael Jurkaddd62e92011-02-16 17:49:14 -08001676 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001677 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1678 try {
1679 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001680 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 } catch (ActivityNotFoundException e) {
1682 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001683 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 } catch (SecurityException e) {
1685 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001686 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001687 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001688 "or use the exported attribute for this activity. "
1689 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001690 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001691 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001692 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001693
Romain Guy8e633c52010-03-04 12:51:36 -08001694 void startActivityForResultSafely(Intent intent, int requestCode) {
1695 try {
1696 startActivityForResult(intent, requestCode);
1697 } catch (ActivityNotFoundException e) {
1698 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1699 } catch (SecurityException e) {
1700 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1701 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1702 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1703 "or use the exported attribute for this activity.", e);
1704 }
1705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001706
Adam Cohena9cf38f2011-05-02 15:36:58 -07001707 private void handleFolderClick(FolderIcon folderIcon) {
1708 final FolderInfo info = folderIcon.mInfo;
1709 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 // Close any open folder
1711 closeFolder();
1712 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001713 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 } else {
1715 // Find the open folder...
Adam Cohena9cf38f2011-05-02 15:36:58 -07001716 Folder openFolder = mWorkspace.getFolderForTag(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 int folderScreen;
1718 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001719 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 // .. and close it
1721 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001722 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001723 // Close any folder open on the current screen
1724 closeFolder();
1725 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001726 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 }
1728 }
1729 }
1730 }
1731
Adam Cohen2801caf2011-05-13 20:57:39 -07001732 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001733 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001734 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1735 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1736 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1737
Adam Cohenc51934b2011-07-26 21:07:43 -07001738 FolderInfo info = (FolderInfo) fi.getTag();
1739 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1740 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001741 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1742 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001743 }
1744
Adam Cohen2801caf2011-05-13 20:57:39 -07001745 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1746 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1747 oa.start();
1748 }
1749
1750 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001751 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001752 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1753 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1754 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1755
Adam Cohenc51934b2011-07-26 21:07:43 -07001756 FolderInfo info = (FolderInfo) fi.getTag();
1757 CellLayout cl = null;
1758 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1759 cl = (CellLayout) fi.getParent().getParent();
1760 }
1761
1762 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001763 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1764 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001765 oa.addListener(new AnimatorListenerAdapter() {
1766 @Override
1767 public void onAnimationEnd(Animator animation) {
1768 if (layout != null) {
1769 layout.clearFolderLeaveBehind();
1770 }
1771 }
1772 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001773 oa.start();
1774 }
1775
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001776 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001777 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778 * is animated relative to the specified View. If the View is null, no animation
1779 * is played.
1780 *
1781 * @param folderInfo The FolderInfo describing the folder to open.
1782 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001783 public void openFolder(FolderIcon folderIcon) {
1784 Folder folder = folderIcon.mFolder;
1785 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786
Adam Cohen2801caf2011-05-13 20:57:39 -07001787 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001788 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789
Adam Cohen4554ee12011-08-03 16:13:21 -07001790 // Just verify that the folder hasn't already been added to the DragLayer.
1791 // There was a one-off crash where the folder had a parent already.
1792 if (folder.getParent() == null) {
1793 mDragLayer.addView(folder);
1794 mDragController.addDropTarget((DropTarget) folder);
1795 } else {
1796 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1797 folder.getParent() + ").");
1798 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001799 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001800 }
1801
1802 public void closeFolder() {
1803 Folder folder = mWorkspace.getOpenFolder();
1804 if (folder != null) {
1805 closeFolder(folder);
1806 }
1807 }
1808
1809 void closeFolder(Folder folder) {
1810 folder.getInfo().opened = false;
1811
1812 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1813 if (parent != null) {
1814 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1815 shrinkAndFadeInFolderIcon(fi);
1816 }
1817 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 }
1819
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001821 if (mState != State.WORKSPACE) {
1822 return false;
1823 }
1824
Joe Onorato9c1289c2009-08-17 11:03:03 -04001825 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001826 return false;
1827 }
1828
1829 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001830 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001831 }
1832
Michael Jurka0280c3b2010-09-17 15:00:07 -07001833 resetAddInfo();
1834 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001836 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 return true;
1838 }
1839
Winson Chung3d503fb2011-07-13 17:25:49 -07001840 // The hotseat touch handling does not go through Workspace, and we always allow long press
1841 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001842 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001843 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1844 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001845 if (itemUnderLongClick == null) {
1846 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001847 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1848 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001849 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001851 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001853 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001854 }
1855 }
1856 }
1857 return true;
1858 }
1859
Winson Chung3d503fb2011-07-13 17:25:49 -07001860 boolean isHotseatLayout(View layout) {
1861 return mHotseat != null && layout != null &&
1862 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1863 }
1864 Hotseat getHotseat() {
1865 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001866 }
1867
Winson Chung3d503fb2011-07-13 17:25:49 -07001868 /**
1869 * Returns the CellLayout of the specified container at the specified screen.
1870 */
1871 CellLayout getCellLayout(long container, int screen) {
1872 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1873 if (mHotseat != null) {
1874 return mHotseat.getLayout();
1875 } else {
1876 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001877 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001878 } else {
1879 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001880 }
1881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 Workspace getWorkspace() {
1884 return mWorkspace;
1885 }
1886
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 @Override
1888 protected Dialog onCreateDialog(int id) {
1889 switch (id) {
1890 case DIALOG_CREATE_SHORTCUT:
1891 return new CreateShortcut().createDialog();
1892 case DIALOG_RENAME_FOLDER:
1893 return new RenameFolder().createDialog();
1894 }
1895
1896 return super.onCreateDialog(id);
1897 }
1898
1899 @Override
1900 protected void onPrepareDialog(int id, Dialog dialog) {
1901 switch (id) {
1902 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 break;
1904 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001905 if (mFolderInfo != null) {
1906 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1907 final CharSequence text = mFolderInfo.title;
1908 input.setText(text);
1909 input.setSelection(0, text.length());
1910 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 break;
1912 }
1913 }
1914
1915 void showRenameDialog(FolderInfo info) {
1916 mFolderInfo = info;
1917 mWaitingForResult = true;
1918 showDialog(DIALOG_RENAME_FOLDER);
1919 }
1920
Adam Cohenfbba09b2011-07-18 21:43:05 -07001921 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001922 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001923 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1924 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 mWaitingForResult = true;
1926 showDialog(DIALOG_CREATE_SHORTCUT);
1927 }
1928
1929 private class RenameFolder {
1930 private EditText mInput;
1931
1932 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1934 mInput = (EditText) layout.findViewById(R.id.folder_name);
1935
1936 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1937 builder.setIcon(0);
1938 builder.setTitle(getString(R.string.rename_folder_title));
1939 builder.setCancelable(true);
1940 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1941 public void onCancel(DialogInterface dialog) {
1942 cleanup();
1943 }
1944 });
1945 builder.setNegativeButton(getString(R.string.cancel_action),
1946 new Dialog.OnClickListener() {
1947 public void onClick(DialogInterface dialog, int which) {
1948 cleanup();
1949 }
1950 }
1951 );
1952 builder.setPositiveButton(getString(R.string.rename_action),
1953 new Dialog.OnClickListener() {
1954 public void onClick(DialogInterface dialog, int which) {
1955 changeFolderName();
1956 }
1957 }
1958 );
1959 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001960
1961 final AlertDialog dialog = builder.create();
1962 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1963 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001964 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001965 mInput.requestFocus();
1966 InputMethodManager inputManager = (InputMethodManager)
1967 getSystemService(Context.INPUT_METHOD_SERVICE);
1968 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001969 }
1970 });
1971
1972 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 }
1974
1975 private void changeFolderName() {
1976 final String name = mInput.getText().toString();
1977 if (!TextUtils.isEmpty(name)) {
1978 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001979 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 mFolderInfo.title = name;
1981 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1982
Joe Onorato9c1289c2009-08-17 11:03:03 -04001983 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001984 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001985 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 } else {
1987 final FolderIcon folderIcon = (FolderIcon)
1988 mWorkspace.getViewForTag(mFolderInfo);
1989 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001990 // TODO: At some point we'll probably want some version of setting
1991 // the text for a folder icon.
1992 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 getWorkspace().requestLayout();
1994 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001995 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001996 mWorkspaceLoading = true;
1997 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001998 }
1999 }
2000 }
2001 cleanup();
2002 }
2003
2004 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 dismissDialog(DIALOG_RENAME_FOLDER);
2006 mWaitingForResult = false;
2007 mFolderInfo = null;
2008 }
2009 }
2010
Daniel Sandler843e8602010-06-07 14:59:01 -04002011 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2012 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002013 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002014 }
2015
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002016 // AllAppsView.Watcher
2017 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002018 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002019 mWorkspace.setVisibility(View.GONE);
2020 }
2021 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002022
2023 /**
2024 * Helper method for the cameraZoomIn/cameraZoomOut animations
2025 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002026 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002027 * @param scaleFactor The scale factor used for the zoom
2028 */
2029 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2030 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002031
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002032 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002033 // Set pivotY so that at the starting zoom factor, the view is partially
2034 // visible. Modifying initialHeightFactor changes how much of the view is
2035 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002036 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002037 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002038 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002039 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002040 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002041 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002042 }
2043 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002044
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002045 /**
2046 * Zoom the camera out from the workspace to reveal 'toView'.
2047 * Assumes that the view to show is anchored at either the very top or very bottom
2048 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002049 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002050 */
Winson Chungc07918d2011-07-01 15:35:26 -07002051 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002052 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002053
Winson Chungf0ea4d32011-06-06 14:27:16 -07002054 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2055 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2056 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2057 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002058
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002059 setPivotsForZoom(toView, toState, scale);
2060
Michael Jurkad74c9842011-07-10 12:44:21 -07002061 // Shrink workspaces away if going to AppsCustomize from workspace
2062 mWorkspace.shrink(Workspace.State.SMALL, animated);
Winson Chung4afe9b32011-07-27 17:46:20 -07002063 hideHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002064
2065 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002066 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002067 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002068 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2069 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002070 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002071 toView.setFastScaleX(a * scale + b * 1f);
2072 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002073 }
2074 });
Adam Cohen61033d32010-11-15 18:29:44 -08002075
Winson Chungf0ea4d32011-06-06 14:27:16 -07002076 toView.setVisibility(View.VISIBLE);
2077 toView.setFastAlpha(0f);
2078 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2079 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2080 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2081 public void onAnimationUpdate(float a, float b) {
2082 // don't need to invalidate because we do so above
2083 toView.setFastAlpha(a * 0f + b * 1f);
2084 }
2085 });
2086 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002087
Michael Jurkaabded662011-03-04 12:06:57 -08002088 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002089 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002090 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002091 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002092 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002093 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002094 // Prepare the position
2095 toView.setTranslationX(0.0f);
2096 toView.setTranslationY(0.0f);
2097 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002098 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002099 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002100 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002101 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002102 // If we don't set the final scale values here, if this animation is cancelled
2103 // it will have the wrong scale value and subsequent cameraPan animations will
2104 // not fix that
2105 toView.setScaleX(1.0f);
2106 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002107 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002108 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002109 }
Winson Chung32174c82011-07-19 15:47:55 -07002110
2111 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2112 // Hide the workspace scrollbar
2113 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002114 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002115 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002116 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002117 });
2118
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002119 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002120 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002121
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002122 if (mStateAnimation != null) mStateAnimation.cancel();
2123 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002124 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002125 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002126 } else {
2127 toView.setTranslationX(0.0f);
2128 toView.setTranslationY(0.0f);
2129 toView.setScaleX(1.0f);
2130 toView.setScaleY(1.0f);
2131 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002132 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002133 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002134 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2135 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002136
Winson Chungc07918d2011-07-01 15:35:26 -07002137 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2138 // Hide the workspace scrollbar
2139 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002140 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002141 }
Michael Jurkaabded662011-03-04 12:06:57 -08002142 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002143 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002144 }
2145
2146 /**
2147 * Zoom the camera back into the workspace, hiding 'fromView'.
2148 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002149 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002150 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002151 */
Winson Chungc07918d2011-07-01 15:35:26 -07002152 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002153 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002154
Winson Chungf0ea4d32011-06-06 14:27:16 -07002155 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2156 final float scaleFactor = (float)
2157 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2158 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002159
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002160 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002161
Michael Jurkad3ef3062010-11-23 16:23:58 -08002162 if (!springLoaded) {
2163 mWorkspace.unshrink(animated);
2164 }
Winson Chung4afe9b32011-07-27 17:46:20 -07002165 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002166 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002167 if (mStateAnimation != null) mStateAnimation.cancel();
2168 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002169
Michael Jurka742574b2011-02-02 23:51:01 -08002170 final float oldScaleX = fromView.getScaleX();
2171 final float oldScaleY = fromView.getScaleY();
2172
2173 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2174 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002175 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2176 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002177 ((View)fromView.getParent()).fastInvalidate();
2178 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2179 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2180 }
2181 });
Michael Jurkaabded662011-03-04 12:06:57 -08002182 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002183 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002184 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002185 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2186 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002187 // don't need to invalidate because we do so above
2188 fromView.setFastAlpha(a * 1f + b * 0f);
2189 }
2190 });
Michael Jurkaabded662011-03-04 12:06:57 -08002191 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002192 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002193 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002194 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002195 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002196 public void onAnimationStart(android.animation.Animator animation) {
2197 if (!springLoaded) {
2198 mWorkspace.showDockDivider(false);
2199 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002200 mWorkspace.showScrollingIndicator(false);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002201 }
2202 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002203 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002204 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002205 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002206 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002207 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002208 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002209 }
2210 });
2211
Winson Chungf0ea4d32011-06-06 14:27:16 -07002212 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002213 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002214 } else {
2215 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002216 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002217 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2218 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002219
Winson Chungc07918d2011-07-01 15:35:26 -07002220 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002221 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002222 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002223 mWorkspace.flashScrollingIndicator();
2224 }
Michael Jurkaabded662011-03-04 12:06:57 -08002225 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002226 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002227 }
2228
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002229 void showWorkspace(boolean animated) {
2230 showWorkspace(animated, null);
2231 }
2232
2233 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002234 if (layout != null) {
2235 // always animated, but that's ok since we never specify a layout and
2236 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002237 mWorkspace.unshrink(layout);
2238 } else {
2239 mWorkspace.unshrink(animated);
2240 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002241 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002242 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002243 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002244
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002245 // Change the state *after* we've called all the transition code
2246 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002247
Winson Chung5fb63472011-02-02 17:03:37 -08002248 // Resume the auto-advance of widgets
2249 mUserPresent = true;
2250 updateRunning();
2251
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002252 // send an accessibility event to announce the context change
2253 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002254 }
2255
Michael Jurkad3ef3062010-11-23 16:23:58 -08002256 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002257 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002258 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002259 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002260 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002261 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002262 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002263 }
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002264 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chunge7a03942011-08-05 15:05:12 -07002265 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002266 @Override
2267 public void run() {
2268 exitSpringLoadedDragMode();
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002269
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002270 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002271 // Before we show workspace, hide all apps again because
2272 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2273 // clean up our state transition functions
2274 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002275 showWorkspace(true);
2276 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002277 }
2278 }, (extendedDelay ?
2279 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2280 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2281 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002282 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002283 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002284 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002285 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2286 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002287 }
2288 // Otherwise, we are not in spring loaded mode, so don't do anything.
2289 }
2290
Adam Cohenfc53cd22011-07-20 15:45:11 -07002291 public boolean isAllAppsCustomizeOpen() {
2292 return mState == State.APPS_CUSTOMIZE;
2293 }
2294
Winson Chungf0ea4d32011-06-06 14:27:16 -07002295 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002296 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002297 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002298 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002299 if (!LauncherApplication.isScreenLarge()) {
2300 if (animated) {
2301 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002302 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002303 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002305 }
2306 }
2307 }
2308
2309 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002311 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002312 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002313 if (!LauncherApplication.isScreenLarge()) {
2314 if (animated) {
2315 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002316 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002317 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002318 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002319 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002320 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002321 }
2322
Winson Chung785d2eb2011-04-14 16:08:02 -07002323 void showAllApps(boolean animated) {
2324 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002325
Winson Chungf0ea4d32011-06-06 14:27:16 -07002326 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2327 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002328
Winson Chung3d503fb2011-07-13 17:25:49 -07002329 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002330 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002331
Winson Chungf0ea4d32011-06-06 14:27:16 -07002332 // Change the state *after* we've called all the transition code
2333 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002334
2335 // Pause the auto-advance of widgets until we are out of AllApps
2336 mUserPresent = false;
2337 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002338 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002339
2340 // Send an accessibility event to announce the context change
2341 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2342 }
2343
Joe Onoratob2061212009-11-24 16:13:54 -05002344 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002345 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002346 * - Home from workspace
2347 * - from center screen
2348 * - from other screens
2349 * - Home 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 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002353 * - from center screen
2354 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002355 * - Launch app from workspace and quit
2356 * - with back
2357 * - with home
2358 * - Launch app from all apps and quit
2359 * - with back
2360 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002361 * - Go to a screen that's not the default, then all
2362 * apps, and launch and app, and go back
2363 * - with back
2364 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002365 * - On workspace, long press power and go back
2366 * - with back
2367 * - with home
2368 * - On all apps, long press power and go back
2369 * - with back
2370 * - with home
2371 * - On workspace, power off
2372 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002373 * - Launch an app and turn off the screen while in that app
2374 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002375 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002376 * - From all apps
2377 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002378 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2379 * - From all apps
2380 * - From the center workspace
2381 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002382 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002383 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002384 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2385 mWorkspace.setVisibility(View.VISIBLE);
2386 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002387
Winson Chung3d503fb2011-07-13 17:25:49 -07002388 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002389 mSearchDeleteBar.showSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002390
Winson Chungf0ea4d32011-06-06 14:27:16 -07002391 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002392 if (mAllAppsButton != null) {
2393 mAllAppsButton.requestFocus();
2394 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002395 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002396 }
2397
Joe Onorato7c312c12009-08-13 21:36:53 -07002398 void lockAllApps() {
2399 // TODO
2400 }
2401
2402 void unlockAllApps() {
2403 // TODO
2404 }
2405
Patrick Dubroy5f445422011-02-18 14:35:21 -08002406 /**
2407 * Add an item from all apps or customize onto the given workspace screen.
2408 * If layout is null, add to the current screen.
2409 */
2410 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002411 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2412 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002413 } else {
2414 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002415 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002416 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002417
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002418 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002419 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002420 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002421 // Look for the toolbar icon specified in the activity meta-data
2422 Bundle metaData = packageManager.getActivityInfo(
2423 activityName, PackageManager.GET_META_DATA).metaData;
2424 if (metaData != null) {
2425 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2426 if (iconResId != 0) {
2427 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002428 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002429 }
2430 }
2431 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002432 // This can happen if the activity defines an invalid drawable
2433 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2434 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002435 } catch (Resources.NotFoundException nfe) {
2436 // This can happen if the activity defines an invalid drawable
2437 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2438 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002439 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002440 return null;
2441 }
2442
2443 // if successful in getting icon, return it; otherwise, set button to use default drawable
2444 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2445 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2446 TextView button = (TextView) findViewById(buttonId);
2447 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2448
2449 // If we were unable to find the icon via the meta-data, use a generic one
2450 if (toolbarIcon == null) {
2451 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2452 return null;
2453 } else {
2454 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2455 return toolbarIcon.getConstantState();
2456 }
2457 }
2458
2459 // if successful in getting icon, return it; otherwise, set button to use default drawable
2460 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2461 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2462 ImageView button = (ImageView) findViewById(buttonId);
2463 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2464
Michael Jurka19e0fc52011-07-22 18:00:21 -07002465 if (button != null) {
2466 // If we were unable to find the icon via the meta-data, use a
2467 // generic one
2468 if (toolbarIcon == null) {
2469 button.setImageResource(fallbackDrawableId);
2470 } else {
2471 button.setImageDrawable(toolbarIcon);
2472 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002473 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002474
2475 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2476
Michael Jurka0423dcf2010-10-05 14:56:18 -07002477 }
2478
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002479 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2480 TextView button = (TextView) findViewById(buttonId);
2481 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2482 }
2483
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002484 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002485 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002486 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002487 }
2488
Michael Jurka0423dcf2010-10-05 14:56:18 -07002489 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002490 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2491 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002492
Winson Chung1cad91e2011-05-25 17:41:01 -07002493 final SearchManager searchManager =
2494 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2495 ComponentName activityName = searchManager.getGlobalSearchActivity();
2496 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002497 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002498 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002499 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002500 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002501 } else {
2502 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002503 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002504 }
2505 }
2506
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002507 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002508 updateButtonWithDrawable(R.id.search_button, d);
2509 }
2510
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002511 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002512 final View searchDivider = findViewById(R.id.search_divider);
2513 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002514
Winson Chung1cad91e2011-05-25 17:41:01 -07002515 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2516 ComponentName activityName = intent.resolveActivity(getPackageManager());
2517 if (activityName != null) {
2518 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002519 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2520 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002521 voiceButton.setVisibility(View.VISIBLE);
2522 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002523 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002524 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002525 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002526 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002527
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002528 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002529 updateButtonWithDrawable(R.id.voice_button, d);
2530 }
2531
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002532 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002533 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002534 */
2535 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002536 final View marketButton = findViewById(R.id.market_button);
2537 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2538 // Find the app market activity by resolving an intent.
2539 // (If multiple app markets are installed, it will return the ResolverActivity.)
2540 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002541 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002542 mAppMarketIntent = intent;
2543 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002544 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002545 marketButton.setVisibility(View.VISIBLE);
2546 } else {
2547 // We should hide and disable the view so that we don't try and restore the visibility
2548 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2549 marketButton.setVisibility(View.GONE);
2550 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002551 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002552 }
2553
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002554 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002555 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002556 }
2557
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002558 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002559 * Displays the shortcut creation dialog and launches, if necessary, the
2560 * appropriate activity.
2561 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002562 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002563 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2564 DialogInterface.OnShowListener {
2565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002567
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002568 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002570
Winson Chung55b65502011-05-26 12:03:43 -07002571 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2572 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002573 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002574
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002575 AlertDialog dialog = builder.create();
2576 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002577 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002578 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002579
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002580 return dialog;
2581 }
2582
2583 public void onCancel(DialogInterface dialog) {
2584 mWaitingForResult = false;
2585 cleanup();
2586 }
2587
Romain Guycbb89e42009-06-08 15:52:54 -07002588 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002589 mWaitingForResult = false;
2590 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002591 }
2592
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002594 try {
2595 dismissDialog(DIALOG_CREATE_SHORTCUT);
2596 } catch (Exception e) {
2597 // An exception is thrown if the dialog is not visible, which is fine
2598 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002599 }
2600
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002601 /**
2602 * Handle the action clicked in the "Add to home" dialog.
2603 */
2604 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002605 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002606
Winson Chung55b65502011-05-26 12:03:43 -07002607 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2608 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002609 case AddAdapter.ITEM_APPLICATION: {
2610 if (mAppsCustomizeTabHost != null) {
2611 mAppsCustomizeTabHost.selectAppsTab();
2612 }
2613 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002614 break;
2615 }
Winson Chung55b65502011-05-26 12:03:43 -07002616 case AddAdapter.ITEM_APPWIDGET: {
2617 if (mAppsCustomizeTabHost != null) {
2618 mAppsCustomizeTabHost.selectWidgetsTab();
2619 }
2620 showAllApps(true);
2621 break;
2622 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002623 case AddAdapter.ITEM_WALLPAPER: {
2624 startWallpaper();
2625 break;
2626 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002627 }
2628 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002629
2630 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002631 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002632 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002633 }
2634
2635 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002636 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002637 */
2638 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2639 @Override
2640 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002641 closeSystemDialogs();
2642 }
2643 }
2644
2645 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002646 * Receives notifications whenever the appwidgets are reset.
2647 */
2648 private class AppWidgetResetObserver extends ContentObserver {
2649 public AppWidgetResetObserver() {
2650 super(new Handler());
2651 }
2652
2653 @Override
2654 public void onChange(boolean selfChange) {
2655 onAppWidgetReset();
2656 }
2657 }
2658
2659 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002660 * If the activity is currently paused, signal that we need to re-run the loader
2661 * in onResume.
2662 *
2663 * This needs to be called from incoming places where resources might have been loaded
2664 * while we are paused. That is becaues the Configuration might be wrong
2665 * when we're not running, and if it comes back to what it was when we
2666 * were paused, we are not restarted.
2667 *
2668 * Implementation of the method from LauncherModel.Callbacks.
2669 *
2670 * @return true if we are currently paused. The caller might be able to
2671 * skip some work in that case since we will come back again.
2672 */
2673 public boolean setLoadOnResume() {
2674 if (mPaused) {
2675 Log.i(TAG, "setLoadOnResume");
2676 mOnResumeNeedsLoad = true;
2677 return true;
2678 } else {
2679 return false;
2680 }
2681 }
2682
2683 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002684 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002685 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002686 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002687 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002688 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002689 } else {
2690 return SCREEN_COUNT / 2;
2691 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002692 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002693
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002694
Joe Onorato9c1289c2009-08-17 11:03:03 -04002695 /**
2696 * Refreshes the shortcuts shown on the workspace.
2697 *
2698 * Implementation of the method from LauncherModel.Callbacks.
2699 */
2700 public void startBinding() {
2701 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002702
2703 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002704 int count = workspace.getChildCount();
2705 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002706 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002707 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2708 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002709 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002710 if (mHotseat != null) {
2711 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002712 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002713
Adam Cohen4eac29a2011-07-11 17:53:37 -07002714 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002715 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002716 }
2717
2718 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002719 * Bind the items start-end from the list.
2720 *
2721 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002722 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002723 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002724 setLoadOnResume();
2725
Joe Onorato9c1289c2009-08-17 11:03:03 -04002726 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002727 for (int i=start; i<end; i++) {
2728 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002729
2730 // Short circuit if we are loading dock items for a configuration which has no dock
2731 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2732 mHotseat == null) {
2733 continue;
2734 }
2735
Joe Onorato9c1289c2009-08-17 11:03:03 -04002736 switch (item.itemType) {
2737 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2738 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002739 View shortcut = createShortcut((ShortcutInfo)item);
2740 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2741 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002742 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002743 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002744 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002745 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002746 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002747 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2748 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002749 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002752 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002753 }
2754
Joe Onorato9c1289c2009-08-17 11:03:03 -04002755 /**
2756 * Implementation of the method from LauncherModel.Callbacks.
2757 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002758 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002759 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002760 sFolders.clear();
2761 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002762 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002763
2764 /**
2765 * Add the views for a widget to the workspace.
2766 *
2767 * Implementation of the method from LauncherModel.Callbacks.
2768 */
2769 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002770 setLoadOnResume();
2771
Daniel Sandler843e8602010-06-07 14:59:01 -04002772 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2773 if (DEBUG_WIDGETS) {
2774 Log.d(TAG, "bindAppWidget: " + item);
2775 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002776 final Workspace workspace = mWorkspace;
2777
2778 final int appWidgetId = item.appWidgetId;
2779 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002780 if (DEBUG_WIDGETS) {
2781 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2782 }
2783
Joe Onorato9c1289c2009-08-17 11:03:03 -04002784 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2785
Joe Onorato9c1289c2009-08-17 11:03:03 -04002786 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2787 item.hostView.setTag(item);
2788
Winson Chung3d503fb2011-07-13 17:25:49 -07002789 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002790 item.cellY, item.spanX, item.spanY, false);
2791
Adam Cohended9f8d2010-11-03 13:25:16 -07002792 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2793
Joe Onorato9c1289c2009-08-17 11:03:03 -04002794 workspace.requestLayout();
2795
Daniel Sandler843e8602010-06-07 14:59:01 -04002796 if (DEBUG_WIDGETS) {
2797 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2798 + (SystemClock.uptimeMillis()-start) + "ms");
2799 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002800 }
2801
2802 /**
2803 * Callback saying that there aren't any more items to bind.
2804 *
2805 * Implementation of the method from LauncherModel.Callbacks.
2806 */
2807 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002808 setLoadOnResume();
2809
Joe Onorato9c1289c2009-08-17 11:03:03 -04002810 if (mSavedState != null) {
2811 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002812 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002813 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002814 mSavedState = null;
2815 }
2816
2817 if (mSavedInstanceState != null) {
2818 super.onRestoreInstanceState(mSavedInstanceState);
2819 mSavedInstanceState = null;
2820 }
2821
Joe Onorato9c1289c2009-08-17 11:03:03 -04002822 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002823
2824 // If we received the result of any pending adds while the loader was running (e.g. the
2825 // widget configuration forced an orientation change), process them now.
2826 for (int i = 0; i < sPendingAddList.size(); i++) {
2827 completeAdd(sPendingAddList.get(i));
2828 }
2829 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002830 }
2831
2832 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002833 * Updates the icons on the launcher that are affected by changes to the package list
2834 * on the device.
2835 */
2836 private void updateIconsAffectedByPackageManagerChanges() {
2837 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002838 updateVoiceSearchIcon();
2839 }
2840
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002841 @Override
2842 public void bindSearchablesChanged() {
2843 updateGlobalSearchIcon();
2844 }
2845
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002846 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002847 * Add the icons for all apps.
2848 *
2849 * Implementation of the method from LauncherModel.Callbacks.
2850 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07002851 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
2852 // Remove the progress bar entirely; we could also make it GONE
2853 // but better to remove it since we know it's not going to be used
2854 View progressBar = mAppsCustomizeTabHost.
2855 findViewById(R.id.apps_customize_progress_bar);
2856 if (progressBar != null) {
2857 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07002858 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07002859 // We just post the call to setApps so the user sees the progress bar
2860 // disappear-- otherwise, it just looks like the progress bar froze
2861 // which doesn't look great
2862 mAppsCustomizeTabHost.post(new Runnable() {
2863 public void run() {
2864 if (mAppsCustomizeContent != null) {
2865 mAppsCustomizeContent.setApps(apps);
2866 }
2867 }
2868 });
2869
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002870 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002871 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002872 }
2873
2874 /**
2875 * A package was installed.
2876 *
2877 * Implementation of the method from LauncherModel.Callbacks.
2878 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002879 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002880 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002881 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002882
Winson Chung785d2eb2011-04-14 16:08:02 -07002883 if (mAppsCustomizeContent != null) {
2884 mAppsCustomizeContent.addApps(apps);
2885 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002886 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002887 }
2888
2889 /**
2890 * A package was updated.
2891 *
2892 * Implementation of the method from LauncherModel.Callbacks.
2893 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002894 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002895 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002896 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002897 if (mWorkspace != null) {
2898 mWorkspace.updateShortcuts(apps);
2899 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002900
Winson Chung785d2eb2011-04-14 16:08:02 -07002901 if (mAppsCustomizeContent != null) {
2902 mAppsCustomizeContent.updateApps(apps);
2903 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002904 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002905 }
2906
2907 /**
2908 * A package was uninstalled.
2909 *
2910 * Implementation of the method from LauncherModel.Callbacks.
2911 */
Joe Onorato36115782010-06-17 13:28:48 -04002912 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002913 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002914 if (permanent) {
2915 mWorkspace.removeItems(apps);
2916 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002917
Winson Chung785d2eb2011-04-14 16:08:02 -07002918 if (mAppsCustomizeContent != null) {
2919 mAppsCustomizeContent.removeApps(apps);
2920 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002921 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002922 }
Joe Onoratobe386092009-11-17 17:32:16 -08002923
2924 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002925 * A number of packages were updated.
2926 */
2927 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002928
Winson Chung785d2eb2011-04-14 16:08:02 -07002929 if (mAppsCustomizeContent != null) {
2930 mAppsCustomizeContent.onPackagesUpdated();
2931 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002932 }
2933
Winson Chung400438b2011-01-16 17:53:48 -08002934 private int mapConfigurationOriActivityInfoOri(int configOri) {
2935 final Display d = getWindowManager().getDefaultDisplay();
2936 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2937 switch (d.getRotation()) {
2938 case Surface.ROTATION_0:
2939 case Surface.ROTATION_180:
2940 // We are currently in the same basic orientation as the natural orientation
2941 naturalOri = configOri;
2942 break;
2943 case Surface.ROTATION_90:
2944 case Surface.ROTATION_270:
2945 // We are currently in the other basic orientation to the natural orientation
2946 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2947 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2948 break;
2949 }
2950
2951 int[] oriMap = {
2952 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2953 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2954 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2955 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2956 };
2957 // Since the map starts at portrait, we need to offset if this device's natural orientation
2958 // is landscape.
2959 int indexOffset = 0;
2960 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2961 indexOffset = 1;
2962 }
2963 return oriMap[(d.getRotation() + indexOffset) % 4];
2964 }
2965 public void lockScreenOrientation() {
2966 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2967 .getConfiguration().orientation));
2968 }
2969 public void unlockScreenOrientation() {
2970 mHandler.postDelayed(new Runnable() {
2971 public void run() {
2972 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2973 }
2974 }, mRestoreScreenOrientationDelay);
2975 }
2976
Winson Chung82f55532011-08-09 14:14:23 -07002977 /* Cling related */
2978 private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed";
2979 private static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed";
2980 private void enableClingsIfNecessary() {
2981 // TEMPORARY: DISABLE CLINGS ON LARGE UI
2982 if (LauncherApplication.isScreenLarge()) return;
2983
2984 // Enable the clings only if they have not been dismissed before
2985 SharedPreferences prefs =
2986 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
2987 if (!prefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false)) {
2988 Cling cling = (Cling) findViewById(R.id.workspace_cling);
2989 cling.init(this);
2990 cling.setVisibility(View.VISIBLE);
2991 }
2992 if (!prefs.getBoolean(ALLAPPS_CLING_DISMISSED_KEY, false)) {
2993 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
2994 cling.init(this);
2995 cling.setVisibility(View.VISIBLE);
2996 }
2997 }
2998 private void dismissCling(final Cling cling, final String flag) {
2999 if (cling != null) {
3000 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
3001 anim.setDuration(DISMISS_CLING_DURATION);
3002 anim.addListener(new AnimatorListenerAdapter() {
3003 public void onAnimationEnd(Animator animation) {
3004 cling.setVisibility(View.GONE);
3005 cling.cleanup();
3006 SharedPreferences prefs =
3007 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3008 SharedPreferences.Editor editor = prefs.edit();
3009 editor.putBoolean(flag, true);
3010 editor.commit();
3011 };
3012 });
3013 anim.start();
3014 }
3015 }
3016 public void dismissWorkspaceCling(View v) {
3017 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3018 dismissCling(cling, WORKSPACE_CLING_DISMISSED_KEY);
3019 }
3020 public void dismissAllAppsCling(View v) {
3021 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
3022 dismissCling(cling, ALLAPPS_CLING_DISMISSED_KEY);
3023 }
3024
Winson Chung80baf5a2010-08-09 16:03:15 -07003025 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003026 * Prints out out state for debugging.
3027 */
3028 public void dumpState() {
3029 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003030 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003031 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3032 Log.d(TAG, "mRestoring=" + mRestoring);
3033 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3034 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003035 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003036 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003037
Winson Chung785d2eb2011-04-14 16:08:02 -07003038 if (mAppsCustomizeContent != null) {
3039 mAppsCustomizeContent.dumpState();
3040 }
Joe Onoratobe386092009-11-17 17:32:16 -08003041 Log.d(TAG, "END launcher2 dump state");
3042 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003043}
Michael Jurka2763be32011-02-24 11:19:57 -08003044
Michael Jurkaabded662011-03-04 12:06:57 -08003045interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07003046 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
3047 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003048}