blob: 33ca88723bb18f837f4399e459293c5881e5e076 [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;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
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;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040054import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070055import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020057import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080058import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070059import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040060import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080061import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070062import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080063import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.text.Selection;
65import android.text.SpannableStringBuilder;
66import android.text.TextUtils;
67import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070068import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080069import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080070import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.view.KeyEvent;
72import android.view.LayoutInflater;
73import android.view.Menu;
74import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070075import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080076import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080078import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070079import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080080import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080081import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070082import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080083import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070084import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070085import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070088import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070091import android.widget.TextView;
92import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070093
Adam Cohendf2cc412011-04-27 16:56:57 -070094import com.android.common.Search;
95import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070096import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080097
Adam Cohenc0dcf592011-06-01 15:30:43 -070098import java.io.DataInputStream;
99import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700100import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.FileNotFoundException;
102import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700103import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700104import java.util.ArrayList;
105import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107/**
108 * Default launcher application.
109 */
Michael Jurka946ad472010-07-09 18:05:18 -0700110public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700111 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
112 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800113 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700114 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
Joe Onorato9c1289c2009-08-17 11:03:03 -0400116 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400117 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700118
Winson Chung70d72102011-08-12 11:24:35 -0700119 private static final int MENU_GROUP_WALLPAPER = 1;
120 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
121 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700122 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
123 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124
125 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700126 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int REQUEST_PICK_APPLICATION = 6;
128 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700129 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700130 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
133
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800134 static final int SCREEN_COUNT = 5;
135 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Joe Onorato7c312c12009-08-13 21:36:53 -0700137 static final int DIALOG_CREATE_SHORTCUT = 1;
138 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Romain Guy98d01652009-06-30 16:21:04 -0700140 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800141 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 // Type: int
144 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700145 // Type: int
146 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700148 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
149 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
151 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700152 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700154 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: boolean
156 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
157 // Type: long
158 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
159
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700160 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
161
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700162 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700163 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700164 private State mState = State.WORKSPACE;
165 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800166 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700167
Joe Onorato9c1289c2009-08-17 11:03:03 -0400168 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700169 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
170 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700171 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700172 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800175 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800177 private final BroadcastReceiver mCloseSystemDialogsReceiver
178 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800179 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private LayoutInflater mInflater;
182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private View mQsbDivider;
185 private View mDockDivider;
186 private DragLayer mDragLayer;
187 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700188
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700189 private AppWidgetManager mAppWidgetManager;
190 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700191
Michael Jurkac9d95c52011-08-29 14:03:34 -0700192 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700193 private int[] mTmpAddItemCellCoordinates = new int[2];
194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private FolderInfo mFolderInfo;
196
Winson Chung3d503fb2011-07-13 17:25:49 -0700197 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800198 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700199
Winson Chungc51db6a2011-10-05 11:44:49 -0700200 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700201 private AppsCustomizeTabHost mAppsCustomizeTabHost;
202 private AppsCustomizePagedView mAppsCustomizeContent;
203 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private Bundle mSavedState;
206
207 private SpannableStringBuilder mDefaultKeySsb = null;
208
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209 private boolean mWorkspaceLoading = true;
210
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800211 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private boolean mRestoring;
213 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700214 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
216 private Bundle mSavedInstanceState;
217
Joe Onorato9c1289c2009-08-17 11:03:03 -0400218 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800220 private boolean mUserPresent = true;
221 private boolean mVisible = false;
222 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700224 private static LocaleConfiguration sLocaleConfiguration = null;
225
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700226 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700227
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700228 private Intent mAppMarketIntent = null;
229
Adam Cohended9f8d2010-11-03 13:25:16 -0700230 // Related to the auto-advancing of widgets
231 private final int ADVANCE_MSG = 1;
232 private final int mAdvanceInterval = 20000;
233 private final int mAdvanceStagger = 250;
234 private long mAutoAdvanceSentTime;
235 private long mAutoAdvanceTimeLeft = -1;
236 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
237 new HashMap<View, AppWidgetProviderInfo>();
238
Winson Chung400438b2011-01-16 17:53:48 -0800239 // Determines how long to wait after a rotation before restoring the screen orientation to
240 // match the sensor state.
241 private final int mRestoreScreenOrientationDelay = 500;
242
Michael Jurka4ef207b2010-11-29 17:05:45 -0800243 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700244 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
245 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800247
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700248 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
249
Adam Cohen2801caf2011-05-13 20:57:39 -0700250
Michael Jurkaddd62e92011-02-16 17:49:14 -0800251 private BubbleTextView mWaitingForResume;
252
Michael Jurkac1f5d262011-09-30 19:32:27 -0700253 private Runnable mBuildLayersRunnable = new Runnable() {
254 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700255 if (mWorkspace != null) {
256 mWorkspace.buildPageHardwareLayers();
257 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700258 }
259 };
260
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800261 private static ArrayList<PendingAddArguments> sPendingAddList
262 = new ArrayList<PendingAddArguments>();
263
264 private static class PendingAddArguments {
265 int requestCode;
266 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800268 int screen;
269 int cellX;
270 int cellY;
271 }
272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 @Override
274 protected void onCreate(Bundle savedInstanceState) {
275 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800276 LauncherApplication app = ((LauncherApplication)getApplication());
277 mModel = app.setLauncher(this);
278 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400279 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700282 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
284 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700285
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200287 android.os.Debug.startMethodTracing(
288 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 }
290
291 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 setContentView(R.layout.launcher);
293 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700294 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800296 registerContentObservers();
297
Joe Onorato7c312c12009-08-13 21:36:53 -0700298 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 mSavedState = savedInstanceState;
301 restoreState(mSavedState);
302
Winson Chunga12a2502010-12-20 14:41:35 -0800303 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700304 if (mAppsCustomizeContent != null) {
305 mAppsCustomizeContent.onPackagesUpdated();
306 }
Winson Chunga12a2502010-12-20 14:41:35 -0800307
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800308 if (PROFILE_STARTUP) {
309 android.os.Debug.stopMethodTracing();
310 }
311
312 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400313 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 }
315
Michael Jurkac57b7a82011-08-09 22:02:20 -0700316 if (!mModel.isAllAppsLoaded()) {
317 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
318 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
319 }
320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 // For handling default keys
322 mDefaultKeySsb = new SpannableStringBuilder();
323 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800324
325 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
326 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800327
Winson Chungc51db6a2011-10-05 11:44:49 -0700328 boolean searchVisible = false;
329 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800330 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700331 int coi = getCurrentOrientationIndexForGlobalIcons();
332 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
333 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700334 updateAppMarketIcon();
335 searchVisible = updateGlobalSearchIcon();
336 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700337 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700338 if (sGlobalSearchIcon[coi] != null) {
339 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700340 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700341 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700342 if (sVoiceSearchIcon[coi] != null) {
343 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700344 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700345 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700346 if (sAppMarketIcon[coi] != null) {
347 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800348 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700349 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700350
Adam Cohen23a4d302011-12-01 17:26:44 -0800351 final String forceEnableRotation =
352 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
353
Adam Cohen446e9402011-09-15 18:21:21 -0700354 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800355 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700356 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
357 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 }
Romain Guycbb89e42009-06-08 15:52:54 -0700359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700361 if (sLocaleConfiguration == null) {
362 new AsyncTask<Void, Void, LocaleConfiguration>() {
363 @Override
364 protected LocaleConfiguration doInBackground(Void... unused) {
365 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
366 readConfiguration(Launcher.this, localeConfiguration);
367 return localeConfiguration;
368 }
369
370 @Override
371 protected void onPostExecute(LocaleConfiguration result) {
372 sLocaleConfiguration = result;
373 checkForLocaleChange(); // recursive, but now with a locale configuration
374 }
375 }.execute();
376 return;
377 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 final Configuration configuration = getResources().getConfiguration();
380
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700381 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 final String locale = configuration.locale.toString();
383
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700384 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 final int mcc = configuration.mcc;
386
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700387 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 final int mnc = configuration.mnc;
389
Romain Guy84f296c2009-11-04 15:00:44 -0800390 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391
Romain Guy84f296c2009-11-04 15:00:44 -0800392 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700393 sLocaleConfiguration.locale = locale;
394 sLocaleConfiguration.mcc = mcc;
395 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700396
Joe Onorato0589f0f2010-02-08 13:44:00 -0800397 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700398
399 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
400 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700401 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700402 public void run() {
403 writeConfiguration(Launcher.this, localeConfiguration);
404 }
405 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700406 }
407 }
408
409 private static class LocaleConfiguration {
410 public String locale;
411 public int mcc = -1;
412 public int mnc = -1;
413 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700414
Romain Guy98d01652009-06-30 16:21:04 -0700415 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
416 DataInputStream in = null;
417 try {
418 in = new DataInputStream(context.openFileInput(PREFERENCES));
419 configuration.locale = in.readUTF();
420 configuration.mcc = in.readInt();
421 configuration.mnc = in.readInt();
422 } catch (FileNotFoundException e) {
423 // Ignore
424 } catch (IOException e) {
425 // Ignore
426 } finally {
427 if (in != null) {
428 try {
429 in.close();
430 } catch (IOException e) {
431 // Ignore
432 }
433 }
434 }
435 }
436
437 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
438 DataOutputStream out = null;
439 try {
440 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
441 out.writeUTF(configuration.locale);
442 out.writeInt(configuration.mcc);
443 out.writeInt(configuration.mnc);
444 out.flush();
445 } catch (FileNotFoundException e) {
446 // Ignore
447 } catch (IOException e) {
448 //noinspection ResultOfMethodCallIgnored
449 context.getFileStreamPath(PREFERENCES).delete();
450 } finally {
451 if (out != null) {
452 try {
453 out.close();
454 } catch (IOException e) {
455 // Ignore
456 }
457 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 }
459 }
460
Adam Cohen716b51e2011-06-30 12:09:54 -0700461 public DragLayer getDragLayer() {
462 return mDragLayer;
463 }
464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 static int getScreen() {
466 synchronized (sLock) {
467 return sScreen;
468 }
469 }
470
471 static void setScreen(int screen) {
472 synchronized (sLock) {
473 sScreen = screen;
474 }
475 }
476
Winson Chung557d6ed2011-07-08 15:34:52 -0700477 /**
478 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
479 * a configuration step, this allows the proper animations to run after other transitions.
480 */
481 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700482 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800483 switch (args.requestCode) {
484 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700485 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
486 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800487 break;
488 case REQUEST_PICK_SHORTCUT:
489 processShortcut(args.intent);
490 break;
491 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700492 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
493 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700494 result = true;
495 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800496 case REQUEST_PICK_APPWIDGET:
497 addAppWidgetFromPick(args.intent);
498 break;
499 case REQUEST_CREATE_APPWIDGET:
500 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700501 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700502 result = true;
503 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800504 case REQUEST_PICK_WALLPAPER:
505 // We just wanted the activity result here so we can clear mWaitingForResult
506 break;
507 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700508 // In any situation where we have a multi-step drop, we should reset the add info only after
509 // we complete the drop
510 resetAddInfo();
511 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800512 }
513
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800514 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800515 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700516 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700517 mWaitingForResult = false;
518
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 // The pattern used here is that a user PICKs a specific application,
520 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700521
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800522 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
523 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700524 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800525 final PendingAddArguments args = new PendingAddArguments();
526 args.requestCode = requestCode;
527 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700528 args.container = mPendingAddInfo.container;
529 args.screen = mPendingAddInfo.screen;
530 args.cellX = mPendingAddInfo.cellX;
531 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800532
533 // If the loader is still running, defer the add until it is done.
534 if (isWorkspaceLocked()) {
535 sPendingAddList.add(args);
536 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700537 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800538 }
Romain Guy18042c82009-11-06 11:44:55 -0800539 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700540 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
541 if (data != null) {
542 // Clean up the appWidgetId if we canceled
543 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
544 if (appWidgetId != -1) {
545 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
546 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800547 }
548 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700549
550 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700551 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800552 }
553
554 @Override
555 protected void onResume() {
556 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800557 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700558 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400559 mWorkspaceLoading = true;
560 mModel.startLoader(this, true);
561 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700562 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800564 if (mWaitingForResume != null) {
565 mWaitingForResume.setStayPressed(false);
566 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700567 // When we resume Launcher, a different Activity might be responsible for the app
568 // market intent, so refresh the icon
569 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570 }
571
572 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700573 protected void onPause() {
574 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700575 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800576 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700577 }
Romain Guycbb89e42009-06-08 15:52:54 -0700578
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700579 @Override
580 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400581 // Flag the loader to stop early before switching
582 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700583 if (mAppsCustomizeContent != null) {
584 mAppsCustomizeContent.surrender();
585 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800586 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700587 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700588
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800589 // We can't hide the IME if it was forced open. So don't bother
590 /*
591 @Override
592 public void onWindowFocusChanged(boolean hasFocus) {
593 super.onWindowFocusChanged(hasFocus);
594
595 if (hasFocus) {
596 final InputMethodManager inputManager = (InputMethodManager)
597 getSystemService(Context.INPUT_METHOD_SERVICE);
598 WindowManager.LayoutParams lp = getWindow().getAttributes();
599 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
600 android.os.Handler()) {
601 protected void onReceiveResult(int resultCode, Bundle resultData) {
602 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
603 }
604 });
605 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
606 }
607 }
608 */
609
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800610 private boolean acceptFilter() {
611 final InputMethodManager inputManager = (InputMethodManager)
612 getSystemService(Context.INPUT_METHOD_SERVICE);
613 return !inputManager.isFullscreenMode();
614 }
615
616 @Override
617 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700618 final int uniChar = event.getUnicodeChar();
619 final boolean handled = super.onKeyDown(keyCode, event);
620 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
621 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
623 keyCode, event);
624 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700625 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700626 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700627 // showSearchDialog()
628 // If there are multiple keystrokes before the search dialog takes focus,
629 // onSearchRequested() will be called for every keystroke,
630 // but it is idempotent, so it's fine.
631 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800632 }
633 }
634
Joe Onorato8a9625e2010-01-28 15:55:35 -0800635 // Eat the long press event so the keyboard doesn't come up.
636 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
637 return true;
638 }
639
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800640 return handled;
641 }
642
Karl Rosaen138a0412009-04-23 19:00:21 -0700643 private String getTypedText() {
644 return mDefaultKeySsb.toString();
645 }
646
647 private void clearTypedText() {
648 mDefaultKeySsb.clear();
649 mDefaultKeySsb.clearSpans();
650 Selection.setSelection(mDefaultKeySsb, 0);
651 }
652
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700654 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
655 * State
656 */
657 private static State intToState(int stateOrdinal) {
658 State state = State.WORKSPACE;
659 final State[] stateValues = State.values();
660 for (int i = 0; i < stateValues.length; i++) {
661 if (stateValues[i].ordinal() == stateOrdinal) {
662 state = stateValues[i];
663 break;
664 }
665 }
666 return state;
667 }
668
669 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800670 * Restores the previous state, if it exists.
671 *
672 * @param savedState The previous state.
673 */
674 private void restoreState(Bundle savedState) {
675 if (savedState == null) {
676 return;
677 }
678
Michael Jurka883f55b2010-10-21 15:47:14 -0700679 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700680 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800681 showAllApps(false);
682 }
683
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
685 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700686 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 }
688
Winson Chung3d503fb2011-07-13 17:25:49 -0700689 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
690 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700691
Winson Chung3d503fb2011-07-13 17:25:49 -0700692 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
693 mPendingAddInfo.container = pendingAddContainer;
694 mPendingAddInfo.screen = pendingAddScreen;
695 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
696 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800697 mRestoring = true;
698 }
699
700 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
701 if (renameFolder) {
702 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700703 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 mRestoring = true;
705 }
Winson Chunga12a2502010-12-20 14:41:35 -0800706
Winson Chung785d2eb2011-04-14 16:08:02 -0700707
708 // Restore the AppsCustomize tab
709 if (mAppsCustomizeTabHost != null) {
710 String curTab = savedState.getString("apps_customize_currentTab");
711 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700712 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700713 mAppsCustomizeContent.setContentType(
714 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
715 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700716 mAppsCustomizeContent.loadAssociatedPages(
717 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700718 }
719
Winson Chung5afbf7b2011-07-25 11:53:08 -0700720 int currentIndex = savedState.getInt("apps_customize_currentIndex");
721 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700722 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 }
724
725 /**
726 * Finds all the views we need and configure them properly.
727 */
728 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700729 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400730
Winson Chung4c98d922011-05-31 16:50:48 -0700731 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
732 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800733 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
734 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735
Winson Chung4c98d922011-05-31 16:50:48 -0700736 // Setup the drag layer
737 mDragLayer.setup(this, dragController);
738
Winson Chung3d503fb2011-07-13 17:25:49 -0700739 // Setup the hotseat
740 mHotseat = (Hotseat) findViewById(R.id.hotseat);
741 if (mHotseat != null) {
742 mHotseat.setup(this);
743 }
744
Winson Chung4c98d922011-05-31 16:50:48 -0700745 // Setup the workspace
746 mWorkspace.setHapticFeedbackEnabled(false);
747 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700748 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700749 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700750
Winson Chungf0ea4d32011-06-06 14:27:16 -0700751 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700752 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700753
Winson Chungf0ea4d32011-06-06 14:27:16 -0700754 // Setup AppsCustomize
755 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
756 findViewById(R.id.apps_customize_pane);
757 mAppsCustomizeContent = (AppsCustomizePagedView)
758 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
759 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400760
Michael Jurka5130e402011-10-13 04:55:35 -0700761 // Get the all apps button
762 mAllAppsButton = findViewById(R.id.all_apps_button);
763 if (mAllAppsButton != null) {
764 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
765 @Override
766 public boolean onTouch(View v, MotionEvent event) {
767 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
768 onTouchDownAllAppsButton(v);
769 }
770 return false;
771 }
772 });
773 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700774 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700775 dragController.setDragScoller(mWorkspace);
776 dragController.setScrollView(mDragLayer);
777 dragController.setMoveTarget(mWorkspace);
778 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700779 if (mSearchDropTargetBar != null) {
780 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800781 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800782 }
783
784 /**
785 * Creates a view representing a shortcut.
786 *
787 * @param info The data structure describing the shortcut.
788 *
789 * @return A View inflated from R.layout.application.
790 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800791 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800792 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700793 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 }
795
796 /**
797 * Creates a view representing a shortcut inflated from the specified resource.
798 *
799 * @param layoutResId The id of the XML layout used to create the shortcut.
800 * @param parent The group the shortcut belongs to.
801 * @param info The data structure describing the shortcut.
802 *
803 * @return A View inflated from layoutResId.
804 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800805 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800806 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
807 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800808 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 return favorite;
810 }
811
812 /**
813 * Add an application shortcut to the workspace.
814 *
815 * @param data The intent describing the application.
816 * @param cellInfo The position on screen where to create the shortcut.
817 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700818 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700819 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700820 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700821
Adam Cohenfbba09b2011-07-18 21:43:05 -0700822 // First we check if we already know the exact location where we want to add this item.
823 if (cellX >= 0 && cellY >= 0) {
824 cellXY[0] = cellX;
825 cellXY[1] = cellY;
826 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700827 showOutOfSpaceMessage();
828 return;
829 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800830
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800831 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800832
Romain Guy73b979d2009-06-09 12:57:21 -0700833 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800834 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800836 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700837 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700838 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800839 } else {
840 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 }
842 }
Romain Guycbb89e42009-06-08 15:52:54 -0700843
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 /**
845 * Add a shortcut to the workspace.
846 *
847 * @param data The intent describing the shortcut.
848 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700850 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
851 int cellY) {
852 int[] cellXY = mTmpAddItemCellCoordinates;
853 int[] touchXY = mPendingAddInfo.dropPos;
854 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700855
Michael Jurkad3ef3062010-11-23 16:23:58 -0800856 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700857
Adam Cohen558baaf2011-08-15 15:22:57 -0700858 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800859 if (info == null) {
860 return;
861 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700862 final View view = createShortcut(info);
863
Adam Cohenfbba09b2011-07-18 21:43:05 -0700864 // First we check if we already know the exact location where we want to add this item.
865 if (cellX >= 0 && cellY >= 0) {
866 cellXY[0] = cellX;
867 cellXY[1] = cellY;
868 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700869
870 // If appropriate, either create a folder or add to an existing folder
871 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
872 true, null,null)) {
873 return;
874 }
875 DragObject dragObject = new DragObject();
876 dragObject.dragInfo = info;
877 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
878 return;
879 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700880 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800881 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700882 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800883 foundCellSpan = (result != null);
884 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700885 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800886 }
887
888 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700889 showOutOfSpaceMessage();
890 return;
891 }
892
Adam Cohen558baaf2011-08-15 15:22:57 -0700893 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894
895 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700896 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
897 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 }
899 }
900
Adam Cohenf814aa02011-09-01 13:48:05 -0700901 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
902 if (spanXY == null) {
903 spanXY = new int[2];
904 }
905
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800906 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700907 // We want to account for the extra amount of padding that we are adding to the widget
908 // to ensure that it gets the full amount of space that it has requested
909 int requiredWidth = minWidth + padding.left + padding.right;
910 int requiredHeight = minHeight + padding.top + padding.bottom;
911 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
912 }
913
914 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
915 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
916 }
917
Adam Cohencbf47e32011-09-16 17:32:37 -0700918 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
919 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
920 }
921
Adam Cohenf814aa02011-09-01 13:48:05 -0700922 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
923 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
924 }
925
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800926 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700927 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700929 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700930 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700932 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700933 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700934
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700935 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700936 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700937
Adam Cohenf814aa02011-09-01 13:48:05 -0700938 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700939
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700941 // We have saved the position to which the widget was dragged-- this really only matters
942 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700943 int[] cellXY = mTmpAddItemCellCoordinates;
944 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700945 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700946 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
947 cellXY[0] = mPendingAddInfo.cellX;
948 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700949 foundCellSpan = true;
950 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700951 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700952 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700953 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800954 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700955 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700956 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700957 }
958
Michael Jurka0280c3b2010-09-17 15:00:07 -0700959 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800960 if (appWidgetId != -1) {
961 // Deleting an app widget ID is a void call but writes to disk before returning
962 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800963 new Thread("deleteAppWidgetId") {
964 public void run() {
965 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
966 }
967 }.start();
968 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700969 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800970 return;
971 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800972
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700973 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -0700974 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700975 launcherInfo.spanX = spanXY[0];
976 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700977
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800978 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700979 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980
981 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700983 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700984
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700985 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800986 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700987
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400989 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700990
991 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 }
993 }
Romain Guycbb89e42009-06-08 15:52:54 -0700994
Adam Cohended9f8d2010-11-03 13:25:16 -0700995 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
996 @Override
997 public void onReceive(Context context, Intent intent) {
998 final String action = intent.getAction();
999 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1000 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001001 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001002 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001003
Winson Chungc100e8e2011-08-09 16:02:43 -07001004 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001005 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001006 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1007 mAppsCustomizeTabHost.reset();
1008 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001009 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001010 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1011 mUserPresent = true;
1012 updateRunning();
1013 }
1014 }
1015 };
1016
1017 @Override
1018 public void onAttachedToWindow() {
1019 super.onAttachedToWindow();
1020
1021 // Listen for broadcasts related to user-presence
1022 final IntentFilter filter = new IntentFilter();
1023 filter.addAction(Intent.ACTION_SCREEN_OFF);
1024 filter.addAction(Intent.ACTION_USER_PRESENT);
1025 registerReceiver(mReceiver, filter);
1026
Adam Cohend113e0c2010-11-11 10:48:05 -08001027 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001028 mVisible = true;
1029 }
1030
1031 @Override
1032 public void onDetachedFromWindow() {
1033 super.onDetachedFromWindow();
1034 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001035 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001036
Adam Cohend113e0c2010-11-11 10:48:05 -08001037 if (mAttached) {
1038 unregisterReceiver(mReceiver);
1039 mAttached = false;
1040 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001041 updateRunning();
1042 }
1043
1044 public void onWindowVisibilityChanged(int visibility) {
1045 mVisible = visibility == View.VISIBLE;
1046 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001047 // The following code used to be in onResume, but it turns out onResume is called when
1048 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1049 // is a more appropriate event to handle
1050 if (mVisible) {
1051 mAppsCustomizeTabHost.onWindowVisible();
1052 if (!mWorkspaceLoading) {
1053 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
1054 final Workspace workspace = mWorkspace;
1055 // We want to let Launcher draw itself at least once before we force it to build
1056 // layers on all the workspace pages, so that transitioning to Launcher from other
1057 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1058 // a true draw so we wait until the second preDraw call to be safe
1059 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1060 boolean mFirstTime = true;
1061 public boolean onPreDraw() {
1062 if (mFirstTime) {
1063 mFirstTime = false;
1064 } else {
1065 //workspace.post(mBuildLayersRunnable);
1066 observer.removeOnPreDrawListener(this);
1067 }
1068 return true;
1069 }
1070 });
1071 }
1072 clearTypedText();
1073 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001074 }
1075
1076 private void sendAdvanceMessage(long delay) {
1077 mHandler.removeMessages(ADVANCE_MSG);
1078 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1079 mHandler.sendMessageDelayed(msg, delay);
1080 mAutoAdvanceSentTime = System.currentTimeMillis();
1081 }
1082
1083 private void updateRunning() {
1084 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1085 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1086 mAutoAdvanceRunning = autoAdvanceRunning;
1087 if (autoAdvanceRunning) {
1088 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1089 sendAdvanceMessage(delay);
1090 } else {
1091 if (!mWidgetsToAdvance.isEmpty()) {
1092 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1093 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1094 }
1095 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001096 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001097 }
1098 }
1099 }
1100
1101 private final Handler mHandler = new Handler() {
1102 @Override
1103 public void handleMessage(Message msg) {
1104 if (msg.what == ADVANCE_MSG) {
1105 int i = 0;
1106 for (View key: mWidgetsToAdvance.keySet()) {
1107 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1108 final int delay = mAdvanceStagger * i;
1109 if (v instanceof Advanceable) {
1110 postDelayed(new Runnable() {
1111 public void run() {
1112 ((Advanceable) v).advance();
1113 }
1114 }, delay);
1115 }
1116 i++;
1117 }
1118 sendAdvanceMessage(mAdvanceInterval);
1119 }
1120 }
1121 };
1122
1123 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001124 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001125 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1126 if (v instanceof Advanceable) {
1127 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001128 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001129 updateRunning();
1130 }
1131 }
1132
1133 void removeWidgetToAutoAdvance(View hostView) {
1134 if (mWidgetsToAdvance.containsKey(hostView)) {
1135 mWidgetsToAdvance.remove(hostView);
1136 updateRunning();
1137 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001138 }
1139
Joe Onorato9c1289c2009-08-17 11:03:03 -04001140 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001141 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001142 launcherInfo.hostView = null;
1143 }
1144
Adam Cohended9f8d2010-11-03 13:25:16 -07001145 void showOutOfSpaceMessage() {
1146 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1147 }
1148
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001149 public LauncherAppWidgetHost getAppWidgetHost() {
1150 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001151 }
Romain Guycbb89e42009-06-08 15:52:54 -07001152
Winson Chunga9abd0e2010-10-27 17:18:37 -07001153 public LauncherModel getModel() {
1154 return mModel;
1155 }
1156
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001157 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001158 getWindow().closeAllPanels();
1159
Winson Chung87acb482011-08-23 17:28:05 -07001160 /**
1161 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001162 try {
1163 dismissDialog(DIALOG_CREATE_SHORTCUT);
1164 // Unlock the workspace if the dialog was showing
1165 } catch (Exception e) {
1166 // An exception is thrown if the dialog is not visible, which is fine
1167 }
1168
1169 try {
1170 dismissDialog(DIALOG_RENAME_FOLDER);
1171 // Unlock the workspace if the dialog was showing
1172 } catch (Exception e) {
1173 // An exception is thrown if the dialog is not visible, which is fine
1174 }
Winson Chung87acb482011-08-23 17:28:05 -07001175 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001176
1177 // Whatever we were doing is hereby canceled.
1178 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001179 }
1180
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181 @Override
1182 protected void onNewIntent(Intent intent) {
1183 super.onNewIntent(intent);
1184
1185 // Close the menu
1186 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001187 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001188 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001189
Joe Onorato14f122b2009-11-19 14:06:36 -08001190 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1191 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001192
Adam Cohenac56cff2011-09-28 20:45:37 -07001193 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001194 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001195 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001196 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1197 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001198 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001199 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001200
1201 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001202 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001203 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001204
Joe Onorato3a8820b2009-11-10 15:06:42 -08001205 final View v = getWindow().peekDecorView();
1206 if (v != null && v.getWindowToken() != null) {
1207 InputMethodManager imm = (InputMethodManager)getSystemService(
1208 INPUT_METHOD_SERVICE);
1209 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001211
Michael Jurka35aa14d2011-07-07 17:01:08 -07001212 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001213 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001214 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001215 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 }
1217 }
1218
1219 @Override
1220 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1221 // Do not call super here
1222 mSavedInstanceState = savedInstanceState;
1223 }
1224
1225 @Override
1226 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001227 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001228 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229
Michael Jurka883f55b2010-10-21 15:47:14 -07001230 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001231 // We close any open folder since it will not be re-opened, and we need to make sure
1232 // this state is reflected.
1233 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
Winson Chung3d503fb2011-07-13 17:25:49 -07001235 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1236 mWaitingForResult) {
1237 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1238 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1239 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1240 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 }
1242
1243 if (mFolderInfo != null && mWaitingForResult) {
1244 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1245 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1246 }
Michael Jurka946ad472010-07-09 18:05:18 -07001247
Winson Chung785d2eb2011-04-14 16:08:02 -07001248 // Save the current AppsCustomize tab
1249 if (mAppsCustomizeTabHost != null) {
1250 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1251 if (currentTabTag != null) {
1252 outState.putString("apps_customize_currentTab", currentTabTag);
1253 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001254 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1255 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001256 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 }
1258
1259 @Override
1260 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001262
Winson Chunge7a03942011-08-05 15:05:12 -07001263 // Remove all pending runnables
1264 mHandler.removeMessages(ADVANCE_MSG);
1265 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001266 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001267
Winson Chungcd2b0142011-06-08 16:02:26 -07001268 // Stop callbacks from LauncherModel
1269 LauncherApplication app = ((LauncherApplication) getApplication());
1270 mModel.stopLoader();
1271 app.setLauncher(null);
1272
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001274 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001275 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001276 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001278 mAppWidgetHost = null;
1279
1280 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281
1282 TextKeyListener.getInstance().release();
1283
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284
Winson Chung3d503fb2011-07-13 17:25:49 -07001285 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001286
1287 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001288 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001289
1290 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1291 mWorkspace.removeAllViews();
1292 mWorkspace = null;
1293 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001294
1295 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 }
1297
Adam Cohena9cf38f2011-05-02 15:36:58 -07001298 public DragController getDragController() {
1299 return mDragController;
1300 }
1301
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 @Override
1303 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001304 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 super.startActivityForResult(intent, requestCode);
1306 }
1307
Winson Chung70d72102011-08-12 11:24:35 -07001308 /**
1309 * Indicates that we want global search for this activity by setting the globalSearch
1310 * argument for {@link #startSearch} to true.
1311 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001313 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001315
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001316 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001317
Karl Rosaen138a0412009-04-23 19:00:21 -07001318 if (initialQuery == null) {
1319 // Use any text typed in the launcher as the initial query
1320 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001321 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 if (appSearchData == null) {
1323 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001324 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001326 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001327
Karl Rosaen138a0412009-04-23 19:00:21 -07001328 final SearchManager searchManager =
1329 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001330 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001331 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 }
1333
Winson Chung70d72102011-08-12 11:24:35 -07001334 @Override
1335 public boolean onCreateOptionsMenu(Menu menu) {
1336 if (isWorkspaceLocked()) {
1337 return false;
1338 }
1339
1340 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001341
1342 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1343 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1344 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001345 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1346 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1347 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001348 String helpUrl = getString(R.string.help_url);
1349 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001350 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1351 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1352
Winson Chung70d72102011-08-12 11:24:35 -07001353 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1354 .setIcon(android.R.drawable.ic_menu_gallery)
1355 .setAlphabeticShortcut('W');
1356 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1357 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001358 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001359 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001360 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1361 .setIcon(android.R.drawable.ic_menu_preferences)
1362 .setIntent(settings)
1363 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001364 if (!helpUrl.isEmpty()) {
1365 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1366 .setIcon(android.R.drawable.ic_menu_help)
1367 .setIntent(help)
1368 .setAlphabeticShortcut('H');
1369 }
Winson Chung70d72102011-08-12 11:24:35 -07001370 return true;
1371 }
1372
1373 @Override
1374 public boolean onPrepareOptionsMenu(Menu menu) {
1375 super.onPrepareOptionsMenu(menu);
1376
1377 if (mAppsCustomizeTabHost.isTransitioning()) {
1378 return false;
1379 }
1380 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1381 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1382
1383 return true;
1384 }
1385
1386 @Override
1387 public boolean onOptionsItemSelected(MenuItem item) {
1388 switch (item.getItemId()) {
1389 case MENU_WALLPAPER_SETTINGS:
1390 startWallpaper();
1391 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001392 }
1393
1394 return super.onOptionsItemSelected(item);
1395 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001397 @Override
1398 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001399 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001400 // Use a custom animation for launching search
1401 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001402 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001403 }
1404
Joe Onorato9c1289c2009-08-17 11:03:03 -04001405 public boolean isWorkspaceLocked() {
1406 return mWorkspaceLoading || mWaitingForResult;
1407 }
1408
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001410 mPendingAddInfo.container = ItemInfo.NO_ID;
1411 mPendingAddInfo.screen = -1;
1412 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1413 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1414 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001415 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001416
Michael Jurkaaf442092010-06-10 17:01:57 -07001417 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001418 // TODO: catch bad widget exception when sent
1419 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001420 // TODO: Is this log message meaningful?
1421 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001422 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001423 }
1424
Winson Chung55cef262010-10-28 14:14:18 -07001425 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001426 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427
Bjorn Bringert7984c942009-12-09 15:38:25 +00001428 if (appWidget.configure != null) {
1429 // Launch over to configure widget, if needed
1430 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1431 intent.setComponent(appWidget.configure);
1432 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001433 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001434 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1435 intent.putExtra(
1436 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1437 info.mimeType);
1438
1439 final String mimeType = info.mimeType;
1440 final ClipData clipData = (ClipData) info.configurationData;
1441 final ClipDescription clipDesc = clipData.getDescription();
1442 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1443 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001444 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001445 final CharSequence stringData = item.getText();
1446 final Uri uriData = item.getUri();
1447 final Intent intentData = item.getIntent();
1448 final String key =
1449 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1450 if (uriData != null) {
1451 intent.putExtra(key, uriData);
1452 } else if (intentData != null) {
1453 intent.putExtra(key, intentData);
1454 } else if (stringData != null) {
1455 intent.putExtra(key, stringData);
1456 }
1457 break;
1458 }
1459 }
1460 }
Winson Chung55cef262010-10-28 14:14:18 -07001461 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001462
Romain Guy8e633c52010-03-04 12:51:36 -08001463 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001465 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001466 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001467
1468 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001469 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 }
1471 }
Romain Guycbb89e42009-06-08 15:52:54 -07001472
Adam Cohenfbba09b2011-07-18 21:43:05 -07001473 /**
1474 * Process a shortcut drop.
1475 *
1476 * @param componentName The name of the component
1477 * @param screen The screen where it should be added
1478 * @param cell The cell it should be added to, optional
1479 * @param position The location on the screen where it was dropped, optional
1480 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1482 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001483 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001484 mPendingAddInfo.container = container;
1485 mPendingAddInfo.screen = screen;
1486 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001487
1488 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001489 mPendingAddInfo.cellX = cell[0];
1490 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001491 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001492
1493 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1494 createShortcutIntent.setComponent(componentName);
1495 processShortcut(createShortcutIntent);
1496 }
1497
Adam Cohenfbba09b2011-07-18 21:43:05 -07001498 /**
1499 * Process a widget drop.
1500 *
1501 * @param info The PendingAppWidgetInfo of the widget being added.
1502 * @param screen The screen where it should be added
1503 * @param cell The cell it should be added to, optional
1504 * @param position The location on the screen where it was dropped, optional
1505 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001506 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1507 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001508 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001509 mPendingAddInfo.container = info.container = container;
1510 mPendingAddInfo.screen = info.screen = screen;
1511 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001512 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001513 mPendingAddInfo.cellX = cell[0];
1514 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001515 }
1516
1517 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1518 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1519 addAppWidgetImpl(appWidgetId, info);
1520 }
1521
Joe Onoratodeb98af2010-02-19 14:59:39 -08001522 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001523 // Handle case where user selected "Applications"
1524 String applicationName = getResources().getString(R.string.group_applications);
1525 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001526
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001527 if (applicationName != null && applicationName.equals(shortcutName)) {
1528 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1529 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001530
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001531 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1532 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001533 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001534 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001535 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001536 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001537 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 }
1539
Winson Chung24ab2f12010-09-16 14:10:47 -07001540 void processWallpaper(Intent intent) {
1541 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1542 }
1543
Winson Chung3d503fb2011-07-13 17:25:49 -07001544 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1545 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001546 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 folderInfo.title = getText(R.string.folder_name);
1548
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001550 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1551 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001552 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553
1554 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001555 FolderIcon newFolder =
1556 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1557 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1558 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001559 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 }
Romain Guycbb89e42009-06-08 15:52:54 -07001561
Joe Onorato9c1289c2009-08-17 11:03:03 -04001562 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001563 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001564 }
1565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001567 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001569 Intent chooser = Intent.createChooser(pickWallpaper,
1570 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001571 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1572 // Removed in Eclair MR1
1573// WallpaperManager wm = (WallpaperManager)
1574// getSystemService(Context.WALLPAPER_SERVICE);
1575// WallpaperInfo wi = wm.getWallpaperInfo();
1576// if (wi != null && wi.getSettingsActivity() != null) {
1577// LabeledIntent li = new LabeledIntent(getPackageName(),
1578// R.string.configure_wallpaper, 0);
1579// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1580// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1581// }
Mike Clerona0618e42009-10-22 13:55:21 -07001582 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001583 }
1584
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001585 /**
1586 * Registers various content observers. The current implementation registers
1587 * only a favorites observer to keep track of the favorites applications.
1588 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001589 private void registerContentObservers() {
1590 ContentResolver resolver = getContentResolver();
1591 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1592 true, mWidgetObserver);
1593 }
1594
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 @Override
1596 public boolean dispatchKeyEvent(KeyEvent event) {
1597 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1598 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001600 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001601 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001602 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001603 dumpState();
1604 return true;
1605 }
1606 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001607 }
1608 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1609 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001610 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 return true;
1612 }
1613 }
1614
1615 return super.dispatchKeyEvent(event);
1616 }
1617
Joe Onorato88ec0992009-11-19 13:16:06 -08001618 @Override
1619 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001620 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001621 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001622 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001623 Folder openFolder = mWorkspace.getOpenFolder();
1624 if (openFolder.isEditingName()) {
1625 openFolder.dismissEditingName();
1626 } else {
1627 closeFolder();
1628 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001629 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001630 mWorkspace.exitWidgetResizeMode();
1631
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001632 // Back button is a no-op here, but give at least some feedback for the button press
1633 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001634 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001635 }
1636
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001637 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001638 * Re-listen when widgets are reset.
1639 */
1640 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001641 if (mAppWidgetHost != null) {
1642 mAppWidgetHost.startListening();
1643 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001644 }
1645
1646 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001647 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1648 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001650 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001651 if (mModel != null) {
1652 mModel.unbindWorkspaceItems();
1653 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001654 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001655
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001656 /**
1657 * Launches the intent referred by the clicked shortcut.
1658 *
1659 * @param v The view representing the clicked shortcut.
1660 */
1661 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001662 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1663 // view has detached (it's possible for this to happen if the view is removed mid touch).
1664 if (v.getWindowToken() == null) {
1665 return;
1666 }
1667
1668 if (mWorkspace.isSwitchingState()) {
1669 return;
1670 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001671
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001672 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001673 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001675 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001676 int[] pos = new int[2];
1677 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001678 intent.setSourceBounds(new Rect(pos[0], pos[1],
1679 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001680 boolean success = startActivitySafely(intent, tag);
1681
1682 if (success && v instanceof BubbleTextView) {
1683 mWaitingForResume = (BubbleTextView) v;
1684 mWaitingForResume.setStayPressed(true);
1685 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001686 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001687 if (v instanceof FolderIcon) {
1688 FolderIcon fi = (FolderIcon) v;
1689 handleFolderClick(fi);
1690 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001691 } else if (v == mAllAppsButton) {
1692 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001693 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001694 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001695 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001696 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 }
1698 }
1699
Michael Jurka0e260592010-06-30 17:07:39 -07001700 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001701 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001702 // clicking anywhere on the workspace causes the customization drawer to slide down
1703 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001704 return false;
1705 }
1706
Michael Jurkaaf442092010-06-10 17:01:57 -07001707 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001708 * Event handler for the search button
1709 *
1710 * @param v The view that was clicked.
1711 */
1712 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001713 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1714
Amith Yamasania135ba82011-08-09 17:42:01 -07001715 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001716 }
1717
1718 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001719 * Event handler for the voice button
1720 *
1721 * @param v The view that was clicked.
1722 */
1723 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001724 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001725
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001726 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001727 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001728 startActivity(intent);
1729 }
1730
1731 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001732 * Event handler for the "grid" button that appears on the home screen, which
1733 * enters all apps mode.
1734 *
1735 * @param v The view that was clicked.
1736 */
1737 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001738 showAllApps(true);
1739 }
1740
1741 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001742 // Provide the same haptic feedback that the system offers for virtual keys.
1743 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001744 }
1745
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001746 public void onClickAppMarketButton(View v) {
1747 if (mAppMarketIntent != null) {
1748 startActivitySafely(mAppMarketIntent, "app market");
1749 }
1750 }
1751
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001752 void startApplicationDetailsActivity(ComponentName componentName) {
1753 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001754 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1755 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001756 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001757 startActivity(intent);
1758 }
1759
Patrick Dubroy5539af72010-09-07 15:22:01 -07001760 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1761 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1762 // System applications cannot be installed. For now, show a toast explaining that.
1763 // We may give them the option of disabling apps this way.
1764 int messageId = R.string.uninstall_system_app_text;
1765 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1766 } else {
1767 String packageName = appInfo.componentName.getPackageName();
1768 String className = appInfo.componentName.getClassName();
1769 Intent intent = new Intent(
1770 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001771 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1772 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001773 startActivity(intent);
1774 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001775 }
1776
Michael Jurkaddd62e92011-02-16 17:49:14 -08001777 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1779 try {
1780 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001781 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 } catch (ActivityNotFoundException e) {
1783 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001784 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 } catch (SecurityException e) {
1786 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001787 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001789 "or use the exported attribute for this activity. "
1790 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001792 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001794
Romain Guy8e633c52010-03-04 12:51:36 -08001795 void startActivityForResultSafely(Intent intent, int requestCode) {
1796 try {
1797 startActivityForResult(intent, requestCode);
1798 } catch (ActivityNotFoundException e) {
1799 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1800 } catch (SecurityException e) {
1801 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1802 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1803 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1804 "or use the exported attribute for this activity.", e);
1805 }
1806 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807
Adam Cohena9cf38f2011-05-02 15:36:58 -07001808 private void handleFolderClick(FolderIcon folderIcon) {
1809 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001810 Folder openFolder = mWorkspace.getFolderForTag(info);
1811
1812 // If the folder info reports that the associated folder is open, then verify that
1813 // it is actually opened. There have been a few instances where this gets out of sync.
1814 if (info.opened && openFolder == null) {
1815 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1816 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1817 info.opened = false;
1818 }
1819
Adam Cohena9cf38f2011-05-02 15:36:58 -07001820 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 // Close any open folder
1822 closeFolder();
1823 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001824 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 } else {
1826 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 int folderScreen;
1828 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001829 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 // .. and close it
1831 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001832 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 // Close any folder open on the current screen
1834 closeFolder();
1835 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001836 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 }
1838 }
1839 }
1840 }
1841
Adam Cohen2801caf2011-05-13 20:57:39 -07001842 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001843 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001844 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1845 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1846 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1847
Adam Cohenc51934b2011-07-26 21:07:43 -07001848 FolderInfo info = (FolderInfo) fi.getTag();
1849 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1850 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001851 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1852 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001853 }
1854
Adam Cohen2801caf2011-05-13 20:57:39 -07001855 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1856 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1857 oa.start();
1858 }
1859
1860 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001861 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001862 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1863 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1864 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1865
Adam Cohenc51934b2011-07-26 21:07:43 -07001866 FolderInfo info = (FolderInfo) fi.getTag();
1867 CellLayout cl = null;
1868 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1869 cl = (CellLayout) fi.getParent().getParent();
1870 }
1871
1872 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001873 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1874 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001875 oa.addListener(new AnimatorListenerAdapter() {
1876 @Override
1877 public void onAnimationEnd(Animator animation) {
1878 if (layout != null) {
1879 layout.clearFolderLeaveBehind();
1880 }
1881 }
1882 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001883 oa.start();
1884 }
1885
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001887 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 * is animated relative to the specified View. If the View is null, no animation
1889 * is played.
1890 *
1891 * @param folderInfo The FolderInfo describing the folder to open.
1892 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001893 public void openFolder(FolderIcon folderIcon) {
1894 Folder folder = folderIcon.mFolder;
1895 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001896
Adam Cohen2801caf2011-05-13 20:57:39 -07001897 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001898 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899
Adam Cohen4554ee12011-08-03 16:13:21 -07001900 // Just verify that the folder hasn't already been added to the DragLayer.
1901 // There was a one-off crash where the folder had a parent already.
1902 if (folder.getParent() == null) {
1903 mDragLayer.addView(folder);
1904 mDragController.addDropTarget((DropTarget) folder);
1905 } else {
1906 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1907 folder.getParent() + ").");
1908 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001909 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001910 }
1911
1912 public void closeFolder() {
1913 Folder folder = mWorkspace.getOpenFolder();
1914 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001915 if (folder.isEditingName()) {
1916 folder.dismissEditingName();
1917 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001918 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001919
1920 // Dismiss the folder cling
1921 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001922 }
1923 }
1924
1925 void closeFolder(Folder folder) {
1926 folder.getInfo().opened = false;
1927
1928 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1929 if (parent != null) {
1930 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1931 shrinkAndFadeInFolderIcon(fi);
1932 }
1933 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 }
1935
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001937 if (mState != State.WORKSPACE) {
1938 return false;
1939 }
1940
Joe Onorato9c1289c2009-08-17 11:03:03 -04001941 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 return false;
1943 }
1944
1945 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001946 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 }
1948
Michael Jurka0280c3b2010-09-17 15:00:07 -07001949 resetAddInfo();
1950 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001952 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 return true;
1954 }
1955
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 // The hotseat touch handling does not go through Workspace, and we always allow long press
1957 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001958 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1960 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001961 if (itemUnderLongClick == null) {
1962 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001963 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1964 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001965 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001967 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001968 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001969 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001970 }
1971 }
1972 }
1973 return true;
1974 }
1975
Winson Chung3d503fb2011-07-13 17:25:49 -07001976 boolean isHotseatLayout(View layout) {
1977 return mHotseat != null && layout != null &&
1978 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1979 }
1980 Hotseat getHotseat() {
1981 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001982 }
Adam Cohenebea84d2011-11-09 17:20:41 -08001983 SearchDropTargetBar getSearchBar() {
1984 return mSearchDropTargetBar;
1985 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001986
Winson Chung3d503fb2011-07-13 17:25:49 -07001987 /**
1988 * Returns the CellLayout of the specified container at the specified screen.
1989 */
1990 CellLayout getCellLayout(long container, int screen) {
1991 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1992 if (mHotseat != null) {
1993 return mHotseat.getLayout();
1994 } else {
1995 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08001996 }
Winson Chung3d503fb2011-07-13 17:25:49 -07001997 } else {
1998 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08001999 }
2000 }
2001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 Workspace getWorkspace() {
2003 return mWorkspace;
2004 }
2005
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 @Override
2007 protected Dialog onCreateDialog(int id) {
2008 switch (id) {
2009 case DIALOG_CREATE_SHORTCUT:
2010 return new CreateShortcut().createDialog();
2011 case DIALOG_RENAME_FOLDER:
2012 return new RenameFolder().createDialog();
2013 }
2014
2015 return super.onCreateDialog(id);
2016 }
2017
2018 @Override
2019 protected void onPrepareDialog(int id, Dialog dialog) {
2020 switch (id) {
2021 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 break;
2023 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002024 if (mFolderInfo != null) {
2025 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2026 final CharSequence text = mFolderInfo.title;
2027 input.setText(text);
2028 input.setSelection(0, text.length());
2029 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 break;
2031 }
2032 }
2033
2034 void showRenameDialog(FolderInfo info) {
2035 mFolderInfo = info;
2036 mWaitingForResult = true;
2037 showDialog(DIALOG_RENAME_FOLDER);
2038 }
2039
Adam Cohenfbba09b2011-07-18 21:43:05 -07002040 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002041 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002042 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2043 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 mWaitingForResult = true;
2045 showDialog(DIALOG_CREATE_SHORTCUT);
2046 }
2047
2048 private class RenameFolder {
2049 private EditText mInput;
2050
2051 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2053 mInput = (EditText) layout.findViewById(R.id.folder_name);
2054
2055 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2056 builder.setIcon(0);
2057 builder.setTitle(getString(R.string.rename_folder_title));
2058 builder.setCancelable(true);
2059 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2060 public void onCancel(DialogInterface dialog) {
2061 cleanup();
2062 }
2063 });
2064 builder.setNegativeButton(getString(R.string.cancel_action),
2065 new Dialog.OnClickListener() {
2066 public void onClick(DialogInterface dialog, int which) {
2067 cleanup();
2068 }
2069 }
2070 );
2071 builder.setPositiveButton(getString(R.string.rename_action),
2072 new Dialog.OnClickListener() {
2073 public void onClick(DialogInterface dialog, int which) {
2074 changeFolderName();
2075 }
2076 }
2077 );
2078 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002079
2080 final AlertDialog dialog = builder.create();
2081 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2082 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002083 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002084 mInput.requestFocus();
2085 InputMethodManager inputManager = (InputMethodManager)
2086 getSystemService(Context.INPUT_METHOD_SERVICE);
2087 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002088 }
2089 });
2090
2091 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002092 }
2093
2094 private void changeFolderName() {
2095 final String name = mInput.getText().toString();
2096 if (!TextUtils.isEmpty(name)) {
2097 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002098 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 mFolderInfo.title = name;
2100 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2101
Joe Onorato9c1289c2009-08-17 11:03:03 -04002102 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002103 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002104 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 } else {
2106 final FolderIcon folderIcon = (FolderIcon)
2107 mWorkspace.getViewForTag(mFolderInfo);
2108 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002109 // TODO: At some point we'll probably want some version of setting
2110 // the text for a folder icon.
2111 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 getWorkspace().requestLayout();
2113 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002114 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002115 mWorkspaceLoading = true;
2116 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 }
2118 }
2119 }
2120 cleanup();
2121 }
2122
2123 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 dismissDialog(DIALOG_RENAME_FOLDER);
2125 mWaitingForResult = false;
2126 mFolderInfo = null;
2127 }
2128 }
2129
Daniel Sandler843e8602010-06-07 14:59:01 -04002130 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2131 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002132 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002133 }
2134
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002135 // AllAppsView.Watcher
2136 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002137 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002138 mWorkspace.setVisibility(View.GONE);
2139 }
2140 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002141
2142 /**
2143 * Helper method for the cameraZoomIn/cameraZoomOut animations
2144 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002145 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002146 * @param scaleFactor The scale factor used for the zoom
2147 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002148 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002149 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002150 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002151 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002152
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002153 void updateWallpaperVisibility(boolean visible) {
2154 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2155 int curflags = getWindow().getAttributes().flags
2156 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2157 if (wpflags != curflags) {
2158 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2159 }
2160 }
2161
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002162 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002163 * Things to test when changing the following seven functions.
2164 * - Home from workspace
2165 * - from center screen
2166 * - from other screens
2167 * - Home from all apps
2168 * - from center screen
2169 * - from other screens
2170 * - Back from all apps
2171 * - from center screen
2172 * - from other screens
2173 * - Launch app from workspace and quit
2174 * - with back
2175 * - with home
2176 * - Launch app from all apps and quit
2177 * - with back
2178 * - with home
2179 * - Go to a screen that's not the default, then all
2180 * apps, and launch and app, and go back
2181 * - with back
2182 * -with home
2183 * - On workspace, long press power and go back
2184 * - with back
2185 * - with home
2186 * - On all apps, long press power and go back
2187 * - with back
2188 * - with home
2189 * - On workspace, power off
2190 * - On all apps, power off
2191 * - Launch an app and turn off the screen while in that app
2192 * - Go back with home key
2193 * - Go back with back key TODO: make this not go to workspace
2194 * - From all apps
2195 * - From workspace
2196 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2197 * - From all apps
2198 * - From the center workspace
2199 * - From another workspace
2200 */
2201
2202 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002203 * Zoom the camera out from the workspace to reveal 'toView'.
2204 * Assumes that the view to show is anchored at either the very top or very bottom
2205 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002206 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002207 private void showAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
2208 if (mStateAnimation != null) {
2209 mStateAnimation.cancel();
2210 mStateAnimation = null;
2211 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002212 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002213 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002214
Winson Chungf0ea4d32011-06-06 14:27:16 -07002215 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2216 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2217 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2218 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002219 final int startDelay =
2220 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002221
Michael Jurkab3e22d92011-10-31 15:58:33 -07002222 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002223
Michael Jurkad74c9842011-07-10 12:44:21 -07002224 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002225 Animator workspaceAnim =
2226 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002227
2228 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002229 toView.setScaleX(scale);
2230 toView.setScaleY(scale);
2231 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2232 scaleAnim.
2233 scaleX(1f).scaleY(1f).
2234 setDuration(duration).
2235 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002236
Winson Chungf0ea4d32011-06-06 14:27:16 -07002237 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002238 toView.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002239 ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
2240 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
2241 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2242 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002243 toView.setAlpha(a * 0f + b * 1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002244 }
2245 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002246
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002247 // toView should appear right at the end of the workspace shrink
2248 // animation
2249 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002250 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002251 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002252
2253 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002254 boolean animationCancelled = false;
2255
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002256 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002257 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002258 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002259 // Prepare the position
2260 toView.setTranslationX(0.0f);
2261 toView.setTranslationY(0.0f);
2262 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002263 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002264 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002265 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002266 public void onAnimationEnd(Animator animation) {
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002267 // If we don't set the final scale values here, if this animation is cancelled
2268 // it will have the wrong scale value and subsequent cameraPan animations will
2269 // not fix that
2270 toView.setScaleX(1.0f);
2271 toView.setScaleY(1.0f);
Michael Jurkaabded662011-03-04 12:06:57 -08002272 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002273 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance,
2274 scaleAnim, false);
Michael Jurka2763be32011-02-24 11:19:57 -08002275 }
Winson Chung32174c82011-07-19 15:47:55 -07002276
2277 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2278 // Hide the workspace scrollbar
2279 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002280 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002281 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002282 if (!animationCancelled) {
2283 updateWallpaperVisibility(false);
2284 }
2285 }
2286
Adam Cohencff6af82011-09-13 14:51:53 -07002287 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002288 public void onAnimationCancel(Animator animation) {
2289 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002290 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002291 });
2292
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002293 if (workspaceAnim != null) {
2294 mStateAnimation.play(workspaceAnim);
2295 }
Michael Jurka1899a362011-11-03 13:50:45 -07002296
2297 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002298 LauncherTransitionable lt = (LauncherTransitionable) toView;
2299 final ViewTreeObserver observer;
2300
2301 lt.onLauncherTransitionStart(instance, mStateAnimation, false);
2302
2303 // If any of the objects being animated haven't been measured/laid out
2304 // yet, delay the animation until we get a layout pass
2305 if ((lt.getContent().getMeasuredWidth() == 0) ||
2306 (mWorkspace.getMeasuredWidth() == 0) ||
2307 (toView.getMeasuredWidth() == 0)) {
2308 observer = mWorkspace.getViewTreeObserver();
2309 delayAnim = true;
2310 } else {
2311 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002312 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002313
2314 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002315 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002316 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2317 public void onGlobalLayout() {
2318 mWorkspace.post(new Runnable() {
2319 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002320 // Check that mStateAnimation hasn't changed while
2321 // we waited for a layout pass
2322 if (mStateAnimation == stateAnimation) {
2323 // Need to update pivots for zoom if layout changed
2324 setPivotsForZoom(toView, scale);
2325 mStateAnimation.start();
2326 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002327 }
2328 });
2329 observer.removeGlobalOnLayoutListener(this);
2330 }
2331 };
2332 observer.addOnGlobalLayoutListener(delayedStart);
2333 } else {
2334 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002335 mStateAnimation.start();
2336 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002337 } else {
2338 toView.setTranslationX(0.0f);
2339 toView.setTranslationY(0.0f);
2340 toView.setScaleX(1.0f);
2341 toView.setScaleY(1.0f);
2342 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002343 toView.bringToFront();
Michael Jurkaabded662011-03-04 12:06:57 -08002344 if (toView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002345 ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, null, false);
2346 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002347
Winson Chungc07918d2011-07-01 15:35:26 -07002348 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2349 // Hide the workspace scrollbar
2350 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002351 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002352 }
Michael Jurkaabded662011-03-04 12:06:57 -08002353 }
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002354 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002355 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002356 }
2357
2358 /**
2359 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002360 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002361 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002362 */
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002363 private void hideAppsCustomizeHelper(
2364 State toState, boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002365 if (mStateAnimation != null) {
2366 mStateAnimation.cancel();
2367 mStateAnimation = null;
2368 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002369 Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002370 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002371
Winson Chungf0ea4d32011-06-06 14:27:16 -07002372 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
2373 final float scaleFactor = (float)
2374 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2375 final View fromView = mAppsCustomizeTabHost;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002376 Animator workspaceAnim = null;
2377
2378 if (toState == State.WORKSPACE) {
2379 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2380 workspaceAnim = mWorkspace.getChangeStateAnimation(
2381 Workspace.State.NORMAL, animated, stagger);
2382 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2383 workspaceAnim = mWorkspace.getChangeStateAnimation(
2384 Workspace.State.SPRING_LOADED, animated);
2385 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002386
Michael Jurkab3e22d92011-10-31 15:58:33 -07002387 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002388 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002389 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002390 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002391 final float oldScaleX = fromView.getScaleX();
2392 final float oldScaleY = fromView.getScaleY();
2393
2394 ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
2395 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002396 scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2397 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002398 fromView.setScaleX(a * oldScaleX + b * scaleFactor);
2399 fromView.setScaleY(a * oldScaleY + b * scaleFactor);
Michael Jurka742574b2011-02-02 23:51:01 -08002400 }
2401 });
Michael Jurkaabded662011-03-04 12:06:57 -08002402 final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
Winson Chung785d2eb2011-04-14 16:08:02 -07002403 alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
Adam Cohencff6af82011-09-13 14:51:53 -07002404 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurkac2e26a02011-03-24 15:20:26 -07002405 alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
2406 public void onAnimationUpdate(float a, float b) {
Adam Cohenc00f0b92011-12-06 19:45:06 -08002407 fromView.setAlpha(a * 1f + b * 0f);
Michael Jurka742574b2011-02-02 23:51:01 -08002408 }
2409 });
Michael Jurkaabded662011-03-04 12:06:57 -08002410 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002411 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim,
2412 true);
Michael Jurka2763be32011-02-24 11:19:57 -08002413 }
Michael Jurka8edd75c2010-12-17 20:15:06 -08002414 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002415 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002416 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002417 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002418 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002419 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002420 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance,
2421 alphaAnim, true);
Michael Jurka2763be32011-02-24 11:19:57 -08002422 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002423 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002424 }
2425 });
2426
Michael Jurkab3e22d92011-10-31 15:58:33 -07002427 mStateAnimation = new AnimatorSet();
Winson Chungf0ea4d32011-06-06 14:27:16 -07002428 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002429 if (workspaceAnim != null) {
2430 mStateAnimation.play(workspaceAnim);
2431 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002432 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002433 } else {
2434 fromView.setVisibility(View.GONE);
Michael Jurkaabded662011-03-04 12:06:57 -08002435 if (fromView instanceof LauncherTransitionable) {
Winson Chung7d7541e2011-09-16 20:14:36 -07002436 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, null, true);
2437 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, null, true);
Michael Jurkaabded662011-03-04 12:06:57 -08002438 }
Michael Jurkab737ee62011-11-15 15:57:22 -08002439 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002440 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002441 }
2442
Michael Jurkae326f182011-11-21 14:05:46 -08002443 @Override
2444 public void onTrimMemory(int level) {
2445 super.onTrimMemory(level);
2446 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2447 mAppsCustomizeTabHost.onTrimMemory();
2448 }
2449 }
2450
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002451 void showWorkspace(boolean animated) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002452 if (mState != State.WORKSPACE) {
2453 mWorkspace.setVisibility(View.VISIBLE);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002454 hideAppsCustomizeHelper(State.WORKSPACE, animated, false);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002455
2456 // Show the search bar and hotseat
2457 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002458 // We only need to animate in the dock divider if we're going from spring loaded mode
2459 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002460
2461 // Set focus to the AppsCustomize button
2462 if (mAllAppsButton != null) {
2463 mAllAppsButton.requestFocus();
2464 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002465 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002466
Michael Jurkab737ee62011-11-15 15:57:22 -08002467 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002468
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002469 // Change the state *after* we've called all the transition code
2470 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002471
Winson Chung5fb63472011-02-02 17:03:37 -08002472 // Resume the auto-advance of widgets
2473 mUserPresent = true;
2474 updateRunning();
2475
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002476 // send an accessibility event to announce the context change
2477 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002478 }
2479
Michael Jurkab3e22d92011-10-31 15:58:33 -07002480 void showAllApps(boolean animated) {
2481 if (mState != State.WORKSPACE) return;
2482
2483 showAppsCustomizeHelper(animated, false);
2484 mAppsCustomizeTabHost.requestFocus();
2485
2486 // Hide the search bar and hotseat
2487 mSearchDropTargetBar.hideSearchBar(animated);
2488
2489 // Change the state *after* we've called all the transition code
2490 mState = State.APPS_CUSTOMIZE;
2491
2492 // Pause the auto-advance of widgets until we are out of AllApps
2493 mUserPresent = false;
2494 updateRunning();
2495 closeFolder();
2496
2497 // Send an accessibility event to announce the context change
2498 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2499 }
2500
Adam Cohen7777d962011-08-18 18:58:38 -07002501 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002502 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002503 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002504 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002505 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002506 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002507 }
Adam Cohen7777d962011-08-18 18:58:38 -07002508
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002509 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chung09bfc452011-09-09 11:30:20 -07002510 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2511
Winson Chunge7a03942011-08-05 15:05:12 -07002512 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002513 @Override
2514 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002515 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002516 // Before we show workspace, hide all apps again because
2517 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2518 // clean up our state transition functions
2519 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002520 mSearchDropTargetBar.showSearchBar(true);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002521 showWorkspace(true);
Adam Cohen7777d962011-08-18 18:58:38 -07002522 } else {
2523 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002524 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002525 }
2526 }, (extendedDelay ?
2527 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2528 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2529 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002530
Michael Jurkad3ef3062010-11-23 16:23:58 -08002531 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002532 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002533 final boolean animated = true;
2534 final boolean springLoaded = true;
2535 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002536 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002537 }
2538 // Otherwise, we are not in spring loaded mode, so don't do anything.
2539 }
2540
Michael Jurkab737ee62011-11-15 15:57:22 -08002541 void hideDockDivider() {
2542 if (mQsbDivider != null && mDockDivider != null) {
2543 mQsbDivider.setVisibility(View.INVISIBLE);
2544 mDockDivider.setVisibility(View.INVISIBLE);
2545 }
2546 }
2547
2548 void showDockDivider(boolean animated) {
2549 if (mQsbDivider != null && mDockDivider != null) {
2550 mQsbDivider.setVisibility(View.VISIBLE);
2551 mDockDivider.setVisibility(View.VISIBLE);
2552 if (mDividerAnimator != null) {
2553 mDividerAnimator.cancel();
2554 mQsbDivider.setAlpha(1f);
2555 mDockDivider.setAlpha(1f);
2556 mDividerAnimator = null;
2557 }
2558 if (animated) {
2559 mDividerAnimator = new AnimatorSet();
2560 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2561 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2562 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2563 mDividerAnimator.start();
2564 }
2565 }
2566 }
2567
Michael Jurkab3e22d92011-10-31 15:58:33 -07002568 void lockAllApps() {
2569 // TODO
2570 }
2571
2572 void unlockAllApps() {
2573 // TODO
2574 }
2575
Adam Cohenfc53cd22011-07-20 15:45:11 -07002576 public boolean isAllAppsCustomizeOpen() {
2577 return mState == State.APPS_CUSTOMIZE;
2578 }
2579
Winson Chungf0ea4d32011-06-06 14:27:16 -07002580 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002581 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002582 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002583 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002584 if (!LauncherApplication.isScreenLarge()) {
2585 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002586 if (mHotseat.getAlpha() != 1f) {
2587 int duration = mSearchDropTargetBar.getTransitionInDuration();
2588 mHotseat.animate().alpha(1f).setDuration(duration);
2589 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002590 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002591 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002592 }
2593 }
2594 }
2595
2596 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002597 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002598 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002599 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002600 if (!LauncherApplication.isScreenLarge()) {
2601 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002602 if (mHotseat.getAlpha() != 0f) {
2603 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2604 mHotseat.animate().alpha(0f).setDuration(duration);
2605 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002606 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002607 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002608 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002609 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002610 }
2611
Patrick Dubroy5f445422011-02-18 14:35:21 -08002612 /**
2613 * Add an item from all apps or customize onto the given workspace screen.
2614 * If layout is null, add to the current screen.
2615 */
2616 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002617 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2618 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002619 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002620 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002621
Winson Chungdff8ebb2011-09-08 17:25:31 -07002622 /** Maps the current orientation to an index for referencing orientation correct global icons */
2623 private int getCurrentOrientationIndexForGlobalIcons() {
2624 // default - 0, landscape - 1
2625 switch (getResources().getConfiguration().orientation) {
2626 case Configuration.ORIENTATION_LANDSCAPE:
2627 return 1;
2628 default:
2629 return 0;
2630 }
2631 }
2632
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002633 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002634 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002635 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002636 // Look for the toolbar icon specified in the activity meta-data
2637 Bundle metaData = packageManager.getActivityInfo(
2638 activityName, PackageManager.GET_META_DATA).metaData;
2639 if (metaData != null) {
2640 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2641 if (iconResId != 0) {
2642 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002643 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002644 }
2645 }
2646 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002647 // This can happen if the activity defines an invalid drawable
2648 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2649 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002650 } catch (Resources.NotFoundException nfe) {
2651 // This can happen if the activity defines an invalid drawable
2652 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2653 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002654 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002655 return null;
2656 }
2657
2658 // if successful in getting icon, return it; otherwise, set button to use default drawable
2659 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2660 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002661 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002662 Resources r = getResources();
2663 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2664 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002665
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002666 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002667 // If we were unable to find the icon via the meta-data, use a generic one
2668 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002669 toolbarIcon = r.getDrawable(fallbackDrawableId);
2670 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002671 if (button != null) {
2672 button.setCompoundDrawables(toolbarIcon, null, null, null);
2673 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002674 return null;
2675 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002676 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002677 if (button != null) {
2678 button.setCompoundDrawables(toolbarIcon, null, null, null);
2679 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002680 return toolbarIcon.getConstantState();
2681 }
2682 }
2683
2684 // if successful in getting icon, return it; otherwise, set button to use default drawable
2685 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2686 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2687 ImageView button = (ImageView) findViewById(buttonId);
2688 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2689
Michael Jurka19e0fc52011-07-22 18:00:21 -07002690 if (button != null) {
2691 // If we were unable to find the icon via the meta-data, use a
2692 // generic one
2693 if (toolbarIcon == null) {
2694 button.setImageResource(fallbackDrawableId);
2695 } else {
2696 button.setImageDrawable(toolbarIcon);
2697 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002698 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002699
2700 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2701
Michael Jurka0423dcf2010-10-05 14:56:18 -07002702 }
2703
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002704 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2705 TextView button = (TextView) findViewById(buttonId);
2706 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2707 }
2708
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002709 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002710 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002711 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002712 }
2713
Winson Chungbb185bd2011-11-21 12:31:42 -08002714 private void invalidatePressedFocusedStates(View container, View button) {
2715 if (container instanceof HolographicLinearLayout) {
2716 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2717 layout.invalidatePressedFocusedStates();
2718 } else if (button instanceof HolographicImageView) {
2719 HolographicImageView view = (HolographicImageView) button;
2720 view.invalidatePressedFocusedStates();
2721 }
2722 }
2723
Winson Chungc51db6a2011-10-05 11:44:49 -07002724 private boolean updateGlobalSearchIcon() {
2725 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002726 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2727 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002728 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002729 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002730
Winson Chung1cad91e2011-05-25 17:41:01 -07002731 final SearchManager searchManager =
2732 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2733 ComponentName activityName = searchManager.getGlobalSearchActivity();
2734 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002735 int coi = getCurrentOrientationIndexForGlobalIcons();
2736 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002737 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002738 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002739 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2740 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002741 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002742 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002743 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002744 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002745 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002746 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2747 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2748 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002749 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002750 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002751 }
2752 }
2753
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002754 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002755 final View searchButtonContainer = findViewById(R.id.search_button_container);
2756 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002757 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002758 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002759 }
2760
Winson Chungc51db6a2011-10-05 11:44:49 -07002761 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002762 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002763 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002764 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002765
Winson Chungc51db6a2011-10-05 11:44:49 -07002766 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002767 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2768 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002769 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002770 int coi = getCurrentOrientationIndexForGlobalIcons();
2771 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002772 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002773 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002774 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002775 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002776 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002777 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002778 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002779 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002780 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002781 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002782 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002783 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002784 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002785
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002786 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002787 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2788 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002789 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002790 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002791 }
2792
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002793 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002794 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002795 */
2796 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002797 final View marketButton = findViewById(R.id.market_button);
2798 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2799 // Find the app market activity by resolving an intent.
2800 // (If multiple app markets are installed, it will return the ResolverActivity.)
2801 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002802 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002803 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002804 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002805 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002806 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002807 marketButton.setVisibility(View.VISIBLE);
2808 } else {
2809 // We should hide and disable the view so that we don't try and restore the visibility
2810 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2811 marketButton.setVisibility(View.GONE);
2812 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002813 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002814 }
2815
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002816 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002817 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002818 }
2819
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002820 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002821 * Displays the shortcut creation dialog and launches, if necessary, the
2822 * appropriate activity.
2823 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002824 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002825 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2826 DialogInterface.OnShowListener {
2827
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002828 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002829
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002830 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002831 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002832
Winson Chung55b65502011-05-26 12:03:43 -07002833 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2834 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002835 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002836
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002837 AlertDialog dialog = builder.create();
2838 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002839 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002840 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002841
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002842 return dialog;
2843 }
2844
2845 public void onCancel(DialogInterface dialog) {
2846 mWaitingForResult = false;
2847 cleanup();
2848 }
2849
Romain Guycbb89e42009-06-08 15:52:54 -07002850 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002851 mWaitingForResult = false;
2852 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002853 }
2854
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002855 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002856 try {
2857 dismissDialog(DIALOG_CREATE_SHORTCUT);
2858 } catch (Exception e) {
2859 // An exception is thrown if the dialog is not visible, which is fine
2860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002861 }
2862
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002863 /**
2864 * Handle the action clicked in the "Add to home" dialog.
2865 */
2866 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002867 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002868
Winson Chung55b65502011-05-26 12:03:43 -07002869 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2870 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002871 case AddAdapter.ITEM_APPLICATION: {
2872 if (mAppsCustomizeTabHost != null) {
2873 mAppsCustomizeTabHost.selectAppsTab();
2874 }
2875 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002876 break;
2877 }
Winson Chung55b65502011-05-26 12:03:43 -07002878 case AddAdapter.ITEM_APPWIDGET: {
2879 if (mAppsCustomizeTabHost != null) {
2880 mAppsCustomizeTabHost.selectWidgetsTab();
2881 }
2882 showAllApps(true);
2883 break;
2884 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002885 case AddAdapter.ITEM_WALLPAPER: {
2886 startWallpaper();
2887 break;
2888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002889 }
2890 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002891
2892 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002893 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002894 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002895 }
2896
2897 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002898 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002899 */
2900 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2901 @Override
2902 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002903 closeSystemDialogs();
2904 }
2905 }
2906
2907 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002908 * Receives notifications whenever the appwidgets are reset.
2909 */
2910 private class AppWidgetResetObserver extends ContentObserver {
2911 public AppWidgetResetObserver() {
2912 super(new Handler());
2913 }
2914
2915 @Override
2916 public void onChange(boolean selfChange) {
2917 onAppWidgetReset();
2918 }
2919 }
2920
2921 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002922 * If the activity is currently paused, signal that we need to re-run the loader
2923 * in onResume.
2924 *
2925 * This needs to be called from incoming places where resources might have been loaded
2926 * while we are paused. That is becaues the Configuration might be wrong
2927 * when we're not running, and if it comes back to what it was when we
2928 * were paused, we are not restarted.
2929 *
2930 * Implementation of the method from LauncherModel.Callbacks.
2931 *
2932 * @return true if we are currently paused. The caller might be able to
2933 * skip some work in that case since we will come back again.
2934 */
2935 public boolean setLoadOnResume() {
2936 if (mPaused) {
2937 Log.i(TAG, "setLoadOnResume");
2938 mOnResumeNeedsLoad = true;
2939 return true;
2940 } else {
2941 return false;
2942 }
2943 }
2944
2945 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002946 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002947 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002948 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002949 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002950 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002951 } else {
2952 return SCREEN_COUNT / 2;
2953 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002954 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002955
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002956
Joe Onorato9c1289c2009-08-17 11:03:03 -04002957 /**
2958 * Refreshes the shortcuts shown on the workspace.
2959 *
2960 * Implementation of the method from LauncherModel.Callbacks.
2961 */
2962 public void startBinding() {
2963 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002964
2965 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002966 int count = workspace.getChildCount();
2967 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002968 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002969 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2970 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002971 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08002972 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07002973 if (mHotseat != null) {
2974 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002975 }
2976 }
2977
2978 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002979 * Bind the items start-end from the list.
2980 *
2981 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002982 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002983 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002984 setLoadOnResume();
2985
Joe Onorato9c1289c2009-08-17 11:03:03 -04002986 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002987 for (int i=start; i<end; i++) {
2988 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002989
2990 // Short circuit if we are loading dock items for a configuration which has no dock
2991 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2992 mHotseat == null) {
2993 continue;
2994 }
2995
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 switch (item.itemType) {
2997 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2998 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07002999 View shortcut = createShortcut((ShortcutInfo)item);
3000 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3001 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003002 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003003 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003004 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003005 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003006 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003007 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3008 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003009 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003010 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003011 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003012 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003013 }
3014
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 /**
3016 * Implementation of the method from LauncherModel.Callbacks.
3017 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003018 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003019 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003020 sFolders.clear();
3021 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003022 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003023
3024 /**
3025 * Add the views for a widget to the workspace.
3026 *
3027 * Implementation of the method from LauncherModel.Callbacks.
3028 */
3029 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003030 setLoadOnResume();
3031
Daniel Sandler843e8602010-06-07 14:59:01 -04003032 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3033 if (DEBUG_WIDGETS) {
3034 Log.d(TAG, "bindAppWidget: " + item);
3035 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003036 final Workspace workspace = mWorkspace;
3037
3038 final int appWidgetId = item.appWidgetId;
3039 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003040 if (DEBUG_WIDGETS) {
3041 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3042 }
3043
Joe Onorato9c1289c2009-08-17 11:03:03 -04003044 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3045
Joe Onorato9c1289c2009-08-17 11:03:03 -04003046 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3047 item.hostView.setTag(item);
3048
Winson Chung3d503fb2011-07-13 17:25:49 -07003049 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003050 item.cellY, item.spanX, item.spanY, false);
3051
Adam Cohended9f8d2010-11-03 13:25:16 -07003052 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3053
Joe Onorato9c1289c2009-08-17 11:03:03 -04003054 workspace.requestLayout();
3055
Daniel Sandler843e8602010-06-07 14:59:01 -04003056 if (DEBUG_WIDGETS) {
3057 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3058 + (SystemClock.uptimeMillis()-start) + "ms");
3059 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003060 }
3061
3062 /**
3063 * Callback saying that there aren't any more items to bind.
3064 *
3065 * Implementation of the method from LauncherModel.Callbacks.
3066 */
3067 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003068 setLoadOnResume();
3069
Joe Onorato9c1289c2009-08-17 11:03:03 -04003070 if (mSavedState != null) {
3071 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003072 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003073 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003074 mSavedState = null;
3075 }
3076
3077 if (mSavedInstanceState != null) {
3078 super.onRestoreInstanceState(mSavedInstanceState);
3079 mSavedInstanceState = null;
3080 }
3081
Joe Onorato9c1289c2009-08-17 11:03:03 -04003082 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003083
3084 // If we received the result of any pending adds while the loader was running (e.g. the
3085 // widget configuration forced an orientation change), process them now.
3086 for (int i = 0; i < sPendingAddList.size(); i++) {
3087 completeAdd(sPendingAddList.get(i));
3088 }
3089 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003090
Winson Chungc51db6a2011-10-05 11:44:49 -07003091 // Update the market app icon as necessary (the other icons will be managed in response to
3092 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003093 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003094
3095 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003096 }
3097
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003098 @Override
3099 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003100 boolean searchVisible = updateGlobalSearchIcon();
3101 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3102 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003103 }
3104
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003105 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003106 * Add the icons for all apps.
3107 *
3108 * Implementation of the method from LauncherModel.Callbacks.
3109 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003110 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3111 // Remove the progress bar entirely; we could also make it GONE
3112 // but better to remove it since we know it's not going to be used
3113 View progressBar = mAppsCustomizeTabHost.
3114 findViewById(R.id.apps_customize_progress_bar);
3115 if (progressBar != null) {
3116 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003117 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003118 // We just post the call to setApps so the user sees the progress bar
3119 // disappear-- otherwise, it just looks like the progress bar froze
3120 // which doesn't look great
3121 mAppsCustomizeTabHost.post(new Runnable() {
3122 public void run() {
3123 if (mAppsCustomizeContent != null) {
3124 mAppsCustomizeContent.setApps(apps);
3125 }
3126 }
3127 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003128 }
3129
3130 /**
3131 * A package was installed.
3132 *
3133 * Implementation of the method from LauncherModel.Callbacks.
3134 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003135 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003136 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003137 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003138
Winson Chung785d2eb2011-04-14 16:08:02 -07003139 if (mAppsCustomizeContent != null) {
3140 mAppsCustomizeContent.addApps(apps);
3141 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003142 }
3143
3144 /**
3145 * A package was updated.
3146 *
3147 * Implementation of the method from LauncherModel.Callbacks.
3148 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003149 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003150 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003151 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003152 if (mWorkspace != null) {
3153 mWorkspace.updateShortcuts(apps);
3154 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003155
Winson Chung785d2eb2011-04-14 16:08:02 -07003156 if (mAppsCustomizeContent != null) {
3157 mAppsCustomizeContent.updateApps(apps);
3158 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003159 }
3160
3161 /**
3162 * A package was uninstalled.
3163 *
3164 * Implementation of the method from LauncherModel.Callbacks.
3165 */
Joe Onorato36115782010-06-17 13:28:48 -04003166 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003167 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003168 if (permanent) {
3169 mWorkspace.removeItems(apps);
3170 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003171
Winson Chung785d2eb2011-04-14 16:08:02 -07003172 if (mAppsCustomizeContent != null) {
3173 mAppsCustomizeContent.removeApps(apps);
3174 }
Winson Chunga1820962011-10-03 16:31:06 -07003175
3176 // Notify the drag controller
3177 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003178 }
Joe Onoratobe386092009-11-17 17:32:16 -08003179
3180 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003181 * A number of packages were updated.
3182 */
3183 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003184 if (mAppsCustomizeContent != null) {
3185 mAppsCustomizeContent.onPackagesUpdated();
3186 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003187 }
3188
Winson Chung400438b2011-01-16 17:53:48 -08003189 private int mapConfigurationOriActivityInfoOri(int configOri) {
3190 final Display d = getWindowManager().getDefaultDisplay();
3191 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3192 switch (d.getRotation()) {
3193 case Surface.ROTATION_0:
3194 case Surface.ROTATION_180:
3195 // We are currently in the same basic orientation as the natural orientation
3196 naturalOri = configOri;
3197 break;
3198 case Surface.ROTATION_90:
3199 case Surface.ROTATION_270:
3200 // We are currently in the other basic orientation to the natural orientation
3201 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3202 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3203 break;
3204 }
3205
3206 int[] oriMap = {
3207 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3208 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3209 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3210 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3211 };
3212 // Since the map starts at portrait, we need to offset if this device's natural orientation
3213 // is landscape.
3214 int indexOffset = 0;
3215 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3216 indexOffset = 1;
3217 }
3218 return oriMap[(d.getRotation() + indexOffset) % 4];
3219 }
Adam Cohen446e9402011-09-15 18:21:21 -07003220
3221 public void lockScreenOrientationOnLargeUI() {
3222 if (LauncherApplication.isScreenLarge()) {
3223 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3224 .getConfiguration().orientation));
3225 }
Winson Chung400438b2011-01-16 17:53:48 -08003226 }
Adam Cohen446e9402011-09-15 18:21:21 -07003227 public void unlockScreenOrientationOnLargeUI() {
3228 if (LauncherApplication.isScreenLarge()) {
3229 mHandler.postDelayed(new Runnable() {
3230 public void run() {
3231 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3232 }
3233 }, mRestoreScreenOrientationDelay);
3234 }
Winson Chung400438b2011-01-16 17:53:48 -08003235 }
3236
Winson Chung82f55532011-08-09 14:14:23 -07003237 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003238 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3239 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003240 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003241 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003242
Winson Chung7d7541e2011-09-16 20:14:36 -07003243 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003244 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003245 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3246 Cling cling = (Cling) findViewById(clingId);
3247 if (cling != null) {
3248 cling.init(this, positionData);
3249 cling.setVisibility(View.VISIBLE);
3250 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3251 if (animate) {
3252 cling.buildLayer();
3253 cling.setAlpha(0f);
3254 cling.animate()
3255 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003256 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003257 .setDuration(SHOW_CLING_DURATION)
3258 .setStartDelay(delay)
3259 .start();
3260 } else {
3261 cling.setAlpha(1f);
3262 }
3263 }
3264 return cling;
3265 }
3266 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003267 if (cling != null) {
3268 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003269 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003270 anim.addListener(new AnimatorListenerAdapter() {
3271 public void onAnimationEnd(Animator animation) {
3272 cling.setVisibility(View.GONE);
3273 cling.cleanup();
3274 SharedPreferences prefs =
3275 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3276 SharedPreferences.Editor editor = prefs.edit();
3277 editor.putBoolean(flag, true);
3278 editor.commit();
3279 };
3280 });
3281 anim.start();
3282 }
3283 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003284 private void removeCling(int id) {
3285 final View cling = findViewById(id);
3286 if (cling != null) {
3287 final ViewGroup parent = (ViewGroup) cling.getParent();
3288 parent.post(new Runnable() {
3289 @Override
3290 public void run() {
3291 parent.removeView(cling);
3292 }
3293 });
3294 }
3295 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003296 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003297 // Enable the clings only if they have not been dismissed before
3298 SharedPreferences prefs =
3299 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003300 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003301 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003302 } else {
3303 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003304 }
3305 }
3306 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003307 // Enable the clings only if they have not been dismissed before
3308 SharedPreferences prefs =
3309 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003310 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003311 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003312 } else {
3313 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003314 }
3315 }
3316 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003317 // Enable the clings only if they have not been dismissed before
3318 SharedPreferences prefs =
3319 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3320 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003321 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003322 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003323 } else {
3324 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003325 }
3326 return cling;
3327 }
3328 public boolean isFolderClingVisible() {
3329 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003330 if (cling != null) {
3331 return cling.getVisibility() == View.VISIBLE;
3332 }
3333 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003334 }
Winson Chung82f55532011-08-09 14:14:23 -07003335 public void dismissWorkspaceCling(View v) {
3336 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003337 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003338 }
3339 public void dismissAllAppsCling(View v) {
3340 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003341 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3342 }
3343 public void dismissFolderCling(View v) {
3344 Cling cling = (Cling) findViewById(R.id.folder_cling);
3345 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003346 }
3347
Winson Chung80baf5a2010-08-09 16:03:15 -07003348 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003349 * Prints out out state for debugging.
3350 */
3351 public void dumpState() {
3352 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003353 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003354 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3355 Log.d(TAG, "mRestoring=" + mRestoring);
3356 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3357 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003358 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003359 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003360
Winson Chung785d2eb2011-04-14 16:08:02 -07003361 if (mAppsCustomizeContent != null) {
3362 mAppsCustomizeContent.dumpState();
3363 }
Joe Onoratobe386092009-11-17 17:32:16 -08003364 Log.d(TAG, "END launcher2 dump state");
3365 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003366
3367 @Override
3368 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3369 super.dump(prefix, fd, writer, args);
3370 writer.println(" ");
3371 writer.println("Debug logs: ");
3372 for (int i = 0; i < sDumpLogs.size(); i++) {
3373 writer.println(" " + sDumpLogs.get(i));
3374 }
3375 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003376}
Michael Jurka2763be32011-02-24 11:19:57 -08003377
Michael Jurkaabded662011-03-04 12:06:57 -08003378interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003379 View getContent();
3380 void onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace);
Winson Chung7d7541e2011-09-16 20:14:36 -07003381 void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003382}