blob: 2fade8f3595b839962efe1e017c4f5829d3de289 [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;
Brett Chabot2a9e2282011-08-23 15:03:13 -070027import android.app.ActivityManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.Dialog;
30import android.app.SearchManager;
31import android.app.StatusBarManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070036import android.content.ClipData;
37import android.content.ClipDescription;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
41import android.content.DialogInterface;
42import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070051import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040053import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070054import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020056import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080057import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070058import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040059import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080060import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070061import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080062import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.text.Selection;
64import android.text.SpannableStringBuilder;
65import android.text.TextUtils;
66import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070067import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080068import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080069import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.view.KeyEvent;
71import android.view.LayoutInflater;
72import android.view.Menu;
73import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070074import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080075import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.View;
Adam Cohen860f4c52011-01-27 20:16:13 -080077import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070078import android.view.ViewGroup;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080079import android.view.accessibility.AccessibilityEvent;
Adam Cohenf16e5712011-01-13 13:31:45 -080080import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070082import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070084import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070085import android.widget.TextView;
86import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070087
Adam Cohendf2cc412011-04-27 16:56:57 -070088import com.android.common.Search;
89import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070090import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080091
Adam Cohenc0dcf592011-06-01 15:30:43 -070092import java.io.DataInputStream;
93import java.io.DataOutputStream;
94import java.io.FileNotFoundException;
95import java.io.IOException;
96import java.util.ArrayList;
97import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -070098
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099/**
100 * Default launcher application.
101 */
Michael Jurka946ad472010-07-09 18:05:18 -0700102public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700103 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
104 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800105 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700106 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107
Joe Onorato9c1289c2009-08-17 11:03:03 -0400108 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400109 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700110
Winson Chung70d72102011-08-12 11:24:35 -0700111 private static final int MENU_GROUP_WALLPAPER = 1;
112 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
113 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700114 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
115 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
117 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700118 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 private static final int REQUEST_PICK_APPLICATION = 6;
120 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700121 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700122 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
124 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
125
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800126 static final int SCREEN_COUNT = 5;
127 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Joe Onorato7c312c12009-08-13 21:36:53 -0700129 static final int DIALOG_CREATE_SHORTCUT = 1;
130 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
Romain Guy98d01652009-06-30 16:21:04 -0700132 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133
134 // Type: int
135 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700136 // Type: int
137 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700139 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
140 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
142 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700143 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700145 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 // Type: boolean
147 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
148 // Type: long
149 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
150
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700151 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
152
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700153 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700154 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700155 private State mState = State.WORKSPACE;
156 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700157
Joe Onorato9c1289c2009-08-17 11:03:03 -0400158 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700159 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
160 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung82f55532011-08-09 14:14:23 -0700161 private static final int DISMISS_CLING_DURATION = 300;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800164 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800166 private final BroadcastReceiver mCloseSystemDialogsReceiver
167 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800168 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
169
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 private LayoutInflater mInflater;
171
Joe Onorato00acb122009-08-04 16:04:30 -0400172 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700174
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700175 private AppWidgetManager mAppWidgetManager;
176 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700177
Winson Chung3d503fb2011-07-13 17:25:49 -0700178 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700179 private int[] mTmpAddItemCellCoordinates = new int[2];
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private FolderInfo mFolderInfo;
182
Winson Chung3d503fb2011-07-13 17:25:49 -0700183 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800184 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700185
Winson Chungf0ea4d32011-06-06 14:27:16 -0700186 private SearchDropTargetBar mSearchDeleteBar;
187 private AppsCustomizeTabHost mAppsCustomizeTabHost;
188 private AppsCustomizePagedView mAppsCustomizeContent;
189 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 private Bundle mSavedState;
192
193 private SpannableStringBuilder mDefaultKeySsb = null;
194
Joe Onorato9c1289c2009-08-17 11:03:03 -0400195 private boolean mWorkspaceLoading = true;
196
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800197 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800198 private boolean mRestoring;
199 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700200 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201
202 private Bundle mSavedInstanceState;
203
Joe Onorato9c1289c2009-08-17 11:03:03 -0400204 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800205 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800206 private boolean mUserPresent = true;
207 private boolean mVisible = false;
208 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700210 private static LocaleConfiguration sLocaleConfiguration = null;
211
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700212 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700213
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700214 private Intent mAppMarketIntent = null;
215
Adam Cohended9f8d2010-11-03 13:25:16 -0700216 // Related to the auto-advancing of widgets
217 private final int ADVANCE_MSG = 1;
218 private final int mAdvanceInterval = 20000;
219 private final int mAdvanceStagger = 250;
220 private long mAutoAdvanceSentTime;
221 private long mAutoAdvanceTimeLeft = -1;
222 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
223 new HashMap<View, AppWidgetProviderInfo>();
224
Winson Chung400438b2011-01-16 17:53:48 -0800225 // Determines how long to wait after a rotation before restoring the screen orientation to
226 // match the sensor state.
227 private final int mRestoreScreenOrientationDelay = 500;
228
Michael Jurka4ef207b2010-11-29 17:05:45 -0800229 // External icons saved in case of resource changes, orientation, etc.
Michael Jurkae7bf83b2010-12-14 18:02:21 -0800230 private static Drawable.ConstantState sGlobalSearchIcon;
231 private static Drawable.ConstantState sVoiceSearchIcon;
232 private static Drawable.ConstantState sAppMarketIcon;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800233
Adam Cohen2801caf2011-05-13 20:57:39 -0700234 private DragLayer mDragLayer;
235
Michael Jurkaddd62e92011-02-16 17:49:14 -0800236 private BubbleTextView mWaitingForResume;
237
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800238 private static ArrayList<PendingAddArguments> sPendingAddList
239 = new ArrayList<PendingAddArguments>();
240
241 private static class PendingAddArguments {
242 int requestCode;
243 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700244 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800245 int screen;
246 int cellX;
247 int cellY;
248 }
249
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 @Override
251 protected void onCreate(Bundle savedInstanceState) {
252 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800253 LauncherApplication app = ((LauncherApplication)getApplication());
254 mModel = app.setLauncher(this);
255 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400256 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700258
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
261 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700262
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200264 android.os.Debug.startMethodTracing(
265 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 }
267
268 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 setContentView(R.layout.launcher);
270 setupViews();
Winson Chung82f55532011-08-09 14:14:23 -0700271 enableClingsIfNecessary();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800273 registerContentObservers();
274
Joe Onorato7c312c12009-08-13 21:36:53 -0700275 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700276
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 mSavedState = savedInstanceState;
278 restoreState(mSavedState);
279
Winson Chunga12a2502010-12-20 14:41:35 -0800280 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700281 if (mAppsCustomizeContent != null) {
282 mAppsCustomizeContent.onPackagesUpdated();
283 }
Winson Chunga12a2502010-12-20 14:41:35 -0800284
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 if (PROFILE_STARTUP) {
286 android.os.Debug.stopMethodTracing();
287 }
288
289 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 }
292
Michael Jurkac57b7a82011-08-09 22:02:20 -0700293 if (!mModel.isAllAppsLoaded()) {
294 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
295 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
296 }
297
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298 // For handling default keys
299 mDefaultKeySsb = new SpannableStringBuilder();
300 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800301
302 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
303 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800304
305 // If we have a saved version of these external icons, we load them up immediately
Winson Chungf0ea4d32011-06-06 14:27:16 -0700306 if (sGlobalSearchIcon == null || sVoiceSearchIcon == null || sAppMarketIcon == null) {
307 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +0100308 updateGlobalSearchIcon();
Winson Chungf0ea4d32011-06-06 14:27:16 -0700309 }
310 if (sGlobalSearchIcon != null) {
311 updateGlobalSearchIcon(sGlobalSearchIcon);
312 }
313 if (sVoiceSearchIcon != null) {
314 updateVoiceSearchIcon(sVoiceSearchIcon);
315 }
316 if (sAppMarketIcon != null) {
317 updateAppMarketIcon(sAppMarketIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800318 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800319 }
Romain Guycbb89e42009-06-08 15:52:54 -0700320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700322 if (sLocaleConfiguration == null) {
323 new AsyncTask<Void, Void, LocaleConfiguration>() {
324 @Override
325 protected LocaleConfiguration doInBackground(Void... unused) {
326 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
327 readConfiguration(Launcher.this, localeConfiguration);
328 return localeConfiguration;
329 }
330
331 @Override
332 protected void onPostExecute(LocaleConfiguration result) {
333 sLocaleConfiguration = result;
334 checkForLocaleChange(); // recursive, but now with a locale configuration
335 }
336 }.execute();
337 return;
338 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700339
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800340 final Configuration configuration = getResources().getConfiguration();
341
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700342 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 final String locale = configuration.locale.toString();
344
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700345 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800346 final int mcc = configuration.mcc;
347
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700348 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349 final int mnc = configuration.mnc;
350
Romain Guy84f296c2009-11-04 15:00:44 -0800351 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800352
Romain Guy84f296c2009-11-04 15:00:44 -0800353 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700354 sLocaleConfiguration.locale = locale;
355 sLocaleConfiguration.mcc = mcc;
356 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700357
Joe Onorato0589f0f2010-02-08 13:44:00 -0800358 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700359
360 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
361 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700362 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700363 public void run() {
364 writeConfiguration(Launcher.this, localeConfiguration);
365 }
366 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700367 }
368 }
369
370 private static class LocaleConfiguration {
371 public String locale;
372 public int mcc = -1;
373 public int mnc = -1;
374 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700375
Romain Guy98d01652009-06-30 16:21:04 -0700376 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
377 DataInputStream in = null;
378 try {
379 in = new DataInputStream(context.openFileInput(PREFERENCES));
380 configuration.locale = in.readUTF();
381 configuration.mcc = in.readInt();
382 configuration.mnc = in.readInt();
383 } catch (FileNotFoundException e) {
384 // Ignore
385 } catch (IOException e) {
386 // Ignore
387 } finally {
388 if (in != null) {
389 try {
390 in.close();
391 } catch (IOException e) {
392 // Ignore
393 }
394 }
395 }
396 }
397
398 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
399 DataOutputStream out = null;
400 try {
401 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
402 out.writeUTF(configuration.locale);
403 out.writeInt(configuration.mcc);
404 out.writeInt(configuration.mnc);
405 out.flush();
406 } catch (FileNotFoundException e) {
407 // Ignore
408 } catch (IOException e) {
409 //noinspection ResultOfMethodCallIgnored
410 context.getFileStreamPath(PREFERENCES).delete();
411 } finally {
412 if (out != null) {
413 try {
414 out.close();
415 } catch (IOException e) {
416 // Ignore
417 }
418 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 }
420 }
421
Adam Cohen716b51e2011-06-30 12:09:54 -0700422 public DragLayer getDragLayer() {
423 return mDragLayer;
424 }
425
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426 static int getScreen() {
427 synchronized (sLock) {
428 return sScreen;
429 }
430 }
431
432 static void setScreen(int screen) {
433 synchronized (sLock) {
434 sScreen = screen;
435 }
436 }
437
Winson Chung557d6ed2011-07-08 15:34:52 -0700438 /**
439 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
440 * a configuration step, this allows the proper animations to run after other transitions.
441 */
442 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700443 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800444 switch (args.requestCode) {
445 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700446 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
447 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800448 break;
449 case REQUEST_PICK_SHORTCUT:
450 processShortcut(args.intent);
451 break;
452 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700453 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
454 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700455 result = true;
456 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800457 case REQUEST_PICK_APPWIDGET:
458 addAppWidgetFromPick(args.intent);
459 break;
460 case REQUEST_CREATE_APPWIDGET:
461 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700462 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700463 result = true;
464 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800465 case REQUEST_PICK_WALLPAPER:
466 // We just wanted the activity result here so we can clear mWaitingForResult
467 break;
468 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700469 // In any situation where we have a multi-step drop, we should reset the add info only after
470 // we complete the drop
471 resetAddInfo();
472 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800473 }
474
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800475 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800476 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700477 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700478 mWaitingForResult = false;
479
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800480 // The pattern used here is that a user PICKs a specific application,
481 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700482
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
484 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700485 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800486 final PendingAddArguments args = new PendingAddArguments();
487 args.requestCode = requestCode;
488 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700489 args.container = mPendingAddInfo.container;
490 args.screen = mPendingAddInfo.screen;
491 args.cellX = mPendingAddInfo.cellX;
492 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800493
494 // If the loader is still running, defer the add until it is done.
495 if (isWorkspaceLocked()) {
496 sPendingAddList.add(args);
497 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700498 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800499 }
Romain Guy18042c82009-11-06 11:44:55 -0800500 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700501 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
502 if (data != null) {
503 // Clean up the appWidgetId if we canceled
504 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
505 if (appWidgetId != -1) {
506 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
507 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800508 }
509 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700510
511 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700512 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513 }
514
515 @Override
516 protected void onResume() {
517 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800518 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700519 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400520 mWorkspaceLoading = true;
521 mModel.startLoader(this, true);
522 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700523 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800524 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800525 if (mWaitingForResume != null) {
526 mWaitingForResume.setStayPressed(false);
527 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700528 // When we resume Launcher, a different Activity might be responsible for the app
529 // market intent, so refresh the icon
530 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 }
532
533 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700534 protected void onPause() {
535 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700536 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800537 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700538 }
Romain Guycbb89e42009-06-08 15:52:54 -0700539
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700540 @Override
541 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400542 // Flag the loader to stop early before switching
543 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700544 if (mAppsCustomizeContent != null) {
545 mAppsCustomizeContent.surrender();
546 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800547 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700548 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700549
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800550 // We can't hide the IME if it was forced open. So don't bother
551 /*
552 @Override
553 public void onWindowFocusChanged(boolean hasFocus) {
554 super.onWindowFocusChanged(hasFocus);
555
556 if (hasFocus) {
557 final InputMethodManager inputManager = (InputMethodManager)
558 getSystemService(Context.INPUT_METHOD_SERVICE);
559 WindowManager.LayoutParams lp = getWindow().getAttributes();
560 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
561 android.os.Handler()) {
562 protected void onReceiveResult(int resultCode, Bundle resultData) {
563 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
564 }
565 });
566 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
567 }
568 }
569 */
570
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 private boolean acceptFilter() {
572 final InputMethodManager inputManager = (InputMethodManager)
573 getSystemService(Context.INPUT_METHOD_SERVICE);
574 return !inputManager.isFullscreenMode();
575 }
576
577 @Override
578 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700579 final int uniChar = event.getUnicodeChar();
580 final boolean handled = super.onKeyDown(keyCode, event);
581 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
582 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
584 keyCode, event);
585 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700586 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700587 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700588 // showSearchDialog()
589 // If there are multiple keystrokes before the search dialog takes focus,
590 // onSearchRequested() will be called for every keystroke,
591 // but it is idempotent, so it's fine.
592 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800593 }
594 }
595
Joe Onorato8a9625e2010-01-28 15:55:35 -0800596 // Eat the long press event so the keyboard doesn't come up.
597 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
598 return true;
599 }
600
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 return handled;
602 }
603
Karl Rosaen138a0412009-04-23 19:00:21 -0700604 private String getTypedText() {
605 return mDefaultKeySsb.toString();
606 }
607
608 private void clearTypedText() {
609 mDefaultKeySsb.clear();
610 mDefaultKeySsb.clearSpans();
611 Selection.setSelection(mDefaultKeySsb, 0);
612 }
613
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800614 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700615 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
616 * State
617 */
618 private static State intToState(int stateOrdinal) {
619 State state = State.WORKSPACE;
620 final State[] stateValues = State.values();
621 for (int i = 0; i < stateValues.length; i++) {
622 if (stateValues[i].ordinal() == stateOrdinal) {
623 state = stateValues[i];
624 break;
625 }
626 }
627 return state;
628 }
629
630 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800631 * Restores the previous state, if it exists.
632 *
633 * @param savedState The previous state.
634 */
635 private void restoreState(Bundle savedState) {
636 if (savedState == null) {
637 return;
638 }
639
Michael Jurka883f55b2010-10-21 15:47:14 -0700640 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700641 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800642 showAllApps(false);
643 }
644
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800645 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
646 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700647 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 }
649
Winson Chung3d503fb2011-07-13 17:25:49 -0700650 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
651 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700652
Winson Chung3d503fb2011-07-13 17:25:49 -0700653 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
654 mPendingAddInfo.container = pendingAddContainer;
655 mPendingAddInfo.screen = pendingAddScreen;
656 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
657 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 mRestoring = true;
659 }
660
661 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
662 if (renameFolder) {
663 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700664 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 mRestoring = true;
666 }
Winson Chunga12a2502010-12-20 14:41:35 -0800667
Winson Chung785d2eb2011-04-14 16:08:02 -0700668
669 // Restore the AppsCustomize tab
670 if (mAppsCustomizeTabHost != null) {
671 String curTab = savedState.getString("apps_customize_currentTab");
672 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700673 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700674 mAppsCustomizeContent.setContentType(
675 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
676 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700677 mAppsCustomizeContent.loadAssociatedPages(
678 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700679 }
680
Winson Chung5afbf7b2011-07-25 11:53:08 -0700681 int currentIndex = savedState.getInt("apps_customize_currentIndex");
682 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700683 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 }
685
686 /**
687 * Finds all the views we need and configure them properly.
688 */
689 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700690 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400691
Winson Chung4c98d922011-05-31 16:50:48 -0700692 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
693 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694
Winson Chung4c98d922011-05-31 16:50:48 -0700695 // Setup the drag layer
696 mDragLayer.setup(this, dragController);
697
Winson Chung3d503fb2011-07-13 17:25:49 -0700698 // Setup the hotseat
699 mHotseat = (Hotseat) findViewById(R.id.hotseat);
700 if (mHotseat != null) {
701 mHotseat.setup(this);
702 }
703
Winson Chung4c98d922011-05-31 16:50:48 -0700704 // Setup the workspace
705 mWorkspace.setHapticFeedbackEnabled(false);
706 mWorkspace.setOnLongClickListener(this);
707 mWorkspace.setup(this, dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700708 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700709
Winson Chungf0ea4d32011-06-06 14:27:16 -0700710 // Get the search/delete bar
711 mSearchDeleteBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700712
Winson Chungf0ea4d32011-06-06 14:27:16 -0700713 // Setup AppsCustomize
714 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
715 findViewById(R.id.apps_customize_pane);
716 mAppsCustomizeContent = (AppsCustomizePagedView)
717 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
718 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400719
Romain Guy1fbc1c82009-11-09 20:43:08 -0800720
Winson Chung4c98d922011-05-31 16:50:48 -0700721
Winson Chung3d503fb2011-07-13 17:25:49 -0700722 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700723 dragController.setDragScoller(mWorkspace);
724 dragController.setScrollView(mDragLayer);
725 dragController.setMoveTarget(mWorkspace);
726 dragController.addDropTarget(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700727 if (mSearchDeleteBar != null) {
728 mSearchDeleteBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800729 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800730 }
731
Romain Guy8a73c512009-11-09 19:19:59 -0800732
Winson Chungaafa03c2010-06-11 17:34:16 -0700733
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 /**
735 * Creates a view representing a shortcut.
736 *
737 * @param info The data structure describing the shortcut.
738 *
739 * @return A View inflated from R.layout.application.
740 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800741 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700743 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 }
745
746 /**
747 * Creates a view representing a shortcut inflated from the specified resource.
748 *
749 * @param layoutResId The id of the XML layout used to create the shortcut.
750 * @param parent The group the shortcut belongs to.
751 * @param info The data structure describing the shortcut.
752 *
753 * @return A View inflated from layoutResId.
754 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800755 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800756 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
757 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800759 return favorite;
760 }
761
762 /**
763 * Add an application shortcut to the workspace.
764 *
765 * @param data The intent describing the application.
766 * @param cellInfo The position on screen where to create the shortcut.
767 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700768 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700769 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700770 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700771
Adam Cohenfbba09b2011-07-18 21:43:05 -0700772 // First we check if we already know the exact location where we want to add this item.
773 if (cellX >= 0 && cellY >= 0) {
774 cellXY[0] = cellX;
775 cellXY[1] = cellY;
776 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700777 showOutOfSpaceMessage();
778 return;
779 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800780
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800781 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800782
Romain Guy73b979d2009-06-09 12:57:21 -0700783 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800784 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800785 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800786 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700787 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700788 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800789 } else {
790 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 }
792 }
Romain Guycbb89e42009-06-08 15:52:54 -0700793
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 /**
795 * Add a shortcut to the workspace.
796 *
797 * @param data The intent describing the shortcut.
798 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800799 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700800 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
801 int cellY) {
802 int[] cellXY = mTmpAddItemCellCoordinates;
803 int[] touchXY = mPendingAddInfo.dropPos;
804 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700805
Michael Jurkad3ef3062010-11-23 16:23:58 -0800806 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700807
Adam Cohen558baaf2011-08-15 15:22:57 -0700808 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
809 final View view = createShortcut(info);
810
Adam Cohenfbba09b2011-07-18 21:43:05 -0700811 // First we check if we already know the exact location where we want to add this item.
812 if (cellX >= 0 && cellY >= 0) {
813 cellXY[0] = cellX;
814 cellXY[1] = cellY;
815 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700816
817 // If appropriate, either create a folder or add to an existing folder
818 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
819 true, null,null)) {
820 return;
821 }
822 DragObject dragObject = new DragObject();
823 dragObject.dragInfo = info;
824 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
825 return;
826 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700827 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800828 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700829 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800830 foundCellSpan = (result != null);
831 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700832 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800833 }
834
835 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700836 showOutOfSpaceMessage();
837 return;
838 }
839
Adam Cohen558baaf2011-08-15 15:22:57 -0700840 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841
842 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700843 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
844 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 }
846 }
847
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700849 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700851 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700852 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700854 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700855 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700856
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700857 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700858 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700859
860 // We want to account for the extra amount of padding that we are adding to the widget
861 // to ensure that it gets the full amount of space that it has requested
862 Resources r = getResources();
863 int requiredWidth = appWidgetInfo.minWidth +
864 r.getDimensionPixelSize(R.dimen.app_widget_padding_left) +
865 r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
866 int requiredHeight = appWidgetInfo.minHeight +
867 r.getDimensionPixelSize(R.dimen.app_widget_padding_top) +
868 r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
869 int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700870
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700872 // We have saved the position to which the widget was dragged-- this really only matters
873 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700874 int[] cellXY = mTmpAddItemCellCoordinates;
875 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700876 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700877 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
878 cellXY[0] = mPendingAddInfo.cellX;
879 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700880 foundCellSpan = true;
881 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700882 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700883 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700884 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800885 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700886 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700887 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700888 }
889
Michael Jurka0280c3b2010-09-17 15:00:07 -0700890 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800891 if (appWidgetId != -1) {
892 // Deleting an app widget ID is a void call but writes to disk before returning
893 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800894 new Thread("deleteAppWidgetId") {
895 public void run() {
896 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
897 }
898 }.start();
899 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700900 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800901 return;
902 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700904 // Build Launcher-specific widget info and save to database
905 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700906 launcherInfo.spanX = spanXY[0];
907 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700908
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800909 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700910 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800911
912 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800913 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700914 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700915
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700916 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700918
Winson Chung3d503fb2011-07-13 17:25:49 -0700919 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400920 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700921
922 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800923 }
924 }
Romain Guycbb89e42009-06-08 15:52:54 -0700925
Adam Cohended9f8d2010-11-03 13:25:16 -0700926 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
927 @Override
928 public void onReceive(Context context, Intent intent) {
929 final String action = intent.getAction();
930 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
931 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700932 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700933 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -0700934
Winson Chungc100e8e2011-08-09 16:02:43 -0700935 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -0700936 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -0700937 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
938 mAppsCustomizeTabHost.reset();
939 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -0700940 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700941 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
942 mUserPresent = true;
943 updateRunning();
944 }
945 }
946 };
947
948 @Override
949 public void onAttachedToWindow() {
950 super.onAttachedToWindow();
951
952 // Listen for broadcasts related to user-presence
953 final IntentFilter filter = new IntentFilter();
954 filter.addAction(Intent.ACTION_SCREEN_OFF);
955 filter.addAction(Intent.ACTION_USER_PRESENT);
956 registerReceiver(mReceiver, filter);
957
Adam Cohend113e0c2010-11-11 10:48:05 -0800958 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -0700959 mVisible = true;
960 }
961
962 @Override
963 public void onDetachedFromWindow() {
964 super.onDetachedFromWindow();
965 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -0700966 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -0700967
Adam Cohend113e0c2010-11-11 10:48:05 -0800968 if (mAttached) {
969 unregisterReceiver(mReceiver);
970 mAttached = false;
971 }
Adam Cohended9f8d2010-11-03 13:25:16 -0700972 updateRunning();
973 }
974
975 public void onWindowVisibilityChanged(int visibility) {
976 mVisible = visibility == View.VISIBLE;
977 updateRunning();
978 }
979
980 private void sendAdvanceMessage(long delay) {
981 mHandler.removeMessages(ADVANCE_MSG);
982 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
983 mHandler.sendMessageDelayed(msg, delay);
984 mAutoAdvanceSentTime = System.currentTimeMillis();
985 }
986
987 private void updateRunning() {
988 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
989 if (autoAdvanceRunning != mAutoAdvanceRunning) {
990 mAutoAdvanceRunning = autoAdvanceRunning;
991 if (autoAdvanceRunning) {
992 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
993 sendAdvanceMessage(delay);
994 } else {
995 if (!mWidgetsToAdvance.isEmpty()) {
996 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
997 (System.currentTimeMillis() - mAutoAdvanceSentTime));
998 }
999 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001000 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001001 }
1002 }
1003 }
1004
1005 private final Handler mHandler = new Handler() {
1006 @Override
1007 public void handleMessage(Message msg) {
1008 if (msg.what == ADVANCE_MSG) {
1009 int i = 0;
1010 for (View key: mWidgetsToAdvance.keySet()) {
1011 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1012 final int delay = mAdvanceStagger * i;
1013 if (v instanceof Advanceable) {
1014 postDelayed(new Runnable() {
1015 public void run() {
1016 ((Advanceable) v).advance();
1017 }
1018 }, delay);
1019 }
1020 i++;
1021 }
1022 sendAdvanceMessage(mAdvanceInterval);
1023 }
1024 }
1025 };
1026
1027 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001028 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001029 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1030 if (v instanceof Advanceable) {
1031 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001032 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001033 updateRunning();
1034 }
1035 }
1036
1037 void removeWidgetToAutoAdvance(View hostView) {
1038 if (mWidgetsToAdvance.containsKey(hostView)) {
1039 mWidgetsToAdvance.remove(hostView);
1040 updateRunning();
1041 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001042 }
1043
Joe Onorato9c1289c2009-08-17 11:03:03 -04001044 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001045 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001046 launcherInfo.hostView = null;
1047 }
1048
Adam Cohended9f8d2010-11-03 13:25:16 -07001049 void showOutOfSpaceMessage() {
1050 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1051 }
1052
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001053 public LauncherAppWidgetHost getAppWidgetHost() {
1054 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 }
Romain Guycbb89e42009-06-08 15:52:54 -07001056
Winson Chunga9abd0e2010-10-27 17:18:37 -07001057 public LauncherModel getModel() {
1058 return mModel;
1059 }
1060
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001061 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001062 getWindow().closeAllPanels();
1063
1064 try {
1065 dismissDialog(DIALOG_CREATE_SHORTCUT);
1066 // Unlock the workspace if the dialog was showing
1067 } catch (Exception e) {
1068 // An exception is thrown if the dialog is not visible, which is fine
1069 }
1070
1071 try {
1072 dismissDialog(DIALOG_RENAME_FOLDER);
1073 // Unlock the workspace if the dialog was showing
1074 } catch (Exception e) {
1075 // An exception is thrown if the dialog is not visible, which is fine
1076 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001077
1078 // Whatever we were doing is hereby canceled.
1079 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001080 }
1081
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 @Override
1083 protected void onNewIntent(Intent intent) {
1084 super.onNewIntent(intent);
1085
1086 // Close the menu
1087 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001088 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001089 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001090
Adam Cohen95bb8002011-07-03 23:40:28 -07001091 closeFolder();
1092
Joe Onorato14f122b2009-11-19 14:06:36 -08001093 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1094 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001095
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001096 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001097 mWorkspace.exitWidgetResizeMode();
Patrick Dubroya0aa0122011-02-24 11:42:23 -08001098 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive()) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001099 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001100 }
Winson Chungde1af762011-07-21 16:44:07 -07001101 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001102 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001103
Joe Onorato3a8820b2009-11-10 15:06:42 -08001104 final View v = getWindow().peekDecorView();
1105 if (v != null && v.getWindowToken() != null) {
1106 InputMethodManager imm = (InputMethodManager)getSystemService(
1107 INPUT_METHOD_SERVICE);
1108 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001109 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001110
Michael Jurka35aa14d2011-07-07 17:01:08 -07001111 // Reset AllApps to its initial state
Winson Chungc100e8e2011-08-09 16:02:43 -07001112 if (mAppsCustomizeTabHost != null) {
1113 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 }
1116 }
1117
1118 @Override
1119 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1120 // Do not call super here
1121 mSavedInstanceState = savedInstanceState;
1122 }
1123
1124 @Override
1125 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001126 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001127 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128
Michael Jurka883f55b2010-10-21 15:47:14 -07001129 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001130 // We close any open folder since it will not be re-opened, and we need to make sure
1131 // this state is reflected.
1132 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133
Winson Chung3d503fb2011-07-13 17:25:49 -07001134 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1135 mWaitingForResult) {
1136 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1137 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1138 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1139 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 }
1141
1142 if (mFolderInfo != null && mWaitingForResult) {
1143 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1144 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1145 }
Michael Jurka946ad472010-07-09 18:05:18 -07001146
Winson Chung785d2eb2011-04-14 16:08:02 -07001147 // Save the current AppsCustomize tab
1148 if (mAppsCustomizeTabHost != null) {
1149 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1150 if (currentTabTag != null) {
1151 outState.putString("apps_customize_currentTab", currentTabTag);
1152 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001153 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1154 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001155 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001156 }
1157
1158 @Override
1159 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001160 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001161
Winson Chunge7a03942011-08-05 15:05:12 -07001162 // Remove all pending runnables
1163 mHandler.removeMessages(ADVANCE_MSG);
1164 mHandler.removeMessages(0);
1165
Winson Chungcd2b0142011-06-08 16:02:26 -07001166 // Stop callbacks from LauncherModel
1167 LauncherApplication app = ((LauncherApplication) getApplication());
1168 mModel.stopLoader();
1169 app.setLauncher(null);
1170
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001171 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001172 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001174 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001176 mAppWidgetHost = null;
1177
1178 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001179
1180 TextKeyListener.getInstance().release();
1181
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001182
Winson Chung3d503fb2011-07-13 17:25:49 -07001183 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001184
1185 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001186 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001187
1188 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1189 mWorkspace.removeAllViews();
1190 mWorkspace = null;
1191 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001192
1193 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 }
1195
Adam Cohena9cf38f2011-05-02 15:36:58 -07001196 public DragController getDragController() {
1197 return mDragController;
1198 }
1199
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 @Override
1201 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001202 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001203 super.startActivityForResult(intent, requestCode);
1204 }
1205
Winson Chung70d72102011-08-12 11:24:35 -07001206 /**
1207 * Indicates that we want global search for this activity by setting the globalSearch
1208 * argument for {@link #startSearch} to true.
1209 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001211 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001213
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001214 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001215
Karl Rosaen138a0412009-04-23 19:00:21 -07001216 if (initialQuery == null) {
1217 // Use any text typed in the launcher as the initial query
1218 initialQuery = getTypedText();
1219 clearTypedText();
1220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221 if (appSearchData == null) {
1222 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001223 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 }
Romain Guycbb89e42009-06-08 15:52:54 -07001225
Karl Rosaen138a0412009-04-23 19:00:21 -07001226 final SearchManager searchManager =
1227 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001228 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001229 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 }
1231
Winson Chung70d72102011-08-12 11:24:35 -07001232 @Override
1233 public boolean onCreateOptionsMenu(Menu menu) {
1234 if (isWorkspaceLocked()) {
1235 return false;
1236 }
1237
1238 super.onCreateOptionsMenu(menu);
Winson Chung236d4312011-08-22 15:12:27 -07001239 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1240 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1241 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Winson Chung70d72102011-08-12 11:24:35 -07001242 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1243 .setIcon(android.R.drawable.ic_menu_gallery)
1244 .setAlphabeticShortcut('W');
1245 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1246 .setIcon(android.R.drawable.ic_menu_manage)
1247 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001248 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1249 .setIcon(android.R.drawable.ic_menu_preferences)
1250 .setIntent(settings)
1251 .setAlphabeticShortcut('P');
Winson Chung70d72102011-08-12 11:24:35 -07001252 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1253 .setIcon(android.R.drawable.ic_menu_help)
1254 .setAlphabeticShortcut('H');
1255 return true;
1256 }
1257
1258 @Override
1259 public boolean onPrepareOptionsMenu(Menu menu) {
1260 super.onPrepareOptionsMenu(menu);
1261
1262 if (mAppsCustomizeTabHost.isTransitioning()) {
1263 return false;
1264 }
1265 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1266 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1267
1268 return true;
1269 }
1270
1271 @Override
1272 public boolean onOptionsItemSelected(MenuItem item) {
1273 switch (item.getItemId()) {
1274 case MENU_WALLPAPER_SETTINGS:
1275 startWallpaper();
1276 return true;
1277 case MENU_MANAGE_APPS:
1278 manageApps();
1279 return true;
1280 case MENU_HELP:
1281 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help_url))));
1282 return true;
1283 }
1284
1285 return super.onOptionsItemSelected(item);
1286 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001288 @Override
1289 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001290 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001291 // Use a custom animation for launching search
1292 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001293 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001294 }
1295
Joe Onorato9c1289c2009-08-17 11:03:03 -04001296 public boolean isWorkspaceLocked() {
1297 return mWorkspaceLoading || mWaitingForResult;
1298 }
1299
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 private void addItems() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001301 showWorkspace(true);
Adam Cohenfbba09b2011-07-18 21:43:05 -07001302 showAddDialog();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 }
1304
Michael Jurka0280c3b2010-09-17 15:00:07 -07001305 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001306 mPendingAddInfo.container = ItemInfo.NO_ID;
1307 mPendingAddInfo.screen = -1;
1308 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1309 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1310 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001311 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001312
Winson Chung7ad01412010-09-27 11:33:03 -07001313 private void manageApps() {
1314 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1315 }
1316
Michael Jurkaaf442092010-06-10 17:01:57 -07001317 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001318 // TODO: catch bad widget exception when sent
1319 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001320 // TODO: Is this log message meaningful?
1321 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001322 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001323 }
1324
Winson Chung55cef262010-10-28 14:14:18 -07001325 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001326 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327
Bjorn Bringert7984c942009-12-09 15:38:25 +00001328 if (appWidget.configure != null) {
1329 // Launch over to configure widget, if needed
1330 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1331 intent.setComponent(appWidget.configure);
1332 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001333 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001334 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1335 intent.putExtra(
1336 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1337 info.mimeType);
1338
1339 final String mimeType = info.mimeType;
1340 final ClipData clipData = (ClipData) info.configurationData;
1341 final ClipDescription clipDesc = clipData.getDescription();
1342 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1343 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001344 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001345 final CharSequence stringData = item.getText();
1346 final Uri uriData = item.getUri();
1347 final Intent intentData = item.getIntent();
1348 final String key =
1349 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1350 if (uriData != null) {
1351 intent.putExtra(key, uriData);
1352 } else if (intentData != null) {
1353 intent.putExtra(key, intentData);
1354 } else if (stringData != null) {
1355 intent.putExtra(key, stringData);
1356 }
1357 break;
1358 }
1359 }
1360 }
Winson Chung55cef262010-10-28 14:14:18 -07001361 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001362
Romain Guy8e633c52010-03-04 12:51:36 -08001363 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001364 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001365 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001366 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001367
1368 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001369 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 }
1371 }
Romain Guycbb89e42009-06-08 15:52:54 -07001372
Adam Cohenfbba09b2011-07-18 21:43:05 -07001373 /**
1374 * Process a shortcut drop.
1375 *
1376 * @param componentName The name of the component
1377 * @param screen The screen where it should be added
1378 * @param cell The cell it should be added to, optional
1379 * @param position The location on the screen where it was dropped, optional
1380 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001381 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1382 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001383 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001384 mPendingAddInfo.container = container;
1385 mPendingAddInfo.screen = screen;
1386 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001387
1388 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001389 mPendingAddInfo.cellX = cell[0];
1390 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001391 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001392
1393 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1394 createShortcutIntent.setComponent(componentName);
1395 processShortcut(createShortcutIntent);
1396 }
1397
Adam Cohenfbba09b2011-07-18 21:43:05 -07001398 /**
1399 * Process a widget drop.
1400 *
1401 * @param info The PendingAppWidgetInfo of the widget being added.
1402 * @param screen The screen where it should be added
1403 * @param cell The cell it should be added to, optional
1404 * @param position The location on the screen where it was dropped, optional
1405 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001406 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1407 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001408 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001409 mPendingAddInfo.container = info.container = container;
1410 mPendingAddInfo.screen = info.screen = screen;
1411 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001412 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001413 mPendingAddInfo.cellX = cell[0];
1414 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001415 }
1416
1417 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1418 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1419 addAppWidgetImpl(appWidgetId, info);
1420 }
1421
Joe Onoratodeb98af2010-02-19 14:59:39 -08001422 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001423 // Handle case where user selected "Applications"
1424 String applicationName = getResources().getString(R.string.group_applications);
1425 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001426
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001427 if (applicationName != null && applicationName.equals(shortcutName)) {
1428 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1429 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001430
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001431 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1432 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001433 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001434 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001435 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001436 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001437 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 }
1439
Winson Chung24ab2f12010-09-16 14:10:47 -07001440 void processWallpaper(Intent intent) {
1441 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1442 }
1443
Winson Chung3d503fb2011-07-13 17:25:49 -07001444 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1445 int cellY) {
Adam Cohend0445262011-07-04 23:53:22 -07001446 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 folderInfo.title = getText(R.string.folder_name);
1448
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001449 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001450 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1451 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001452 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
1454 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001455 FolderIcon newFolder =
1456 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1457 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1458 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001459 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 }
Romain Guycbb89e42009-06-08 15:52:54 -07001461
Joe Onorato9c1289c2009-08-17 11:03:03 -04001462 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001463 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001464 }
1465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 private void showNotifications() {
1467 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1468 if (statusBar != null) {
1469 statusBar.expand();
1470 }
1471 }
1472
1473 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001474 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001475 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001476 Intent chooser = Intent.createChooser(pickWallpaper,
1477 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001478 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1479 // Removed in Eclair MR1
1480// WallpaperManager wm = (WallpaperManager)
1481// getSystemService(Context.WALLPAPER_SERVICE);
1482// WallpaperInfo wi = wm.getWallpaperInfo();
1483// if (wi != null && wi.getSettingsActivity() != null) {
1484// LabeledIntent li = new LabeledIntent(getPackageName(),
1485// R.string.configure_wallpaper, 0);
1486// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1487// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1488// }
Mike Clerona0618e42009-10-22 13:55:21 -07001489 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490 }
1491
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001492 /**
1493 * Registers various content observers. The current implementation registers
1494 * only a favorites observer to keep track of the favorites applications.
1495 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001496 private void registerContentObservers() {
1497 ContentResolver resolver = getContentResolver();
1498 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1499 true, mWidgetObserver);
1500 }
1501
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 @Override
1503 public boolean dispatchKeyEvent(KeyEvent event) {
1504 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1505 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001507 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001508 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001509 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001510 dumpState();
1511 return true;
1512 }
1513 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001514 }
1515 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1516 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001517 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518 return true;
1519 }
1520 }
1521
1522 return super.dispatchKeyEvent(event);
1523 }
1524
Joe Onorato88ec0992009-11-19 13:16:06 -08001525 @Override
1526 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001527 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001528 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001529 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001530 Folder openFolder = mWorkspace.getOpenFolder();
1531 if (openFolder.isEditingName()) {
1532 openFolder.dismissEditingName();
1533 } else {
1534 closeFolder();
1535 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001536 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001537 mWorkspace.exitWidgetResizeMode();
1538
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001539 // Back button is a no-op here, but give at least some feedback for the button press
1540 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001541 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001542 }
1543
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001545 * Re-listen when widgets are reset.
1546 */
1547 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001548 if (mAppWidgetHost != null) {
1549 mAppWidgetHost.startListening();
1550 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001551 }
1552
1553 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001554 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1555 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001557 private void unbindWorkspaceAndHotseatItems() {
Adam Cohen4eac29a2011-07-11 17:53:37 -07001558 LauncherModel.unbindWorkspaceItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001560
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 /**
1562 * Launches the intent referred by the clicked shortcut.
1563 *
1564 * @param v The view representing the clicked shortcut.
1565 */
1566 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001567 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1568 // view has detached (it's possible for this to happen if the view is removed mid touch).
1569 if (v.getWindowToken() == null) {
1570 return;
1571 }
1572
1573 if (mWorkspace.isSwitchingState()) {
1574 return;
1575 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001576
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001578 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001580 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001581 int[] pos = new int[2];
1582 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001583 intent.setSourceBounds(new Rect(pos[0], pos[1],
1584 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001585 boolean success = startActivitySafely(intent, tag);
1586
1587 if (success && v instanceof BubbleTextView) {
1588 mWaitingForResume = (BubbleTextView) v;
1589 mWaitingForResume.setStayPressed(true);
1590 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001592 if (v instanceof FolderIcon) {
1593 FolderIcon fi = (FolderIcon) v;
1594 handleFolderClick(fi);
1595 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001596 } else if (v == mAllAppsButton) {
1597 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001598 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001599 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001600 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001601 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 }
1603 }
1604
Michael Jurka0e260592010-06-30 17:07:39 -07001605 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001606 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001607 // clicking anywhere on the workspace causes the customization drawer to slide down
1608 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001609 return false;
1610 }
1611
Michael Jurkaaf442092010-06-10 17:01:57 -07001612 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001613 * Event handler for the search button
1614 *
1615 * @param v The view that was clicked.
1616 */
1617 public void onClickSearchButton(View v) {
Amith Yamasania135ba82011-08-09 17:42:01 -07001618 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001619 }
1620
1621 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001622 * Event handler for the voice button
1623 *
1624 * @param v The view that was clicked.
1625 */
1626 public void onClickVoiceButton(View v) {
1627 startVoiceSearch();
1628 }
1629
1630 private void startVoiceSearch() {
1631 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1632 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1633 startActivity(intent);
1634 }
1635
1636 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001637 * Event handler for the "grid" button that appears on the home screen, which
1638 * enters all apps mode.
1639 *
1640 * @param v The view that was clicked.
1641 */
1642 public void onClickAllAppsButton(View v) {
1643 showAllApps(true);
1644 }
1645
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001646 public void onClickAppMarketButton(View v) {
1647 if (mAppMarketIntent != null) {
1648 startActivitySafely(mAppMarketIntent, "app market");
1649 }
1650 }
1651
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001652 void startApplicationDetailsActivity(ComponentName componentName) {
1653 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001654 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1655 Uri.fromParts("package", packageName, null));
1656 startActivity(intent);
1657 }
1658
Patrick Dubroy5539af72010-09-07 15:22:01 -07001659 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1660 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1661 // System applications cannot be installed. For now, show a toast explaining that.
1662 // We may give them the option of disabling apps this way.
1663 int messageId = R.string.uninstall_system_app_text;
1664 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1665 } else {
1666 String packageName = appInfo.componentName.getPackageName();
1667 String className = appInfo.componentName.getClassName();
1668 Intent intent = new Intent(
1669 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1670 startActivity(intent);
1671 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001672 }
1673
Michael Jurkaddd62e92011-02-16 17:49:14 -08001674 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001675 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1676 try {
1677 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001678 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001679 } catch (ActivityNotFoundException e) {
1680 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001681 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682 } catch (SecurityException e) {
1683 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001684 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001686 "or use the exported attribute for this activity. "
1687 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001688 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001689 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001690 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001691
Romain Guy8e633c52010-03-04 12:51:36 -08001692 void startActivityForResultSafely(Intent intent, int requestCode) {
1693 try {
1694 startActivityForResult(intent, requestCode);
1695 } catch (ActivityNotFoundException e) {
1696 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1697 } catch (SecurityException e) {
1698 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1699 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1700 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1701 "or use the exported attribute for this activity.", e);
1702 }
1703 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704
Adam Cohena9cf38f2011-05-02 15:36:58 -07001705 private void handleFolderClick(FolderIcon folderIcon) {
1706 final FolderInfo info = folderIcon.mInfo;
1707 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 // Close any open folder
1709 closeFolder();
1710 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001711 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 } else {
1713 // Find the open folder...
Adam Cohena9cf38f2011-05-02 15:36:58 -07001714 Folder openFolder = mWorkspace.getFolderForTag(info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 int folderScreen;
1716 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001717 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 // .. and close it
1719 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001720 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 // Close any folder open on the current screen
1722 closeFolder();
1723 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001724 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 }
1726 }
1727 }
1728 }
1729
Adam Cohen2801caf2011-05-13 20:57:39 -07001730 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001731 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001732 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1733 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1734 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1735
Adam Cohenc51934b2011-07-26 21:07:43 -07001736 FolderInfo info = (FolderInfo) fi.getTag();
1737 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1738 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001739 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1740 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001741 }
1742
Adam Cohen2801caf2011-05-13 20:57:39 -07001743 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1744 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1745 oa.start();
1746 }
1747
1748 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001749 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001750 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1751 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1752 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1753
Adam Cohenc51934b2011-07-26 21:07:43 -07001754 FolderInfo info = (FolderInfo) fi.getTag();
1755 CellLayout cl = null;
1756 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1757 cl = (CellLayout) fi.getParent().getParent();
1758 }
1759
1760 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001761 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1762 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001763 oa.addListener(new AnimatorListenerAdapter() {
1764 @Override
1765 public void onAnimationEnd(Animator animation) {
1766 if (layout != null) {
1767 layout.clearFolderLeaveBehind();
1768 }
1769 }
1770 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001771 oa.start();
1772 }
1773
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001775 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001776 * is animated relative to the specified View. If the View is null, no animation
1777 * is played.
1778 *
1779 * @param folderInfo The FolderInfo describing the folder to open.
1780 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001781 public void openFolder(FolderIcon folderIcon) {
1782 Folder folder = folderIcon.mFolder;
1783 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784
Adam Cohen2801caf2011-05-13 20:57:39 -07001785 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001786 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787
Adam Cohen4554ee12011-08-03 16:13:21 -07001788 // Just verify that the folder hasn't already been added to the DragLayer.
1789 // There was a one-off crash where the folder had a parent already.
1790 if (folder.getParent() == null) {
1791 mDragLayer.addView(folder);
1792 mDragController.addDropTarget((DropTarget) folder);
1793 } else {
1794 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1795 folder.getParent() + ").");
1796 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001797 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001798 }
1799
1800 public void closeFolder() {
1801 Folder folder = mWorkspace.getOpenFolder();
1802 if (folder != null) {
1803 closeFolder(folder);
1804 }
1805 }
1806
1807 void closeFolder(Folder folder) {
1808 folder.getInfo().opened = false;
1809
1810 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1811 if (parent != null) {
1812 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1813 shrinkAndFadeInFolderIcon(fi);
1814 }
1815 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
1817
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001819 if (mState != State.WORKSPACE) {
1820 return false;
1821 }
1822
Joe Onorato9c1289c2009-08-17 11:03:03 -04001823 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 return false;
1825 }
1826
1827 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001828 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 }
1830
Michael Jurka0280c3b2010-09-17 15:00:07 -07001831 resetAddInfo();
1832 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001834 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 return true;
1836 }
1837
Winson Chung3d503fb2011-07-13 17:25:49 -07001838 // The hotseat touch handling does not go through Workspace, and we always allow long press
1839 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001840 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001841 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1842 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001843 if (itemUnderLongClick == null) {
1844 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001845 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1846 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001847 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001848 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001849 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001851 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 }
1853 }
1854 }
1855 return true;
1856 }
1857
Winson Chung3d503fb2011-07-13 17:25:49 -07001858 boolean isHotseatLayout(View layout) {
1859 return mHotseat != null && layout != null &&
1860 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1861 }
1862 Hotseat getHotseat() {
1863 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001864 }
1865
Winson Chung3d503fb2011-07-13 17:25:49 -07001866 /**
1867 * Returns the CellLayout of the specified container at the specified screen.
1868 */
1869 CellLayout getCellLayout(long container, int screen) {
1870 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1871 if (mHotseat != null) {
1872 return mHotseat.getLayout();
1873 } else {
1874 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001875 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001876 } else {
1877 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001878 }
1879 }
1880
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 Workspace getWorkspace() {
1882 return mWorkspace;
1883 }
1884
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001885 @Override
1886 protected Dialog onCreateDialog(int id) {
1887 switch (id) {
1888 case DIALOG_CREATE_SHORTCUT:
1889 return new CreateShortcut().createDialog();
1890 case DIALOG_RENAME_FOLDER:
1891 return new RenameFolder().createDialog();
1892 }
1893
1894 return super.onCreateDialog(id);
1895 }
1896
1897 @Override
1898 protected void onPrepareDialog(int id, Dialog dialog) {
1899 switch (id) {
1900 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001901 break;
1902 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07001903 if (mFolderInfo != null) {
1904 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
1905 final CharSequence text = mFolderInfo.title;
1906 input.setText(text);
1907 input.setSelection(0, text.length());
1908 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 break;
1910 }
1911 }
1912
1913 void showRenameDialog(FolderInfo info) {
1914 mFolderInfo = info;
1915 mWaitingForResult = true;
1916 showDialog(DIALOG_RENAME_FOLDER);
1917 }
1918
Adam Cohenfbba09b2011-07-18 21:43:05 -07001919 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001920 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001921 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
1922 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 mWaitingForResult = true;
1924 showDialog(DIALOG_CREATE_SHORTCUT);
1925 }
1926
1927 private class RenameFolder {
1928 private EditText mInput;
1929
1930 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
1932 mInput = (EditText) layout.findViewById(R.id.folder_name);
1933
1934 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
1935 builder.setIcon(0);
1936 builder.setTitle(getString(R.string.rename_folder_title));
1937 builder.setCancelable(true);
1938 builder.setOnCancelListener(new Dialog.OnCancelListener() {
1939 public void onCancel(DialogInterface dialog) {
1940 cleanup();
1941 }
1942 });
1943 builder.setNegativeButton(getString(R.string.cancel_action),
1944 new Dialog.OnClickListener() {
1945 public void onClick(DialogInterface dialog, int which) {
1946 cleanup();
1947 }
1948 }
1949 );
1950 builder.setPositiveButton(getString(R.string.rename_action),
1951 new Dialog.OnClickListener() {
1952 public void onClick(DialogInterface dialog, int which) {
1953 changeFolderName();
1954 }
1955 }
1956 );
1957 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07001958
1959 final AlertDialog dialog = builder.create();
1960 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
1961 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07001962 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05001963 mInput.requestFocus();
1964 InputMethodManager inputManager = (InputMethodManager)
1965 getSystemService(Context.INPUT_METHOD_SERVICE);
1966 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07001967 }
1968 });
1969
1970 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 }
1972
1973 private void changeFolderName() {
1974 final String name = mInput.getText().toString();
1975 if (!TextUtils.isEmpty(name)) {
1976 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001977 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001978 mFolderInfo.title = name;
1979 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
1980
Joe Onorato9c1289c2009-08-17 11:03:03 -04001981 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07001982 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001983 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001984 } else {
1985 final FolderIcon folderIcon = (FolderIcon)
1986 mWorkspace.getViewForTag(mFolderInfo);
1987 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001988 // TODO: At some point we'll probably want some version of setting
1989 // the text for a folder icon.
1990 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 getWorkspace().requestLayout();
1992 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07001993 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04001994 mWorkspaceLoading = true;
1995 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001996 }
1997 }
1998 }
1999 cleanup();
2000 }
2001
2002 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 dismissDialog(DIALOG_RENAME_FOLDER);
2004 mWaitingForResult = false;
2005 mFolderInfo = null;
2006 }
2007 }
2008
Daniel Sandler843e8602010-06-07 14:59:01 -04002009 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2010 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002011 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002012 }
2013
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002014 // AllAppsView.Watcher
2015 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002016 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002017 mWorkspace.setVisibility(View.GONE);
2018 }
2019 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002020
2021 /**
2022 * Helper method for the cameraZoomIn/cameraZoomOut animations
2023 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002024 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002025 * @param scaleFactor The scale factor used for the zoom
2026 */
2027 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2028 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002029
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002030 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002031 // Set pivotY so that at the starting zoom factor, the view is partially
2032 // visible. Modifying initialHeightFactor changes how much of the view is
2033 // initially showing, and hence the perceived angle from which the view enters.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002034 if (state == State.APPS_CUSTOMIZE) {
Michael Jurkaea573482011-02-03 19:48:18 -08002035 final float initialHeightFactor = 0.175f;
Adam Cohenf16e5712011-01-13 13:31:45 -08002036 view.setPivotY((1 - initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002037 } else {
Adam Cohenf16e5712011-01-13 13:31:45 -08002038 final float initialHeightFactor = 0.2f;
Adam Cohen61033d32010-11-15 18:29:44 -08002039 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002040 }
2041 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002042
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002043 /**
2044 * Zoom the camera out from the workspace to reveal 'toView'.
2045 * Assumes that the view to show is anchored at either the very top or very bottom
2046 * of the screen.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002047 * @param toState The state to zoom out to. Must be APPS_CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002048 */
Winson Chungc07918d2011-07-01 15:35:26 -07002049 private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002050 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002051
Winson Chungf0ea4d32011-06-06 14:27:16 -07002052 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2053 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2054 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2055 final View toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002056
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002057 setPivotsForZoom(toView, toState, scale);
2058
Michael Jurkad74c9842011-07-10 12:44:21 -07002059 // Shrink workspaces away if going to AppsCustomize from workspace
2060 mWorkspace.shrink(Workspace.State.SMALL, animated);
Winson Chung4afe9b32011-07-27 17:46:20 -07002061 hideHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002062
2063 if (animated) {
Michael Jurkaabded662011-03-04 12:06:57 -08002064 final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
Michael Jurka742574b2011-02-02 23:51:01 -08002065 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002066 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2067 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002068 ((View) toView.getParent()).fastInvalidate();
Michael Jurka11148e52011-02-03 18:20:25 -08002069 toView.setFastScaleX(a * scale + b * 1f);
2070 toView.setFastScaleY(a * scale + b * 1f);
Michael Jurka742574b2011-02-02 23:51:01 -08002071 }
2072 });
Adam Cohen61033d32010-11-15 18:29:44 -08002073
Winson Chungf0ea4d32011-06-06 14:27:16 -07002074 toView.setVisibility(View.VISIBLE);
2075 toView.setFastAlpha(0f);
2076 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2077 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2078 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2079 public void onAnimationUpdate(float a, float b) {
2080 // don't need to invalidate because we do so above
2081 toView.setFastAlpha(a * 0f + b * 1f);
2082 }
2083 });
2084 alphaAnim.start();
Adam Cohenf16e5712011-01-13 13:31:45 -08002085
Michael Jurkaabded662011-03-04 12:06:57 -08002086 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002087 ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false);
Michael Jurkabfadaad2011-01-31 21:35:39 -08002088 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002089 scaleAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002090 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002091 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002092 // Prepare the position
2093 toView.setTranslationX(0.0f);
2094 toView.setTranslationY(0.0f);
2095 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002096 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002097 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002098 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002099 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002100 // If we don't set the final scale values here, if this animation is cancelled
2101 // it will have the wrong scale value and subsequent cameraPan animations will
2102 // not fix that
2103 toView.setScaleX(1.0f);
2104 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002105 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002106 ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002107 }
Winson Chung32174c82011-07-19 15:47:55 -07002108
2109 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2110 // Hide the workspace scrollbar
2111 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002112 mWorkspace.hideDockDivider(true);
Winson Chung32174c82011-07-19 15:47:55 -07002113 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002114 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002115 });
2116
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002117 // toView should appear right at the end of the workspace shrink animation
Adam Cohenf16e5712011-01-13 13:31:45 -08002118 final int startDelay = 0;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002119
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002120 if (mStateAnimation != null) mStateAnimation.cancel();
2121 mStateAnimation = new AnimatorSet();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002122 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002123 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002124 } else {
2125 toView.setTranslationX(0.0f);
2126 toView.setTranslationY(0.0f);
2127 toView.setScaleX(1.0f);
2128 toView.setScaleY(1.0f);
2129 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002130 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002131 if (toView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002132 ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false);
2133 ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002134
Winson Chungc07918d2011-07-01 15:35:26 -07002135 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2136 // Hide the workspace scrollbar
2137 mWorkspace.hideScrollingIndicator(true);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002138 mWorkspace.hideDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002139 }
Michael Jurkaabded662011-03-04 12:06:57 -08002140 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002141 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002142 }
2143
2144 /**
2145 * Zoom the camera back into the workspace, hiding 'fromView'.
2146 * This is the opposite of cameraZoomOut.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002147 * @param fromState The current state (must be APPS_CUSTOMIZE).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002148 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002149 */
Winson Chungc07918d2011-07-01 15:35:26 -07002150 private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002151 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002152
Winson Chungf0ea4d32011-06-06 14:27:16 -07002153 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2154 final float scaleFactor = (float)
2155 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2156 final View fromView = mAppsCustomizeTabHost;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002157
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002158 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002159
Michael Jurkad3ef3062010-11-23 16:23:58 -08002160 if (!springLoaded) {
2161 mWorkspace.unshrink(animated);
2162 }
Winson Chung4afe9b32011-07-27 17:46:20 -07002163 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002164 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002165 if (mStateAnimation != null) mStateAnimation.cancel();
2166 mStateAnimation = new AnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08002167
Michael Jurka742574b2011-02-02 23:51:01 -08002168 final float oldScaleX = fromView.getScaleX();
2169 final float oldScaleY = fromView.getScaleY();
2170
2171 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2172 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002173 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2174 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002175 ((View)fromView.getParent()).fastInvalidate();
2176 fromView.setFastScaleX(a * oldScaleX + b * scaleFactor);
2177 fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
2178 }
2179 });
Michael Jurkaabded662011-03-04 12:06:57 -08002180 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002181 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Michael Jurkaea573482011-02-03 19:48:18 -08002182 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Michael Jurkac2e26a02011-03-24 15:20:26 -07002183 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2184 public void onAnimationUpdate(float a, float b) {
Michael Jurka742574b2011-02-02 23:51:01 -08002185 // don't need to invalidate because we do so above
2186 fromView.setFastAlpha(a * 1f + b * 0f);
2187 }
2188 });
Michael Jurkaabded662011-03-04 12:06:57 -08002189 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002190 ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002191 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002192 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002193 @Override
Winson Chungbb6f6a52011-07-25 17:55:44 -07002194 public void onAnimationStart(android.animation.Animator animation) {
2195 if (!springLoaded) {
2196 mWorkspace.showDockDivider(false);
2197 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002198 mWorkspace.showScrollingIndicator(false);
Winson Chungbb6f6a52011-07-25 17:55:44 -07002199 }
2200 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002201 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002202 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002203 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002204 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true);
Michael Jurka2763be32011-02-24 11:19:57 -08002205 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002206 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002207 }
2208 });
2209
Winson Chungf0ea4d32011-06-06 14:27:16 -07002210 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002211 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002212 } else {
2213 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002214 if (fromView instanceof LauncherTransitionable) {
Winson Chung5a808352011-06-27 19:08:49 -07002215 ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true);
2216 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true);
Winson Chung3ac74c52011-06-30 17:39:37 -07002217
Winson Chungc07918d2011-07-01 15:35:26 -07002218 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chungf5f8cef2011-07-22 11:16:13 -07002219 // Flash the workspace scrollbar
Winson Chungbb6f6a52011-07-25 17:55:44 -07002220 mWorkspace.showDockDivider(true);
Winson Chungc07918d2011-07-01 15:35:26 -07002221 mWorkspace.flashScrollingIndicator();
2222 }
Michael Jurkaabded662011-03-04 12:06:57 -08002223 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002224 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002225 }
2226
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002227 void showWorkspace(boolean animated) {
2228 showWorkspace(animated, null);
2229 }
2230
2231 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002232 if (layout != null) {
2233 // always animated, but that's ok since we never specify a layout and
2234 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002235 mWorkspace.unshrink(layout);
2236 } else {
2237 mWorkspace.unshrink(animated);
2238 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002239 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002240 closeAllApps(animated);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002241 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002242
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002243 // Change the state *after* we've called all the transition code
2244 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002245
Winson Chung5fb63472011-02-02 17:03:37 -08002246 // Resume the auto-advance of widgets
2247 mUserPresent = true;
2248 updateRunning();
2249
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002250 // send an accessibility event to announce the context change
2251 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002252 }
2253
Michael Jurkad3ef3062010-11-23 16:23:58 -08002254 void enterSpringLoadedDragMode(CellLayout layout) {
Winson Chungb26f3d62011-06-02 10:49:29 -07002255 if (mState == State.APPS_CUSTOMIZE) {
Winson Chungc07918d2011-07-01 15:35:26 -07002256 mWorkspace.enterSpringLoadedDragMode(layout);
Winson Chungb26f3d62011-06-02 10:49:29 -07002257 cameraZoomIn(State.APPS_CUSTOMIZE, true, true);
Winson Chungc07918d2011-07-01 15:35:26 -07002258 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002259 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002260 // Otherwise, we are not in spring loaded mode, so don't do anything.
Michael Jurkad3ef3062010-11-23 16:23:58 -08002261 }
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002262 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chunge7a03942011-08-05 15:05:12 -07002263 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002264 @Override
2265 public void run() {
2266 exitSpringLoadedDragMode();
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002267
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002268 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002269 // Before we show workspace, hide all apps again because
2270 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2271 // clean up our state transition functions
2272 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002273 showWorkspace(true);
2274 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002275 }
2276 }, (extendedDelay ?
2277 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2278 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2279 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002280 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002281 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkad74c9842011-07-10 12:44:21 -07002282 mWorkspace.exitSpringLoadedDragMode(Workspace.State.SMALL);
Winson Chungb26f3d62011-06-02 10:49:29 -07002283 cameraZoomOut(State.APPS_CUSTOMIZE, true, true);
2284 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002285 }
2286 // Otherwise, we are not in spring loaded mode, so don't do anything.
2287 }
2288
Adam Cohenfc53cd22011-07-20 15:45:11 -07002289 public boolean isAllAppsCustomizeOpen() {
2290 return mState == State.APPS_CUSTOMIZE;
2291 }
2292
Winson Chungf0ea4d32011-06-06 14:27:16 -07002293 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002294 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002295 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002296 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002297 if (!LauncherApplication.isScreenLarge()) {
2298 if (animated) {
2299 int duration = mSearchDeleteBar.getTransitionInDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002300 mHotseat.animate().alpha(1f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002301 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002302 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002303 }
2304 }
2305 }
2306
2307 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002308 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002309 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002311 if (!LauncherApplication.isScreenLarge()) {
2312 if (animated) {
2313 int duration = mSearchDeleteBar.getTransitionOutDuration();
Winson Chung3d503fb2011-07-13 17:25:49 -07002314 mHotseat.animate().alpha(0f).setDuration(duration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002315 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002316 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002317 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002318 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002319 }
2320
Winson Chung785d2eb2011-04-14 16:08:02 -07002321 void showAllApps(boolean animated) {
2322 if (mState != State.WORKSPACE) return;
Winson Chung785d2eb2011-04-14 16:08:02 -07002323
Winson Chungf0ea4d32011-06-06 14:27:16 -07002324 cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
2325 mAppsCustomizeTabHost.requestFocus();
Winson Chung785d2eb2011-04-14 16:08:02 -07002326
Winson Chung3d503fb2011-07-13 17:25:49 -07002327 // Hide the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002328 mSearchDeleteBar.hideSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002329
Winson Chungf0ea4d32011-06-06 14:27:16 -07002330 // Change the state *after* we've called all the transition code
2331 mState = State.APPS_CUSTOMIZE;
Winson Chung785d2eb2011-04-14 16:08:02 -07002332
2333 // Pause the auto-advance of widgets until we are out of AllApps
2334 mUserPresent = false;
2335 updateRunning();
Adam Cohen2f84ef22011-07-26 17:16:44 -07002336 closeFolder();
Winson Chung785d2eb2011-04-14 16:08:02 -07002337
2338 // Send an accessibility event to announce the context change
2339 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2340 }
2341
Joe Onoratob2061212009-11-24 16:13:54 -05002342 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002343 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002344 * - Home from workspace
2345 * - from center screen
2346 * - from other screens
2347 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002348 * - from center screen
2349 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002350 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002351 * - from center screen
2352 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002353 * - Launch app from workspace and quit
2354 * - with back
2355 * - with home
2356 * - Launch app from all apps and quit
2357 * - with back
2358 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002359 * - Go to a screen that's not the default, then all
2360 * apps, and launch and app, and go back
2361 * - with back
2362 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002363 * - On workspace, long press power and go back
2364 * - with back
2365 * - with home
2366 * - On all apps, long press power and go back
2367 * - with back
2368 * - with home
2369 * - On workspace, power off
2370 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002371 * - Launch an app and turn off the screen while in that app
2372 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002373 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002374 * - From all apps
2375 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002376 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2377 * - From all apps
2378 * - From the center workspace
2379 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002380 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002381 void closeAllApps(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002382 if (mState == State.APPS_CUSTOMIZE || mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2383 mWorkspace.setVisibility(View.VISIBLE);
2384 cameraZoomIn(State.APPS_CUSTOMIZE, animated, false);
Winson Chung785d2eb2011-04-14 16:08:02 -07002385
Winson Chung3d503fb2011-07-13 17:25:49 -07002386 // Show the search bar and hotseat
Winson Chungf0ea4d32011-06-06 14:27:16 -07002387 mSearchDeleteBar.showSearchBar(animated);
Winson Chung785d2eb2011-04-14 16:08:02 -07002388
Winson Chungf0ea4d32011-06-06 14:27:16 -07002389 // Set focus to the AppsCustomize button
Winson Chung3d503fb2011-07-13 17:25:49 -07002390 if (mAllAppsButton != null) {
2391 mAllAppsButton.requestFocus();
2392 }
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002393 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002394 }
2395
Joe Onorato7c312c12009-08-13 21:36:53 -07002396 void lockAllApps() {
2397 // TODO
2398 }
2399
2400 void unlockAllApps() {
2401 // TODO
2402 }
2403
Patrick Dubroy5f445422011-02-18 14:35:21 -08002404 /**
2405 * Add an item from all apps or customize onto the given workspace screen.
2406 * If layout is null, add to the current screen.
2407 */
2408 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002409 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2410 showOutOfSpaceMessage();
Patrick Dubroy5f445422011-02-18 14:35:21 -08002411 } else {
2412 layout.animateDrop();
Michael Jurka213d9632010-07-28 11:29:25 -07002413 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002414 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002415
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002416 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002417 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002418 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002419 // Look for the toolbar icon specified in the activity meta-data
2420 Bundle metaData = packageManager.getActivityInfo(
2421 activityName, PackageManager.GET_META_DATA).metaData;
2422 if (metaData != null) {
2423 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2424 if (iconResId != 0) {
2425 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002426 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002427 }
2428 }
2429 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002430 // This can happen if the activity defines an invalid drawable
2431 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2432 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002433 } catch (Resources.NotFoundException nfe) {
2434 // This can happen if the activity defines an invalid drawable
2435 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2436 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002437 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002438 return null;
2439 }
2440
2441 // if successful in getting icon, return it; otherwise, set button to use default drawable
2442 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2443 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2444 TextView button = (TextView) findViewById(buttonId);
2445 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2446
2447 // If we were unable to find the icon via the meta-data, use a generic one
2448 if (toolbarIcon == null) {
2449 button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0);
2450 return null;
2451 } else {
2452 button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null);
2453 return toolbarIcon.getConstantState();
2454 }
2455 }
2456
2457 // if successful in getting icon, return it; otherwise, set button to use default drawable
2458 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2459 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2460 ImageView button = (ImageView) findViewById(buttonId);
2461 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2462
Michael Jurka19e0fc52011-07-22 18:00:21 -07002463 if (button != null) {
2464 // If we were unable to find the icon via the meta-data, use a
2465 // generic one
2466 if (toolbarIcon == null) {
2467 button.setImageResource(fallbackDrawableId);
2468 } else {
2469 button.setImageDrawable(toolbarIcon);
2470 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002471 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002472
2473 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2474
Michael Jurka0423dcf2010-10-05 14:56:18 -07002475 }
2476
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002477 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2478 TextView button = (TextView) findViewById(buttonId);
2479 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2480 }
2481
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002482 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002483 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002484 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002485 }
2486
Michael Jurka0423dcf2010-10-05 14:56:18 -07002487 private void updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002488 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2489 final View searchDivider = findViewById(R.id.search_divider);
Winson Chung97d85d22011-04-13 11:27:36 -07002490
Winson Chung1cad91e2011-05-25 17:41:01 -07002491 final SearchManager searchManager =
2492 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2493 ComponentName activityName = searchManager.getGlobalSearchActivity();
2494 if (activityName != null) {
Mathew Inwood68524cd2011-07-01 13:59:38 +01002495 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002496 R.id.search_button, activityName, R.drawable.ic_search_normal_holo);
Winson Chung1cad91e2011-05-25 17:41:01 -07002497 searchButton.setVisibility(View.VISIBLE);
Winson Chung649723c2011-07-06 20:41:23 -07002498 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002499 } else {
2500 searchButton.setVisibility(View.GONE);
Winson Chung649723c2011-07-06 20:41:23 -07002501 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002502 }
2503 }
2504
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002505 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002506 updateButtonWithDrawable(R.id.search_button, d);
2507 }
2508
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002509 private void updateVoiceSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07002510 final View searchDivider = findViewById(R.id.search_divider);
2511 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002512
Winson Chung1cad91e2011-05-25 17:41:01 -07002513 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2514 ComponentName activityName = intent.resolveActivity(getPackageManager());
2515 if (activityName != null) {
2516 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Winson Chung649723c2011-07-06 20:41:23 -07002517 R.id.voice_button, activityName, R.drawable.ic_voice_search_holo);
2518 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002519 voiceButton.setVisibility(View.VISIBLE);
2520 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002521 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002522 voiceButton.setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002523 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002524 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002525
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002526 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002527 updateButtonWithDrawable(R.id.voice_button, d);
2528 }
2529
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002530 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002531 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002532 */
2533 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002534 final View marketButton = findViewById(R.id.market_button);
2535 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2536 // Find the app market activity by resolving an intent.
2537 // (If multiple app markets are installed, it will return the ResolverActivity.)
2538 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002539 if (activityName != null) {
Winson Chung785d2eb2011-04-14 16:08:02 -07002540 mAppMarketIntent = intent;
2541 sAppMarketIcon = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002542 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002543 marketButton.setVisibility(View.VISIBLE);
2544 } else {
2545 // We should hide and disable the view so that we don't try and restore the visibility
2546 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2547 marketButton.setVisibility(View.GONE);
2548 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002549 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002550 }
2551
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002552 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002553 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002554 }
2555
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002556 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 * Displays the shortcut creation dialog and launches, if necessary, the
2558 * appropriate activity.
2559 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002560 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002561 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2562 DialogInterface.OnShowListener {
2563
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002568
Winson Chung55b65502011-05-26 12:03:43 -07002569 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2570 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002571 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002572
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002573 AlertDialog dialog = builder.create();
2574 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002575 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002576 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002577
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002578 return dialog;
2579 }
2580
2581 public void onCancel(DialogInterface dialog) {
2582 mWaitingForResult = false;
2583 cleanup();
2584 }
2585
Romain Guycbb89e42009-06-08 15:52:54 -07002586 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002587 mWaitingForResult = false;
2588 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002589 }
2590
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002592 try {
2593 dismissDialog(DIALOG_CREATE_SHORTCUT);
2594 } catch (Exception e) {
2595 // An exception is thrown if the dialog is not visible, which is fine
2596 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002597 }
2598
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002599 /**
2600 * Handle the action clicked in the "Add to home" dialog.
2601 */
2602 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002603 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002604
Winson Chung55b65502011-05-26 12:03:43 -07002605 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2606 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002607 case AddAdapter.ITEM_APPLICATION: {
2608 if (mAppsCustomizeTabHost != null) {
2609 mAppsCustomizeTabHost.selectAppsTab();
2610 }
2611 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002612 break;
2613 }
Winson Chung55b65502011-05-26 12:03:43 -07002614 case AddAdapter.ITEM_APPWIDGET: {
2615 if (mAppsCustomizeTabHost != null) {
2616 mAppsCustomizeTabHost.selectWidgetsTab();
2617 }
2618 showAllApps(true);
2619 break;
2620 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002621 case AddAdapter.ITEM_WALLPAPER: {
2622 startWallpaper();
2623 break;
2624 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002625 }
2626 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002627
2628 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002629 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002630 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002631 }
2632
2633 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002634 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002635 */
2636 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2637 @Override
2638 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002639 closeSystemDialogs();
2640 }
2641 }
2642
2643 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002644 * Receives notifications whenever the appwidgets are reset.
2645 */
2646 private class AppWidgetResetObserver extends ContentObserver {
2647 public AppWidgetResetObserver() {
2648 super(new Handler());
2649 }
2650
2651 @Override
2652 public void onChange(boolean selfChange) {
2653 onAppWidgetReset();
2654 }
2655 }
2656
2657 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002658 * If the activity is currently paused, signal that we need to re-run the loader
2659 * in onResume.
2660 *
2661 * This needs to be called from incoming places where resources might have been loaded
2662 * while we are paused. That is becaues the Configuration might be wrong
2663 * when we're not running, and if it comes back to what it was when we
2664 * were paused, we are not restarted.
2665 *
2666 * Implementation of the method from LauncherModel.Callbacks.
2667 *
2668 * @return true if we are currently paused. The caller might be able to
2669 * skip some work in that case since we will come back again.
2670 */
2671 public boolean setLoadOnResume() {
2672 if (mPaused) {
2673 Log.i(TAG, "setLoadOnResume");
2674 mOnResumeNeedsLoad = true;
2675 return true;
2676 } else {
2677 return false;
2678 }
2679 }
2680
2681 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002682 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002683 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002684 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002685 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002686 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002687 } else {
2688 return SCREEN_COUNT / 2;
2689 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002690 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002691
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002692
Joe Onorato9c1289c2009-08-17 11:03:03 -04002693 /**
2694 * Refreshes the shortcuts shown on the workspace.
2695 *
2696 * Implementation of the method from LauncherModel.Callbacks.
2697 */
2698 public void startBinding() {
2699 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002700
2701 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002702 int count = workspace.getChildCount();
2703 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002704 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002705 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2706 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002707 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002708 if (mHotseat != null) {
2709 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002710 }
Adam Cohenf5d77c92011-02-03 12:55:38 -08002711
Adam Cohen4eac29a2011-07-11 17:53:37 -07002712 // This wasn't being called before which resulted in a leak of AppWidgetHostViews
Winson Chung3d503fb2011-07-13 17:25:49 -07002713 unbindWorkspaceAndHotseatItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002714 }
2715
2716 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002717 * Bind the items start-end from the list.
2718 *
2719 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002720 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002721 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002722 setLoadOnResume();
2723
Joe Onorato9c1289c2009-08-17 11:03:03 -04002724 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002725 for (int i=start; i<end; i++) {
2726 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002727
2728 // Short circuit if we are loading dock items for a configuration which has no dock
2729 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2730 mHotseat == null) {
2731 continue;
2732 }
2733
Joe Onorato9c1289c2009-08-17 11:03:03 -04002734 switch (item.itemType) {
2735 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2736 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002737 View shortcut = createShortcut((ShortcutInfo)item);
2738 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
2739 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002740 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07002741 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07002742 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002743 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07002744 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07002745 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
2746 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002747 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002748 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002749 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002750 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 }
2752
Joe Onorato9c1289c2009-08-17 11:03:03 -04002753 /**
2754 * Implementation of the method from LauncherModel.Callbacks.
2755 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002756 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002757 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002758 sFolders.clear();
2759 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002760 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002761
2762 /**
2763 * Add the views for a widget to the workspace.
2764 *
2765 * Implementation of the method from LauncherModel.Callbacks.
2766 */
2767 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002768 setLoadOnResume();
2769
Daniel Sandler843e8602010-06-07 14:59:01 -04002770 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2771 if (DEBUG_WIDGETS) {
2772 Log.d(TAG, "bindAppWidget: " + item);
2773 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002774 final Workspace workspace = mWorkspace;
2775
2776 final int appWidgetId = item.appWidgetId;
2777 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002778 if (DEBUG_WIDGETS) {
2779 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2780 }
2781
Joe Onorato9c1289c2009-08-17 11:03:03 -04002782 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2783
Joe Onorato9c1289c2009-08-17 11:03:03 -04002784 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2785 item.hostView.setTag(item);
2786
Winson Chung3d503fb2011-07-13 17:25:49 -07002787 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04002788 item.cellY, item.spanX, item.spanY, false);
2789
Adam Cohended9f8d2010-11-03 13:25:16 -07002790 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
2791
Joe Onorato9c1289c2009-08-17 11:03:03 -04002792 workspace.requestLayout();
2793
Daniel Sandler843e8602010-06-07 14:59:01 -04002794 if (DEBUG_WIDGETS) {
2795 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2796 + (SystemClock.uptimeMillis()-start) + "ms");
2797 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002798 }
2799
2800 /**
2801 * Callback saying that there aren't any more items to bind.
2802 *
2803 * Implementation of the method from LauncherModel.Callbacks.
2804 */
2805 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002806 setLoadOnResume();
2807
Joe Onorato9c1289c2009-08-17 11:03:03 -04002808 if (mSavedState != null) {
2809 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002810 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002811 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002812 mSavedState = null;
2813 }
2814
2815 if (mSavedInstanceState != null) {
2816 super.onRestoreInstanceState(mSavedInstanceState);
2817 mSavedInstanceState = null;
2818 }
2819
Joe Onorato9c1289c2009-08-17 11:03:03 -04002820 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08002821
2822 // If we received the result of any pending adds while the loader was running (e.g. the
2823 // widget configuration forced an orientation change), process them now.
2824 for (int i = 0; i < sPendingAddList.size(); i++) {
2825 completeAdd(sPendingAddList.get(i));
2826 }
2827 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002828 }
2829
2830 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002831 * Updates the icons on the launcher that are affected by changes to the package list
2832 * on the device.
2833 */
2834 private void updateIconsAffectedByPackageManagerChanges() {
2835 updateAppMarketIcon();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002836 updateVoiceSearchIcon();
2837 }
2838
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002839 @Override
2840 public void bindSearchablesChanged() {
2841 updateGlobalSearchIcon();
2842 }
2843
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002844 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002845 * Add the icons for all apps.
2846 *
2847 * Implementation of the method from LauncherModel.Callbacks.
2848 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07002849 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
2850 // Remove the progress bar entirely; we could also make it GONE
2851 // but better to remove it since we know it's not going to be used
2852 View progressBar = mAppsCustomizeTabHost.
2853 findViewById(R.id.apps_customize_progress_bar);
2854 if (progressBar != null) {
2855 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07002856 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07002857 // We just post the call to setApps so the user sees the progress bar
2858 // disappear-- otherwise, it just looks like the progress bar froze
2859 // which doesn't look great
2860 mAppsCustomizeTabHost.post(new Runnable() {
2861 public void run() {
2862 if (mAppsCustomizeContent != null) {
2863 mAppsCustomizeContent.setApps(apps);
2864 }
2865 }
2866 });
2867
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002868 updateIconsAffectedByPackageManagerChanges();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01002869 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002870 }
2871
2872 /**
2873 * A package was installed.
2874 *
2875 * Implementation of the method from LauncherModel.Callbacks.
2876 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002877 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002878 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002879 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002880
Winson Chung785d2eb2011-04-14 16:08:02 -07002881 if (mAppsCustomizeContent != null) {
2882 mAppsCustomizeContent.addApps(apps);
2883 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002884 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002885 }
2886
2887 /**
2888 * A package was updated.
2889 *
2890 * Implementation of the method from LauncherModel.Callbacks.
2891 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002892 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002893 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002894 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08002895 if (mWorkspace != null) {
2896 mWorkspace.updateShortcuts(apps);
2897 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002898
Winson Chung785d2eb2011-04-14 16:08:02 -07002899 if (mAppsCustomizeContent != null) {
2900 mAppsCustomizeContent.updateApps(apps);
2901 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002902 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002903 }
2904
2905 /**
2906 * A package was uninstalled.
2907 *
2908 * Implementation of the method from LauncherModel.Callbacks.
2909 */
Joe Onorato36115782010-06-17 13:28:48 -04002910 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002911 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002912 if (permanent) {
2913 mWorkspace.removeItems(apps);
2914 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002915
Winson Chung785d2eb2011-04-14 16:08:02 -07002916 if (mAppsCustomizeContent != null) {
2917 mAppsCustomizeContent.removeApps(apps);
2918 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002919 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002920 }
Joe Onoratobe386092009-11-17 17:32:16 -08002921
2922 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002923 * A number of packages were updated.
2924 */
2925 public void bindPackagesUpdated() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002926
Winson Chung785d2eb2011-04-14 16:08:02 -07002927 if (mAppsCustomizeContent != null) {
2928 mAppsCustomizeContent.onPackagesUpdated();
2929 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002930 }
2931
Winson Chung400438b2011-01-16 17:53:48 -08002932 private int mapConfigurationOriActivityInfoOri(int configOri) {
2933 final Display d = getWindowManager().getDefaultDisplay();
2934 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
2935 switch (d.getRotation()) {
2936 case Surface.ROTATION_0:
2937 case Surface.ROTATION_180:
2938 // We are currently in the same basic orientation as the natural orientation
2939 naturalOri = configOri;
2940 break;
2941 case Surface.ROTATION_90:
2942 case Surface.ROTATION_270:
2943 // We are currently in the other basic orientation to the natural orientation
2944 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
2945 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
2946 break;
2947 }
2948
2949 int[] oriMap = {
2950 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
2951 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
2952 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
2953 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
2954 };
2955 // Since the map starts at portrait, we need to offset if this device's natural orientation
2956 // is landscape.
2957 int indexOffset = 0;
2958 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
2959 indexOffset = 1;
2960 }
2961 return oriMap[(d.getRotation() + indexOffset) % 4];
2962 }
2963 public void lockScreenOrientation() {
2964 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
2965 .getConfiguration().orientation));
2966 }
2967 public void unlockScreenOrientation() {
2968 mHandler.postDelayed(new Runnable() {
2969 public void run() {
2970 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
2971 }
2972 }, mRestoreScreenOrientationDelay);
2973 }
2974
Winson Chung82f55532011-08-09 14:14:23 -07002975 /* Cling related */
2976 private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed";
2977 private static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed";
2978 private void enableClingsIfNecessary() {
2979 // TEMPORARY: DISABLE CLINGS ON LARGE UI
2980 if (LauncherApplication.isScreenLarge()) return;
2981
Brett Chabot2a9e2282011-08-23 15:03:13 -07002982 // disable clings when running in a test harness
2983 if(ActivityManager.isRunningInTestHarness()) return;
2984
Winson Chung82f55532011-08-09 14:14:23 -07002985 // Enable the clings only if they have not been dismissed before
2986 SharedPreferences prefs =
2987 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
2988 if (!prefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false)) {
2989 Cling cling = (Cling) findViewById(R.id.workspace_cling);
2990 cling.init(this);
2991 cling.setVisibility(View.VISIBLE);
2992 }
2993 if (!prefs.getBoolean(ALLAPPS_CLING_DISMISSED_KEY, false)) {
2994 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
2995 cling.init(this);
2996 cling.setVisibility(View.VISIBLE);
2997 }
2998 }
2999 private void dismissCling(final Cling cling, final String flag) {
3000 if (cling != null) {
3001 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
3002 anim.setDuration(DISMISS_CLING_DURATION);
3003 anim.addListener(new AnimatorListenerAdapter() {
3004 public void onAnimationEnd(Animator animation) {
3005 cling.setVisibility(View.GONE);
3006 cling.cleanup();
3007 SharedPreferences prefs =
3008 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3009 SharedPreferences.Editor editor = prefs.edit();
3010 editor.putBoolean(flag, true);
3011 editor.commit();
3012 };
3013 });
3014 anim.start();
3015 }
3016 }
3017 public void dismissWorkspaceCling(View v) {
3018 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3019 dismissCling(cling, WORKSPACE_CLING_DISMISSED_KEY);
3020 }
3021 public void dismissAllAppsCling(View v) {
3022 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
3023 dismissCling(cling, ALLAPPS_CLING_DISMISSED_KEY);
3024 }
3025
Winson Chung80baf5a2010-08-09 16:03:15 -07003026 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003027 * Prints out out state for debugging.
3028 */
3029 public void dumpState() {
3030 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003031 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003032 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3033 Log.d(TAG, "mRestoring=" + mRestoring);
3034 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3035 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003036 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003037 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003038
Winson Chung785d2eb2011-04-14 16:08:02 -07003039 if (mAppsCustomizeContent != null) {
3040 mAppsCustomizeContent.dumpState();
3041 }
Joe Onoratobe386092009-11-17 17:32:16 -08003042 Log.d(TAG, "END launcher2 dump state");
3043 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003044}
Michael Jurka2763be32011-02-24 11:19:57 -08003045
Michael Jurkaabded662011-03-04 12:06:57 -08003046interface LauncherTransitionable {
Winson Chung5a808352011-06-27 19:08:49 -07003047 void onLauncherTransitionStart(Animator animation, boolean toWorkspace);
3048 void onLauncherTransitionEnd(Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003049}