blob: 182f217ff5a9e1f04c34b878b894047d1b9e3c37 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
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;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700212 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
213 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700214 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700215
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800216 private final BroadcastReceiver mCloseSystemDialogsReceiver
217 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800218 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 private LayoutInflater mInflater;
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700223 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800224 private DragLayer mDragLayer;
225 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700226 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700227
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700228 private AppWidgetManager mAppWidgetManager;
229 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700230
Michael Jurkac9d95c52011-08-29 14:03:34 -0700231 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700232 private AppWidgetProviderInfo mPendingAddWidgetInfo;
233
Michael Jurka0280c3b2010-09-17 15:00:07 -0700234 private int[] mTmpAddItemCellCoordinates = new int[2];
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private FolderInfo mFolderInfo;
237
Winson Chung3d503fb2011-07-13 17:25:49 -0700238 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700239 private View mOverviewPanel;
240
Michael Jurka838a4ca2011-02-07 13:33:06 -0800241 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700242
Winson Chungc51db6a2011-10-05 11:44:49 -0700243 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700244 private AppsCustomizeTabHost mAppsCustomizeTabHost;
245 private AppsCustomizePagedView mAppsCustomizeContent;
246 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100247 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700250 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
251 // scroll issues (because the workspace may not have been measured yet) and extra work.
252 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
253 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
255 private SpannableStringBuilder mDefaultKeySsb = null;
256
Joe Onorato9c1289c2009-08-17 11:03:03 -0400257 private boolean mWorkspaceLoading = true;
258
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800259 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 private boolean mRestoring;
261 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700262 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
Michael Jurka1e2f4652013-07-08 18:03:46 -0700264 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700265 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
266
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // Keep track of whether the user has left launcher
268 private static boolean sPausedFromUserAction = false;
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private Bundle mSavedInstanceState;
271
Joe Onorato9c1289c2009-08-17 11:03:03 -0400272 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800273 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800274 private boolean mUserPresent = true;
275 private boolean mVisible = false;
276 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700277 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700278 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static LocaleConfiguration sLocaleConfiguration = null;
281
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700282 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700284 private Intent mAppMarketIntent = null;
285
Adam Cohended9f8d2010-11-03 13:25:16 -0700286 // Related to the auto-advancing of widgets
287 private final int ADVANCE_MSG = 1;
288 private final int mAdvanceInterval = 20000;
289 private final int mAdvanceStagger = 250;
290 private long mAutoAdvanceSentTime;
291 private long mAutoAdvanceTimeLeft = -1;
292 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
293 new HashMap<View, AppWidgetProviderInfo>();
294
Winson Chung400438b2011-01-16 17:53:48 -0800295 // Determines how long to wait after a rotation before restoring the screen orientation to
296 // match the sensor state.
297 private final int mRestoreScreenOrientationDelay = 500;
298
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700300 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
302 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
Craig Mautner360310b2012-10-26 15:13:08 -0700304 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700305
Adam Cohen1462de32012-07-24 22:34:36 -0700306 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
307
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700308 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700309 static Date sDateStamp = new Date();
310 static DateFormat sDateFormat =
311 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
312 static long sRunStart = System.currentTimeMillis();
313 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700314
Winson Chung46353de2012-02-16 14:05:10 -0800315 // We only want to get the SharedPreferences once since it does an FS stat each time we get
316 // it from the context.
317 private SharedPreferences mSharedPrefs;
318
Adam Cohene25af792013-06-06 23:08:25 -0700319 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
320
Winson Chungf0c6ae02012-03-21 16:10:31 -0700321 // Holds the page that we need to animate to, and the icon views that we need to animate up
322 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700323 private ImageView mFolderIconImageView;
324 private Bitmap mFolderIconBitmap;
325 private Canvas mFolderIconCanvas;
326 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700327
Michael Jurkaddd62e92011-02-16 17:49:14 -0800328 private BubbleTextView mWaitingForResume;
329
Michael Jurka22143132012-10-04 17:42:38 +0200330 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
331 = new HideFromAccessibilityHelper();
332
Michael Jurkac1f5d262011-09-30 19:32:27 -0700333 private Runnable mBuildLayersRunnable = new Runnable() {
334 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700335 if (mWorkspace != null) {
336 mWorkspace.buildPageHardwareLayers();
337 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700338 }
339 };
340
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800341 private static ArrayList<PendingAddArguments> sPendingAddList
342 = new ArrayList<PendingAddArguments>();
343
Michael Jurka0a457bf2012-11-19 14:05:05 -0800344 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
345
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800346 private static class PendingAddArguments {
347 int requestCode;
348 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700349 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700350 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800351 int cellX;
352 int cellY;
353 }
354
Daniel Sandlerff02d492013-08-05 02:12:05 -0400355 private Stats mStats;
356
Michael Jurka0a457bf2012-11-19 14:05:05 -0800357 private static boolean isPropertyEnabled(String propertyName) {
358 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700359 }
360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 @Override
362 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700363 if (DEBUG_STRICT_MODE) {
364 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
365 .detectDiskReads()
366 .detectDiskWrites()
367 .detectNetwork() // or .detectAll() for all detectable problems
368 .penaltyLog()
369 .build());
370 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
371 .detectLeakedSqlLiteObjects()
372 .detectLeakedClosableObjects()
373 .penaltyLog()
374 .penaltyDeath()
375 .build());
376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400379
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400381 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700382
383 // Determine the dynamic grid properties
384 Point smallestSize = new Point();
385 Point largestSize = new Point();
386 Point realSize = new Point();
387 Display display = getWindowManager().getDefaultDisplay();
388 display.getCurrentSizeRange(smallestSize, largestSize);
389 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700390 DisplayMetrics dm = new DisplayMetrics();
391 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700392 // Lazy-initialize the dynamic grid
393 DeviceProfile grid = app.initDynamicGrid(this,
394 Math.min(smallestSize.x, smallestSize.y),
395 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700396 realSize.x, realSize.y,
397 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700398
399 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400400 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700401 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800402 mModel = app.setLauncher(this);
403 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400404 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700406
Daniel Sandlerff02d492013-08-05 02:12:05 -0400407 mStats = new Stats(this);
408
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700409 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
411 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700412
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700413 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
414 // this also ensures that any synchronous binding below doesn't re-trigger another
415 // LauncherModel load.
416 mPaused = false;
417
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200419 android.os.Debug.startMethodTracing(
420 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 }
422
423 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 setContentView(R.layout.launcher);
425 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100426 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800428 registerContentObservers();
429
Joe Onorato7c312c12009-08-13 21:36:53 -0700430 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700431
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 mSavedState = savedInstanceState;
433 restoreState(mSavedState);
434
Winson Chunga12a2502010-12-20 14:41:35 -0800435 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700436 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200437 mAppsCustomizeContent.onPackagesUpdated(
438 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700439 }
Winson Chunga12a2502010-12-20 14:41:35 -0800440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 if (PROFILE_STARTUP) {
442 android.os.Debug.stopMethodTracing();
443 }
444
445 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700446 if (sPausedFromUserAction) {
447 // If the user leaves launcher, then we should just load items asynchronously when
448 // they return.
449 mModel.startLoader(true, -1);
450 } else {
451 // We only load the page synchronously if the user rotates (or triggers a
452 // configuration change) while launcher is in the foreground
453 mModel.startLoader(true, mWorkspace.getCurrentPage());
454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 // For handling default keys
458 mDefaultKeySsb = new SpannableStringBuilder();
459 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800460
461 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
462 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800463
Adam Cohenf9426d52012-06-04 17:26:21 -0700464 updateGlobalIcons();
465
466 // On large interfaces, we want the screen to auto-rotate based on the current orientation
467 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700468
469 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700470 }
471
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 protected void onUserLeaveHint() {
473 super.onUserLeaveHint();
474 sPausedFromUserAction = true;
475 }
476
Winson Chung98ca0f72013-07-29 12:58:51 -0700477 /** To be overriden by subclasses to hint to Launcher that we have custom content */
478 protected boolean hasCustomContentToLeft() {
479 return false;
480 }
481
Dave Hawkeya8881582013-09-17 15:55:33 -0600482 /**
483 * To be overridden by subclasses to create the custom content and call
484 * {@link #addToCustomContentPage}. This will only be invoked if
485 * {@link #hasCustomContentToLeft()} is {@code true}.
486 */
487 protected void addCustomContentToLeft() {
488 }
489
490 /**
491 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
492 * ensure the custom content page is added or removed if necessary.
493 */
494 protected void invalidateHasCustomContentToLeft() {
495 if (mWorkspace.getScreenOrder().isEmpty()) {
496 // Not bound yet, wait for bindScreens to be called.
497 return;
498 }
499
500 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
501 // Create the custom content page and call the subclass to populate it.
502 mWorkspace.createCustomContentPage();
503 addCustomContentToLeft();
504 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
505 mWorkspace.removeCustomContentPage();
506 }
507 }
508
Adam Cohenf9426d52012-06-04 17:26:21 -0700509 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700510 boolean searchVisible = false;
511 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800512 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700513 int coi = getCurrentOrientationIndexForGlobalIcons();
514 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
515 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700516 updateAppMarketIcon();
517 searchVisible = updateGlobalSearchIcon();
518 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700519 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700520 if (sGlobalSearchIcon[coi] != null) {
521 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700523 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700524 if (sVoiceSearchIcon[coi] != null) {
525 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700526 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700527 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700528 if (sAppMarketIcon[coi] != null) {
529 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800530 }
Winson Chungadf0c182012-08-23 14:59:07 -0700531 if (mSearchDropTargetBar != null) {
532 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
533 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800534 }
Romain Guycbb89e42009-06-08 15:52:54 -0700535
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800536 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700537 if (sLocaleConfiguration == null) {
538 new AsyncTask<Void, Void, LocaleConfiguration>() {
539 @Override
540 protected LocaleConfiguration doInBackground(Void... unused) {
541 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
542 readConfiguration(Launcher.this, localeConfiguration);
543 return localeConfiguration;
544 }
545
546 @Override
547 protected void onPostExecute(LocaleConfiguration result) {
548 sLocaleConfiguration = result;
549 checkForLocaleChange(); // recursive, but now with a locale configuration
550 }
551 }.execute();
552 return;
553 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700554
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 final Configuration configuration = getResources().getConfiguration();
556
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700557 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final String locale = configuration.locale.toString();
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final int mcc = configuration.mcc;
562
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700563 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final int mnc = configuration.mnc;
565
Romain Guy84f296c2009-11-04 15:00:44 -0800566 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567
Romain Guy84f296c2009-11-04 15:00:44 -0800568 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700569 sLocaleConfiguration.locale = locale;
570 sLocaleConfiguration.mcc = mcc;
571 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700572
Joe Onorato0589f0f2010-02-08 13:44:00 -0800573 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574
575 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
576 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700577 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 public void run() {
579 writeConfiguration(Launcher.this, localeConfiguration);
580 }
581 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700582 }
583 }
584
585 private static class LocaleConfiguration {
586 public String locale;
587 public int mcc = -1;
588 public int mnc = -1;
589 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700590
Romain Guy98d01652009-06-30 16:21:04 -0700591 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
592 DataInputStream in = null;
593 try {
594 in = new DataInputStream(context.openFileInput(PREFERENCES));
595 configuration.locale = in.readUTF();
596 configuration.mcc = in.readInt();
597 configuration.mnc = in.readInt();
598 } catch (FileNotFoundException e) {
599 // Ignore
600 } catch (IOException e) {
601 // Ignore
602 } finally {
603 if (in != null) {
604 try {
605 in.close();
606 } catch (IOException e) {
607 // Ignore
608 }
609 }
610 }
611 }
612
613 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
614 DataOutputStream out = null;
615 try {
616 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
617 out.writeUTF(configuration.locale);
618 out.writeInt(configuration.mcc);
619 out.writeInt(configuration.mnc);
620 out.flush();
621 } catch (FileNotFoundException e) {
622 // Ignore
623 } catch (IOException e) {
624 //noinspection ResultOfMethodCallIgnored
625 context.getFileStreamPath(PREFERENCES).delete();
626 } finally {
627 if (out != null) {
628 try {
629 out.close();
630 } catch (IOException e) {
631 // Ignore
632 }
633 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800634 }
635 }
636
Anton Hanssona2f665f2013-09-26 12:18:32 +0100637 public Stats getStats() {
638 return mStats;
639 }
640
Bjorn Bringertc459e522013-06-07 19:36:01 +0100641 public LayoutInflater getInflater() {
642 return mInflater;
643 }
644
Adam Cohen716b51e2011-06-30 12:09:54 -0700645 public DragLayer getDragLayer() {
646 return mDragLayer;
647 }
648
Winson Chung36a62fe2012-05-06 18:04:42 -0700649 boolean isDraggingEnabled() {
650 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
651 // that is subsequently removed from the workspace in startBinding().
652 return !mModel.isLoadingWorkspace();
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 static int getScreen() {
656 synchronized (sLock) {
657 return sScreen;
658 }
659 }
660
661 static void setScreen(int screen) {
662 synchronized (sLock) {
663 sScreen = screen;
664 }
665 }
666
Winson Chung557d6ed2011-07-08 15:34:52 -0700667 /**
668 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
669 * a configuration step, this allows the proper animations to run after other transitions.
670 */
671 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700672 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800673 switch (args.requestCode) {
674 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700675 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700676 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800677 break;
678 case REQUEST_PICK_SHORTCUT:
679 processShortcut(args.intent);
680 break;
681 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700682 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700683 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700684 result = true;
685 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 case REQUEST_CREATE_APPWIDGET:
687 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700688 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 result = true;
690 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 }
Michael Jurka27614d22012-04-02 06:40:22 -0700692 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
693 // if you turned the screen off and then back while in All Apps, Launcher would not
694 // return to the workspace. Clearing mAddInfo.container here fixes this issue
695 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700696 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800697 }
698
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 protected void onActivityResult(
701 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700702 // Reset the startActivity waiting flag
703 mWaitingForResult = false;
704
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 if (requestCode == REQUEST_BIND_APPWIDGET) {
706 int appWidgetId = data != null ?
707 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
708 if (resultCode == RESULT_CANCELED) {
709 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
710 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700711 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 }
713 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200714 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
715 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
716 mWorkspace.exitOverviewMode(false);
717 }
718 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700719 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200720
Winson Chung557d6ed2011-07-08 15:34:52 -0700721 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800722 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
723 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700724
Adam Cohened66b2b2012-01-23 17:28:51 -0800725 // We have special handling for widgets
726 if (isWidgetDrop) {
727 int appWidgetId = data != null ?
728 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700729 if (appWidgetId < 0) {
730 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
731 "widget configuration activity.");
732 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
733 } else {
734 completeTwoStageWidgetDrop(resultCode, appWidgetId);
735 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800736 return;
737 }
738
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 // The pattern used here is that a user PICKs a specific application,
740 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700741
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
743 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700744 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 final PendingAddArguments args = new PendingAddArguments();
746 args.requestCode = requestCode;
747 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700748 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700749 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700750 args.cellX = mPendingAddInfo.cellX;
751 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 if (isWorkspaceLocked()) {
753 sPendingAddList.add(args);
754 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700755 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800758 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700759 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800760 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
761 null);
762 }
763
764 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700765 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700766 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 Runnable onCompleteRunnable = null;
768 int animationType = 0;
769
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700770 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 if (resultCode == RESULT_OK) {
772 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
773 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700774 mPendingAddWidgetInfo);
775 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 onCompleteRunnable = new Runnable() {
777 @Override
778 public void run() {
779 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700780 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
782 null);
783 }
784 };
785 } else if (resultCode == RESULT_CANCELED) {
786 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
787 onCompleteRunnable = new Runnable() {
788 @Override
789 public void run() {
790 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
791 null);
792 }
793 };
794 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700795 if (mDragLayer.getAnimatedView() != null) {
796 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
797 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
798 animationType, boundWidget, true);
799 } else {
800 // The animated view may be null in the case of a rotation during widget configuration
801 onCompleteRunnable.run();
802 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800803 }
804
805 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700806 protected void onStop() {
807 super.onStop();
808 FirstFrameAnimatorHelper.setIsVisible(false);
809 }
810
811 @Override
812 protected void onStart() {
813 super.onStart();
814 FirstFrameAnimatorHelper.setIsVisible(true);
815 }
816
817 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200819 long startTime = 0;
820 if (DEBUG_RESUME_TIME) {
821 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400822 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200823 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700825
Winson Chung4a2afa32012-07-19 14:53:05 -0700826 // Restore the previous launcher state
827 if (mOnResumeState == State.WORKSPACE) {
828 showWorkspace(false);
829 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700830 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700831 }
832 mOnResumeState = State.NONE;
833
Craig Mautner360310b2012-10-26 15:13:08 -0700834 // Background was set to gradient in onPause(), restore to black if in all apps.
835 setWorkspaceBackground(mState == State.WORKSPACE);
836
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800837 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700838 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700839 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400840 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700841 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400842 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700843 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700845 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200846 // We might have postponed some bind calls until onResume (see waitUntilResume) --
847 // execute them here
848 long startTimeCallbacks = 0;
849 if (DEBUG_RESUME_TIME) {
850 startTimeCallbacks = System.currentTimeMillis();
851 }
852
853 if (mAppsCustomizeContent != null) {
854 mAppsCustomizeContent.setBulkBind(true);
855 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700856 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
857 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200858 }
859 if (mAppsCustomizeContent != null) {
860 mAppsCustomizeContent.setBulkBind(false);
861 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700862 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200863 if (DEBUG_RESUME_TIME) {
864 Log.d(TAG, "Time spent processing callbacks in onResume: " +
865 (System.currentTimeMillis() - startTimeCallbacks));
866 }
Michael Jurka447bf842013-05-15 14:52:15 +0200867 }
Michael Jurka54554252013-08-01 12:52:23 +0200868 if (mOnResumeCallbacks.size() > 0) {
869 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
870 mOnResumeCallbacks.get(i).run();
871 }
872 mOnResumeCallbacks.clear();
873 }
Winson Chunge4e50662012-01-23 14:45:13 -0800874
875 // Reset the pressed state of icons that were locked in the press state while activities
876 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800877 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800878 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800879 mWaitingForResume.setStayPressed(false);
880 }
Winson Chunge4e50662012-01-23 14:45:13 -0800881 if (mAppsCustomizeContent != null) {
882 // Resets the previous all apps icon press state
883 mAppsCustomizeContent.resetDrawableState();
884 }
Winson Chung780fe592013-09-26 14:48:44 -0700885 // Reset AllApps to its initial state
886 if (mAppsCustomizeTabHost != null) {
887 mAppsCustomizeTabHost.reset();
888 }
Adam Cohen06dff352012-06-01 17:17:08 -0700889 // It is possible that widgets can receive updates while launcher is not in the foreground.
890 // Consequently, the widgets will be inflated in the orientation of the foreground activity
891 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
892 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700893 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700894
Winson Chung780fe592013-09-26 14:48:44 -0700895 // Process any items that were added while Launcher was away.
896 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
897
Adam Cohenf9426d52012-06-04 17:26:21 -0700898 // Again, as with the above scenario, it's possible that one or more of the global icons
899 // were updated in the wrong orientation.
900 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200901 if (DEBUG_RESUME_TIME) {
902 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
903 }
Adam Cohen06dff352012-06-01 17:17:08 -0700904 }
905
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700907 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700908 // Ensure that items added to Launcher are queued until Launcher returns
909 InstallShortcutReceiver.enableInstallQueue();
910
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700911 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700912 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800913 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700914 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700915 }
Romain Guycbb89e42009-06-08 15:52:54 -0700916
Adam Cohen66a01fd2013-06-11 12:48:00 -0700917 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600918 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
919 addCustomContentToLeft();
920 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700921 }
922
Adam Cohenbffe7452013-07-22 18:21:45 -0700923 QSBScroller mQsbScroller = new QSBScroller() {
924 int scrollY = 0;
925
926 @Override
927 public void setScrollY(int scroll) {
928 scrollY = scroll;
929
930 if (mWorkspace.isOnOrMovingToCustomContent()) {
931 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100932 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700933 }
934 }
935 };
936
937 public void resetQSBScroll() {
938 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100939 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700940 }
941
942 public interface CustomContentCallbacks {
943 // Custom content is completely shown
944 public void onShow();
945
946 // Custom content is completely hidden
947 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700948
949 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
950 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700951 }
952
Adam Cohen30bacb22013-08-29 14:25:25 -0700953 protected void startSettings() {
954 }
955
Adam Cohenbffe7452013-07-22 18:21:45 -0700956 public interface QSBScroller {
957 public void setScrollY(int scrollY);
958 }
959
Adam Cohen66a01fd2013-06-11 12:48:00 -0700960 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700961 public QSBScroller addToCustomContentPage(View customContent) {
962 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700963 }
964
Winson Chung98ca0f72013-07-29 12:58:51 -0700965 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700966 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700967 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700968 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700969 }
970
Adam Cohenedb40762013-07-18 16:45:45 -0700971 // The custom content needs to offset its content to account for the QSB
972 public int getTopOffsetForCustomContent() {
973 return mWorkspace.getPaddingTop();
974 }
975
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700976 @Override
977 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 // Flag the loader to stop early before switching
979 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700980 if (mAppsCustomizeContent != null) {
981 mAppsCustomizeContent.surrender();
982 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800983 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700984 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700985
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800986 // We can't hide the IME if it was forced open. So don't bother
987 /*
988 @Override
989 public void onWindowFocusChanged(boolean hasFocus) {
990 super.onWindowFocusChanged(hasFocus);
991
992 if (hasFocus) {
993 final InputMethodManager inputManager = (InputMethodManager)
994 getSystemService(Context.INPUT_METHOD_SERVICE);
995 WindowManager.LayoutParams lp = getWindow().getAttributes();
996 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
997 android.os.Handler()) {
998 protected void onReceiveResult(int resultCode, Bundle resultData) {
999 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1000 }
1001 });
1002 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1003 }
1004 }
1005 */
1006
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001007 private boolean acceptFilter() {
1008 final InputMethodManager inputManager = (InputMethodManager)
1009 getSystemService(Context.INPUT_METHOD_SERVICE);
1010 return !inputManager.isFullscreenMode();
1011 }
1012
1013 @Override
1014 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001015 final int uniChar = event.getUnicodeChar();
1016 final boolean handled = super.onKeyDown(keyCode, event);
1017 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1018 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1020 keyCode, event);
1021 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001022 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001023 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001024 // showSearchDialog()
1025 // If there are multiple keystrokes before the search dialog takes focus,
1026 // onSearchRequested() will be called for every keystroke,
1027 // but it is idempotent, so it's fine.
1028 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 }
1030 }
1031
Joe Onorato8a9625e2010-01-28 15:55:35 -08001032 // Eat the long press event so the keyboard doesn't come up.
1033 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1034 return true;
1035 }
1036
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 return handled;
1038 }
1039
Karl Rosaen138a0412009-04-23 19:00:21 -07001040 private String getTypedText() {
1041 return mDefaultKeySsb.toString();
1042 }
1043
1044 private void clearTypedText() {
1045 mDefaultKeySsb.clear();
1046 mDefaultKeySsb.clearSpans();
1047 Selection.setSelection(mDefaultKeySsb, 0);
1048 }
1049
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001051 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1052 * State
1053 */
1054 private static State intToState(int stateOrdinal) {
1055 State state = State.WORKSPACE;
1056 final State[] stateValues = State.values();
1057 for (int i = 0; i < stateValues.length; i++) {
1058 if (stateValues[i].ordinal() == stateOrdinal) {
1059 state = stateValues[i];
1060 break;
1061 }
1062 }
1063 return state;
1064 }
1065
1066 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001067 * Restores the previous state, if it exists.
1068 *
1069 * @param savedState The previous state.
1070 */
1071 private void restoreState(Bundle savedState) {
1072 if (savedState == null) {
1073 return;
1074 }
1075
Michael Jurka883f55b2010-10-21 15:47:14 -07001076 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001077 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001078 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001079 }
1080
Winson Chungf0c6ae02012-03-21 16:10:31 -07001081 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001083 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001084 }
1085
Winson Chung3d503fb2011-07-13 17:25:49 -07001086 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001087 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001088
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1090 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001091 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001092 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1093 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001094 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1095 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1096 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001097 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 mRestoring = true;
1099 }
1100
1101 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1102 if (renameFolder) {
1103 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001104 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 mRestoring = true;
1106 }
Winson Chunga12a2502010-12-20 14:41:35 -08001107
Winson Chung785d2eb2011-04-14 16:08:02 -07001108 // Restore the AppsCustomize tab
1109 if (mAppsCustomizeTabHost != null) {
1110 String curTab = savedState.getString("apps_customize_currentTab");
1111 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001112 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001113 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001114 mAppsCustomizeContent.loadAssociatedPages(
1115 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 }
1117
Winson Chung5afbf7b2011-07-25 11:53:08 -07001118 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1119 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001120 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 }
1122
1123 /**
1124 * Finds all the views we need and configure them properly.
1125 */
1126 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001127 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001128
Craig Mautner360310b2012-10-26 15:13:08 -07001129 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001130 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1131 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001132
John Spurlock77e1f472013-09-11 10:09:51 -04001133 mLauncherView.setSystemUiVisibility(
1134 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001135 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001136
Winson Chung4c98d922011-05-31 16:50:48 -07001137 // Setup the drag layer
1138 mDragLayer.setup(this, dragController);
1139
Winson Chung3d503fb2011-07-13 17:25:49 -07001140 // Setup the hotseat
1141 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1142 if (mHotseat != null) {
1143 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001144 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001145 }
1146
Adam Cohenf358a4b2013-07-23 16:47:31 -07001147 mOverviewPanel = findViewById(R.id.overview_panel);
1148 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1149 @Override
1150 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001151 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001152 }
1153 });
1154 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1155 @Override
1156 public void onClick(View arg0) {
1157 startWallpaper();
1158 }
1159 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001160 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1161 @Override
1162 public void onClick(View arg0) {
1163 startSettings();
1164 }
1165 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001166 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001167
Winson Chung4c98d922011-05-31 16:50:48 -07001168 // Setup the workspace
1169 mWorkspace.setHapticFeedbackEnabled(false);
1170 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001171 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001172 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001173
Winson Chungf0ea4d32011-06-06 14:27:16 -07001174 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001175 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001176
Winson Chungf0ea4d32011-06-06 14:27:16 -07001177 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001178 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001179 mAppsCustomizeContent = (AppsCustomizePagedView)
1180 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1181 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001182
Winson Chung3d503fb2011-07-13 17:25:49 -07001183 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001184 dragController.setDragScoller(mWorkspace);
1185 dragController.setScrollView(mDragLayer);
1186 dragController.setMoveTarget(mWorkspace);
1187 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001188 if (mSearchDropTargetBar != null) {
1189 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001190 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001191
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001192 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001193 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001194 mWeightWatcher = new WeightWatcher(this);
1195 mWeightWatcher.setAlpha(0.5f);
1196 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001197 new FrameLayout.LayoutParams(
1198 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001199 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001200 Gravity.BOTTOM)
1201 );
Adam Cohen39a06042013-07-19 14:30:12 -07001202
1203 boolean show = shouldShowWeightWatcher();
1204 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001205 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001206 }
1207
1208 /**
1209 * Creates a view representing a shortcut.
1210 *
1211 * @param info The data structure describing the shortcut.
1212 *
1213 * @return A View inflated from R.layout.application.
1214 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001215 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001217 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 }
1219
1220 /**
1221 * Creates a view representing a shortcut inflated from the specified resource.
1222 *
1223 * @param layoutResId The id of the XML layout used to create the shortcut.
1224 * @param parent The group the shortcut belongs to.
1225 * @param info The data structure describing the shortcut.
1226 *
1227 * @return A View inflated from layoutResId.
1228 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001229 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001230 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1231 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 return favorite;
1234 }
1235
1236 /**
1237 * Add an application shortcut to the workspace.
1238 *
1239 * @param data The intent describing the application.
1240 * @param cellInfo The position on screen where to create the shortcut.
1241 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001242 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001243 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001244 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001245
Adam Cohenfbba09b2011-07-18 21:43:05 -07001246 // First we check if we already know the exact location where we want to add this item.
1247 if (cellX >= 0 && cellY >= 0) {
1248 cellXY[0] = cellX;
1249 cellXY[1] = cellY;
1250 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001251 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001252 return;
1253 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001255 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001256
Romain Guy73b979d2009-06-09 12:57:21 -07001257 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001258 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001260 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001261 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001262 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001263 } else {
1264 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 }
1266 }
Romain Guycbb89e42009-06-08 15:52:54 -07001267
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 /**
1269 * Add a shortcut to the workspace.
1270 *
1271 * @param data The intent describing the shortcut.
1272 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001275 int cellY) {
1276 int[] cellXY = mTmpAddItemCellCoordinates;
1277 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001278 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001279
Michael Jurkad3ef3062010-11-23 16:23:58 -08001280 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001281
Adam Cohen558baaf2011-08-15 15:22:57 -07001282 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001283 if (info == null) {
1284 return;
1285 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001286 final View view = createShortcut(info);
1287
Adam Cohenfbba09b2011-07-18 21:43:05 -07001288 // First we check if we already know the exact location where we want to add this item.
1289 if (cellX >= 0 && cellY >= 0) {
1290 cellXY[0] = cellX;
1291 cellXY[1] = cellY;
1292 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001293
1294 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001295 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001296 true, null,null)) {
1297 return;
1298 }
1299 DragObject dragObject = new DragObject();
1300 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001301 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1302 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001303 return;
1304 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001305 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001306 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001307 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001308 foundCellSpan = (result != null);
1309 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001310 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001311 }
1312
1313 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001314 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001315 return;
1316 }
1317
Adam Cohendcd297f2013-06-18 13:13:40 -07001318 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319
1320 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001321 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001322 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 }
1324 }
1325
Adam Cohen2f093b62012-04-30 18:59:53 -07001326 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1327 int minHeight) {
1328 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001329 // We want to account for the extra amount of padding that we are adding to the widget
1330 // to ensure that it gets the full amount of space that it has requested
1331 int requiredWidth = minWidth + padding.left + padding.right;
1332 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001333 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1337 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001338 }
1339
Adam Cohen2f093b62012-04-30 18:59:53 -07001340 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1341 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001342 }
1343
Adam Cohen2f093b62012-04-30 18:59:53 -07001344 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1345 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001346 }
1347
Adam Cohen2f093b62012-04-30 18:59:53 -07001348 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1349 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001350 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001351 }
1352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001354 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001356 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001359 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001360 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1361 if (appWidgetInfo == null) {
1362 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1363 }
Romain Guycbb89e42009-06-08 15:52:54 -07001364
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001365 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001366 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001367
Adam Cohen2f093b62012-04-30 18:59:53 -07001368 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1369 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001370
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001372 // We have saved the position to which the widget was dragged-- this really only matters
1373 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 int[] cellXY = mTmpAddItemCellCoordinates;
1375 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001376 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001377 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1379 cellXY[0] = mPendingAddInfo.cellX;
1380 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001381 spanXY[0] = mPendingAddInfo.spanX;
1382 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001383 foundCellSpan = true;
1384 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001385 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001386 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001387 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1388 spanXY[1], cellXY, finalSpan);
1389 spanXY[0] = finalSpan[0];
1390 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001391 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001392 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001393 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001394 }
1395
Michael Jurka0280c3b2010-09-17 15:00:07 -07001396 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001397 if (appWidgetId != -1) {
1398 // Deleting an app widget ID is a void call but writes to disk before returning
1399 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001400 new Thread("deleteAppWidgetId") {
1401 public void run() {
1402 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1403 }
1404 }.start();
1405 }
Winson Chung93eef082012-03-23 15:59:27 -07001406 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001407 return;
1408 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001410 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001411 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1412 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001413 launcherInfo.spanX = spanXY[0];
1414 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001415 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1416 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001417
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001419 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420
1421 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001422 if (hostView == null) {
1423 // Perform actual inflation because we're live
1424 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1425 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1426 } else {
1427 // The AppWidgetHostView has already been inflated and instantiated
1428 launcherInfo.hostView = hostView;
1429 }
Romain Guycbb89e42009-06-08 15:52:54 -07001430
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001432 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001433 launcherInfo.notifyWidgetSizeChanged(this);
1434
Adam Cohendcd297f2013-06-18 13:13:40 -07001435 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001436 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001437
1438 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001440 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441 }
Romain Guycbb89e42009-06-08 15:52:54 -07001442
Adam Cohended9f8d2010-11-03 13:25:16 -07001443 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1444 @Override
1445 public void onReceive(Context context, Intent intent) {
1446 final String action = intent.getAction();
1447 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1448 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001449 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001450 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001451
Winson Chungc100e8e2011-08-09 16:02:43 -07001452 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001453 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001454 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001455 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001456 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001457 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1458 mUserPresent = true;
1459 updateRunning();
1460 }
1461 }
1462 };
1463
1464 @Override
1465 public void onAttachedToWindow() {
1466 super.onAttachedToWindow();
1467
1468 // Listen for broadcasts related to user-presence
1469 final IntentFilter filter = new IntentFilter();
1470 filter.addAction(Intent.ACTION_SCREEN_OFF);
1471 filter.addAction(Intent.ACTION_USER_PRESENT);
1472 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001473 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001474 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001475 mVisible = true;
1476 }
1477
1478 @Override
1479 public void onDetachedFromWindow() {
1480 super.onDetachedFromWindow();
1481 mVisible = false;
1482
Adam Cohend113e0c2010-11-11 10:48:05 -08001483 if (mAttached) {
1484 unregisterReceiver(mReceiver);
1485 mAttached = false;
1486 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001487 updateRunning();
1488 }
1489
1490 public void onWindowVisibilityChanged(int visibility) {
1491 mVisible = visibility == View.VISIBLE;
1492 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001493 // The following code used to be in onResume, but it turns out onResume is called when
1494 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1495 // is a more appropriate event to handle
1496 if (mVisible) {
1497 mAppsCustomizeTabHost.onWindowVisible();
1498 if (!mWorkspaceLoading) {
1499 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001500 // We want to let Launcher draw itself at least once before we force it to build
1501 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001502 // apps is nice and speedy.
1503 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001504 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001506 if (mStarted) return;
1507 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001508 // We delay the layer building a bit in order to give
1509 // other message processing a time to run. In particular
1510 // this avoids a delay in hiding the IME if it was
1511 // currently shown, because doing that may involve
1512 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001513 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001514 final ViewTreeObserver.OnDrawListener listener = this;
1515 mWorkspace.post(new Runnable() {
1516 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001517 if (mWorkspace != null &&
1518 mWorkspace.getViewTreeObserver() != null) {
1519 mWorkspace.getViewTreeObserver().
1520 removeOnDrawListener(listener);
1521 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001522 }
1523 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001524 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001525 }
1526 });
1527 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001528 // When Launcher comes back to foreground, a different Activity might be responsible for
1529 // the app market intent, so refresh the icon
1530 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001531 clearTypedText();
1532 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001533 }
1534
1535 private void sendAdvanceMessage(long delay) {
1536 mHandler.removeMessages(ADVANCE_MSG);
1537 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1538 mHandler.sendMessageDelayed(msg, delay);
1539 mAutoAdvanceSentTime = System.currentTimeMillis();
1540 }
1541
1542 private void updateRunning() {
1543 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1544 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1545 mAutoAdvanceRunning = autoAdvanceRunning;
1546 if (autoAdvanceRunning) {
1547 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1548 sendAdvanceMessage(delay);
1549 } else {
1550 if (!mWidgetsToAdvance.isEmpty()) {
1551 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1552 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1553 }
1554 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001555 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 }
1557 }
1558 }
1559
1560 private final Handler mHandler = new Handler() {
1561 @Override
1562 public void handleMessage(Message msg) {
1563 if (msg.what == ADVANCE_MSG) {
1564 int i = 0;
1565 for (View key: mWidgetsToAdvance.keySet()) {
1566 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1567 final int delay = mAdvanceStagger * i;
1568 if (v instanceof Advanceable) {
1569 postDelayed(new Runnable() {
1570 public void run() {
1571 ((Advanceable) v).advance();
1572 }
1573 }, delay);
1574 }
1575 i++;
1576 }
1577 sendAdvanceMessage(mAdvanceInterval);
1578 }
1579 }
1580 };
1581
1582 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001583 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1585 if (v instanceof Advanceable) {
1586 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001587 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001588 updateRunning();
1589 }
1590 }
1591
1592 void removeWidgetToAutoAdvance(View hostView) {
1593 if (mWidgetsToAdvance.containsKey(hostView)) {
1594 mWidgetsToAdvance.remove(hostView);
1595 updateRunning();
1596 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001597 }
1598
Joe Onorato9c1289c2009-08-17 11:03:03 -04001599 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001601 launcherInfo.hostView = null;
1602 }
1603
Winson Chung93eef082012-03-23 15:59:27 -07001604 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1605 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1606 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 }
1608
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001609 public LauncherAppWidgetHost getAppWidgetHost() {
1610 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 }
Romain Guycbb89e42009-06-08 15:52:54 -07001612
Winson Chunga9abd0e2010-10-27 17:18:37 -07001613 public LauncherModel getModel() {
1614 return mModel;
1615 }
1616
Bjorn Bringertc459e522013-06-07 19:36:01 +01001617 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001618 getWindow().closeAllPanels();
1619
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001620 // Whatever we were doing is hereby canceled.
1621 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001622 }
1623
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 @Override
1625 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001626 long startTime = 0;
1627 if (DEBUG_RESUME_TIME) {
1628 startTime = System.currentTimeMillis();
1629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001630 super.onNewIntent(intent);
1631
1632 // Close the menu
1633 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001634 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001635 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001636
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 final boolean alreadyOnHome =
1638 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001639 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001640
Jamie Genniscb222e82012-10-23 15:44:26 -07001641 Runnable processIntent = new Runnable() {
1642 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001643 if (mWorkspace == null) {
1644 // Can be cases where mWorkspace is null, this prevents a NPE
1645 return;
1646 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001647 Folder openFolder = mWorkspace.getOpenFolder();
1648 // In all these cases, only animate if we're already on home
1649 mWorkspace.exitWidgetResizeMode();
1650 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1651 openFolder == null) {
1652 mWorkspace.moveToDefaultScreen(true);
1653 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001654
Jamie Genniscb222e82012-10-23 15:44:26 -07001655 closeFolder();
1656 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001657
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 // If we are already on home, then just animate back to the workspace,
1659 // otherwise, just wait until onResume to set the state back to Workspace
1660 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001661 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001662 } else {
1663 mOnResumeState = State.WORKSPACE;
1664 }
1665
1666 final View v = getWindow().peekDecorView();
1667 if (v != null && v.getWindowToken() != null) {
1668 InputMethodManager imm = (InputMethodManager)getSystemService(
1669 INPUT_METHOD_SERVICE);
1670 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1671 }
1672
Winson Chung7819a562013-09-19 15:55:45 -07001673 // Reset the apps customize page
1674 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001675 mAppsCustomizeTabHost.reset();
1676 }
1677 }
1678 };
1679
1680 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1681 // Delay processing of the intent to allow the status bar animation to finish
1682 // first in order to avoid janky animations.
1683 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001684 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001685 // Process the intent immediately.
1686 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001687 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001688
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
Michael Jurka447bf842013-05-15 14:52:15 +02001690 if (DEBUG_RESUME_TIME) {
1691 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 }
1694
Adam Cohen040a5d22013-09-16 17:09:33 -07001695 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1696 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001697 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001698 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001699 }
1700 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001701 protected void showWorkspaceAndExitOverviewMode() {
1702 showWorkspaceAndExitOverviewMode(true);
1703 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001704
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001706 public void onRestoreInstanceState(Bundle state) {
1707 super.onRestoreInstanceState(state);
1708 for (int page: mSynchronouslyBoundPages) {
1709 mWorkspace.restoreInstanceStateForChild(page);
1710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
1712
1713 @Override
1714 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001715 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001716 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717
Michael Jurka883f55b2010-10-21 15:47:14 -07001718 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001719 // We close any open folder since it will not be re-opened, and we need to make sure
1720 // this state is reflected.
1721 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722
Adam Cohendcd297f2013-06-18 13:13:40 -07001723 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001724 mWaitingForResult) {
1725 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001726 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001727 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1728 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001729 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1730 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1731 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 }
1733
1734 if (mFolderInfo != null && mWaitingForResult) {
1735 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1736 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1737 }
Michael Jurka946ad472010-07-09 18:05:18 -07001738
Winson Chung785d2eb2011-04-14 16:08:02 -07001739 // Save the current AppsCustomize tab
1740 if (mAppsCustomizeTabHost != null) {
1741 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1742 if (currentTabTag != null) {
1743 outState.putString("apps_customize_currentTab", currentTabTag);
1744 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001745 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1746 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 }
1749
1750 @Override
1751 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001753
Winson Chunge7a03942011-08-05 15:05:12 -07001754 // Remove all pending runnables
1755 mHandler.removeMessages(ADVANCE_MSG);
1756 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001757 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001758
Winson Chungcd2b0142011-06-08 16:02:26 -07001759 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001760 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001761 mModel.stopLoader();
1762 app.setLauncher(null);
1763
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001765 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001767 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001769 mAppWidgetHost = null;
1770
1771 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772
1773 TextKeyListener.getInstance().release();
1774
Winson Chung81b52252012-08-27 15:34:29 -07001775 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1776 // to prevent leaking Launcher activities on orientation change.
1777 if (mModel != null) {
1778 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1779 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001780
1781 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001782 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001783
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001784 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001785 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1786 mWorkspace.removeAllViews();
1787 mWorkspace = null;
1788 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001789
Michael Jurka2ecf9952012-06-18 12:52:28 -07001790 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
1792
Adam Cohena9cf38f2011-05-02 15:36:58 -07001793 public DragController getDragController() {
1794 return mDragController;
1795 }
1796
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 @Override
1798 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001799 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 super.startActivityForResult(intent, requestCode);
1801 }
1802
Winson Chung70d72102011-08-12 11:24:35 -07001803 /**
1804 * Indicates that we want global search for this activity by setting the globalSearch
1805 * argument for {@link #startSearch} to true.
1806 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001808 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001810
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001811 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001812
Karl Rosaen138a0412009-04-23 19:00:21 -07001813 if (initialQuery == null) {
1814 // Use any text typed in the launcher as the initial query
1815 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 if (appSearchData == null) {
1818 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001819 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
Winson Chungadf0c182012-08-23 14:59:07 -07001821 Rect sourceBounds = new Rect();
1822 if (mSearchDropTargetBar != null) {
1823 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1824 }
Romain Guycbb89e42009-06-08 15:52:54 -07001825
Bjorn Bringertc459e522013-06-07 19:36:01 +01001826 startSearch(initialQuery, selectInitialQuery,
1827 appSearchData, sourceBounds);
1828 }
1829
1830 public void startSearch(String initialQuery,
1831 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001832 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001833 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001834 }
1835
1836 /**
1837 * Starts the global search activity. This code is a copied from SearchManager
1838 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001839 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001840 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001841 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001842 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1843 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1844 if (globalSearchActivity == null) {
1845 Log.w(TAG, "No global search activity found.");
1846 return;
1847 }
1848 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1849 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1850 intent.setComponent(globalSearchActivity);
1851 // Make sure that we have a Bundle to put source in
1852 if (appSearchData == null) {
1853 appSearchData = new Bundle();
1854 } else {
1855 appSearchData = new Bundle(appSearchData);
1856 }
1857 // Set source to package name of app that starts global search, if not set already.
1858 if (!appSearchData.containsKey("source")) {
1859 appSearchData.putString("source", getPackageName());
1860 }
1861 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1862 if (!TextUtils.isEmpty(initialQuery)) {
1863 intent.putExtra(SearchManager.QUERY, initialQuery);
1864 }
1865 if (selectInitialQuery) {
1866 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1867 }
1868 intent.setSourceBounds(sourceBounds);
1869 try {
1870 startActivity(intent);
1871 } catch (ActivityNotFoundException ex) {
1872 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1873 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 }
1875
Winson Chung70d72102011-08-12 11:24:35 -07001876 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001877 public boolean onPrepareOptionsMenu(Menu menu) {
1878 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001879 if (!mWorkspace.isInOverviewMode()) {
1880 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001881 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001882 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001883 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001885 @Override
1886 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001887 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001888 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001889 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001890 }
1891
Joe Onorato9c1289c2009-08-17 11:03:03 -04001892 public boolean isWorkspaceLocked() {
1893 return mWorkspaceLoading || mWaitingForResult;
1894 }
1895
Michael Jurka0280c3b2010-09-17 15:00:07 -07001896 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001897 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001898 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001899 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1900 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001901 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001903 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001904
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001905 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1906 AppWidgetProviderInfo appWidgetInfo) {
1907 if (appWidgetInfo.configure != null) {
1908 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001909
Bjorn Bringert7984c942009-12-09 15:38:25 +00001910 // Launch over to configure widget, if needed
1911 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001912 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001913 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001914 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001916 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001917 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001918 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001919 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001920 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 }
1922 }
Romain Guycbb89e42009-06-08 15:52:54 -07001923
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001924 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001925 // Close any folders that may be open.
1926 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001927 mWorkspace.moveToCustomContentScreen(animate);
1928 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001929 /**
1930 * Process a shortcut drop.
1931 *
1932 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001933 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001934 * @param cell The cell it should be added to, optional
1935 * @param position The location on the screen where it was dropped, optional
1936 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001937 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001938 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001939 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001940 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001941 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001942 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001943
1944 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001945 mPendingAddInfo.cellX = cell[0];
1946 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001947 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001948
1949 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1950 createShortcutIntent.setComponent(componentName);
1951 processShortcut(createShortcutIntent);
1952 }
1953
Adam Cohenfbba09b2011-07-18 21:43:05 -07001954 /**
1955 * Process a widget drop.
1956 *
1957 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001958 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001959 * @param cell The cell it should be added to, optional
1960 * @param position The location on the screen where it was dropped, optional
1961 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001962 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001963 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001964 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001966 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001967 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001968 mPendingAddInfo.minSpanX = info.minSpanX;
1969 mPendingAddInfo.minSpanY = info.minSpanY;
1970
Adam Cohenfbba09b2011-07-18 21:43:05 -07001971 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001972 mPendingAddInfo.cellX = cell[0];
1973 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001974 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001975 if (span != null) {
1976 mPendingAddInfo.spanX = span[0];
1977 mPendingAddInfo.spanY = span[1];
1978 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001979
Adam Cohened66b2b2012-01-23 17:28:51 -08001980 AppWidgetHostView hostView = info.boundWidget;
1981 int appWidgetId;
1982 if (hostView != null) {
1983 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001984 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001985 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001986 // In this case, we either need to start an activity to get permission to bind
1987 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001988 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001989 Bundle options = info.bindOptions;
1990
1991 boolean success = false;
1992 if (options != null) {
1993 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1994 info.componentName, options);
1995 } else {
1996 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1997 info.componentName);
1998 }
1999 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002000 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002001 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002002 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002003 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2004 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2005 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002006 // TODO: we need to make sure that this accounts for the options bundle.
2007 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002008 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2009 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002010 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002011 }
2012
Joe Onoratodeb98af2010-02-19 14:59:39 -08002013 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002014 // Handle case where user selected "Applications"
2015 String applicationName = getResources().getString(R.string.group_applications);
2016 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002017
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002018 if (applicationName != null && applicationName.equals(shortcutName)) {
2019 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2020 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002021
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002022 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2023 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002024 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002025 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002026 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002027 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002028 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 }
2030
Winson Chung24ab2f12010-09-16 14:10:47 -07002031 void processWallpaper(Intent intent) {
2032 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2033 }
2034
Adam Cohendcd297f2013-06-18 13:13:40 -07002035 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002036 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002037 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 folderInfo.title = getText(R.string.folder_name);
2039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002041 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002042 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002043 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044
2045 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002046 FolderIcon newFolder =
2047 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002048 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002049 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002050 // Force measure the new folder icon
2051 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2052 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002053 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 }
Romain Guycbb89e42009-06-08 15:52:54 -07002055
Joe Onorato9c1289c2009-08-17 11:03:03 -04002056 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002057 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002058 }
2059
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002060 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002061 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002063 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002064 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 }
2066
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002067 protected ComponentName getWallpaperPickerComponent() {
2068 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2069 }
2070
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002071 /**
2072 * Registers various content observers. The current implementation registers
2073 * only a favorites observer to keep track of the favorites applications.
2074 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002075 private void registerContentObservers() {
2076 ContentResolver resolver = getContentResolver();
2077 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2078 true, mWidgetObserver);
2079 }
2080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002081 @Override
2082 public boolean dispatchKeyEvent(KeyEvent event) {
2083 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2084 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002086 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002087 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002088 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002089 dumpState();
2090 return true;
2091 }
2092 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002093 }
2094 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2095 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002096 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002097 return true;
2098 }
2099 }
2100
2101 return super.dispatchKeyEvent(event);
2102 }
2103
Joe Onorato88ec0992009-11-19 13:16:06 -08002104 @Override
2105 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002106 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002107 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002108 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002109 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002110 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002111 Folder openFolder = mWorkspace.getOpenFolder();
2112 if (openFolder.isEditingName()) {
2113 openFolder.dismissEditingName();
2114 } else {
2115 closeFolder();
2116 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002117 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002118 mWorkspace.exitWidgetResizeMode();
2119
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002120 // Back button is a no-op here, but give at least some feedback for the button press
2121 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002122 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002123 }
2124
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002125 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002126 * Re-listen when widgets are reset.
2127 */
2128 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002129 if (mAppWidgetHost != null) {
2130 mAppWidgetHost.startListening();
2131 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002132 }
2133
2134 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 * Launches the intent referred by the clicked shortcut.
2136 *
2137 * @param v The view representing the clicked shortcut.
2138 */
2139 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002140 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2141 // view has detached (it's possible for this to happen if the view is removed mid touch).
2142 if (v.getWindowToken() == null) {
2143 return;
2144 }
2145
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002146 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002147 return;
2148 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002149
Adam Cohen1697b792013-09-17 19:08:21 -07002150 if (v instanceof Workspace) {
2151 if (mWorkspace.isInOverviewMode()) {
2152 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002153 }
2154 return;
2155 }
2156
2157 if (v instanceof CellLayout) {
2158 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002159 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002160 }
2161 }
2162
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002164 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002166 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2167 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002168
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002169 // Check for special shortcuts
2170 if (intent.getComponent() != null) {
2171 final String shortcutClass = intent.getComponent().getClassName();
2172
2173 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002174 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002175 return;
2176 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2177 MemoryDumpActivity.startDump(this);
2178 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002179 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2180 toggleShowWeightWatcher();
2181 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002182 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002183 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002184
2185 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002186 int[] pos = new int[2];
2187 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002188 intent.setSourceBounds(new Rect(pos[0], pos[1],
2189 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002190
2191 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002192
Daniel Sandlerff02d492013-08-05 02:12:05 -04002193 mStats.recordLaunch(intent, shortcut);
2194
Michael Jurkaddd62e92011-02-16 17:49:14 -08002195 if (success && v instanceof BubbleTextView) {
2196 mWaitingForResume = (BubbleTextView) v;
2197 mWaitingForResume.setStayPressed(true);
2198 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002199 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002200 if (v instanceof FolderIcon) {
2201 FolderIcon fi = (FolderIcon) v;
2202 handleFolderClick(fi);
2203 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002204 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002205 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002206 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002207 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002208 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002209 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 }
2211 }
2212
Michael Jurka0e260592010-06-30 17:07:39 -07002213 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002214 return false;
2215 }
2216
Michael Jurkaaf442092010-06-10 17:01:57 -07002217 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002218 * Event handler for the search button
2219 *
2220 * @param v The view that was clicked.
2221 */
2222 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002223 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2224
Amith Yamasania135ba82011-08-09 17:42:01 -07002225 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002226 }
2227
2228 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002229 * Event handler for the voice button
2230 *
2231 * @param v The view that was clicked.
2232 */
2233 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002234 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002235
Bjorn Bringertc459e522013-06-07 19:36:01 +01002236 startVoice();
2237 }
2238
2239 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002240 try {
2241 final SearchManager searchManager =
2242 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2243 ComponentName activityName = searchManager.getGlobalSearchActivity();
2244 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002245 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002246 if (activityName != null) {
2247 intent.setPackage(activityName.getPackageName());
2248 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002249 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002250 } catch (ActivityNotFoundException e) {
2251 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002252 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002253 startActivitySafely(null, intent, "onClickVoiceButton");
2254 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002255 }
2256
2257 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002258 * Event handler for the "grid" button that appears on the home screen, which
2259 * enters all apps mode.
2260 *
2261 * @param v The view that was clicked.
2262 */
2263 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002264 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002265 }
2266
2267 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002268 // Provide the same haptic feedback that the system offers for virtual keys.
2269 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002270 }
2271
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002272 public void onClickAppMarketButton(View v) {
2273 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002274 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002275 } else {
2276 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002277 }
2278 }
2279
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002280 /**
2281 * Called when the user stops interacting with the launcher.
2282 * This implies that the user is now on the homescreen and is not doing housekeeping.
2283 */
2284 protected void onInteractionEnd() {}
2285
2286 /**
2287 * Called when the user starts interacting with the launcher.
2288 * The possible interactions are:
2289 * - open all apps
2290 * - reorder an app shortcut, or a widget
2291 * - open the overview mode.
2292 * This is a good time to stop doing things that only make sense
2293 * when the user is on the homescreen and not doing housekeeping.
2294 */
2295 protected void onInteractionBegin() {}
2296
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002297 void startApplicationDetailsActivity(ComponentName componentName) {
2298 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002299 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2300 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002301 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002302 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002303 }
2304
Michael Jurka1e2f4652013-07-08 18:03:46 -07002305 // returns true if the activity was started
2306 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002307 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002308 // System applications cannot be installed. For now, show a toast explaining that.
2309 // We may give them the option of disabling apps this way.
2310 int messageId = R.string.uninstall_system_app_text;
2311 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002312 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002313 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002314 String packageName = componentName.getPackageName();
2315 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002316 Intent intent = new Intent(
2317 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002318 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2319 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002320 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002321 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002322 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002323 }
2324
Michael Jurka86a720e2012-05-09 11:23:23 -07002325 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002327
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002328 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002329 // Only launch using the new animation if the shortcut has not opted out (this is a
2330 // private contract between launcher and may be ignored in the future).
2331 boolean useLaunchAnimation = (v != null) &&
2332 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2333 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002334 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2335 v.getMeasuredWidth(), v.getMeasuredHeight());
2336
2337 startActivity(intent, opts.toBundle());
2338 } else {
2339 startActivity(intent);
2340 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002341 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 } catch (SecurityException e) {
2343 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002344 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002345 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002346 "or use the exported attribute for this activity. "
2347 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002348 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002349 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002351
Michael Jurka86a720e2012-05-09 11:23:23 -07002352 boolean startActivitySafely(View v, Intent intent, Object tag) {
2353 boolean success = false;
2354 try {
2355 success = startActivity(v, intent, tag);
2356 } catch (ActivityNotFoundException e) {
2357 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2358 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2359 }
2360 return success;
2361 }
2362
Adam Cohena9cf38f2011-05-02 15:36:58 -07002363 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002364 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002365 Folder openFolder = mWorkspace.getFolderForTag(info);
2366
2367 // If the folder info reports that the associated folder is open, then verify that
2368 // it is actually opened. There have been a few instances where this gets out of sync.
2369 if (info.opened && openFolder == null) {
2370 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002371 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002372 info.opened = false;
2373 }
2374
Adam Cohenfb91f302012-06-11 15:45:18 -07002375 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376 // Close any open folder
2377 closeFolder();
2378 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002379 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002380 } else {
2381 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 int folderScreen;
2383 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002384 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 // .. and close it
2386 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002387 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002388 // Close any folder open on the current screen
2389 closeFolder();
2390 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002391 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002392 }
2393 }
2394 }
2395 }
2396
Adam Cohen268c4752012-06-06 17:47:33 -07002397 /**
2398 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2399 * in the DragLayer in the exact absolute location of the original FolderIcon.
2400 */
2401 private void copyFolderIconToImage(FolderIcon fi) {
2402 final int width = fi.getMeasuredWidth();
2403 final int height = fi.getMeasuredHeight();
2404
2405 // Lazy load ImageView, Bitmap and Canvas
2406 if (mFolderIconImageView == null) {
2407 mFolderIconImageView = new ImageView(this);
2408 }
2409 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2410 mFolderIconBitmap.getHeight() != height) {
2411 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2412 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2413 }
2414
2415 DragLayer.LayoutParams lp;
2416 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2417 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2418 } else {
2419 lp = new DragLayer.LayoutParams(width, height);
2420 }
2421
Adam Cohen307fe232012-08-16 17:55:58 -07002422 // The layout from which the folder is being opened may be scaled, adjust the starting
2423 // view size by this scale factor.
2424 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002425 lp.customPosition = true;
2426 lp.x = mRectForFolderAnimation.left;
2427 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002428 lp.width = (int) (scale * width);
2429 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002430
2431 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2432 fi.draw(mFolderIconCanvas);
2433 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002434 if (fi.getFolder() != null) {
2435 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2436 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002437 }
Adam Cohen268c4752012-06-06 17:47:33 -07002438 // Just in case this image view is still in the drag layer from a previous animation,
2439 // we remove it and re-add it.
2440 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2441 mDragLayer.removeView(mFolderIconImageView);
2442 }
2443 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002444 if (fi.getFolder() != null) {
2445 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002446 }
Adam Cohen268c4752012-06-06 17:47:33 -07002447 }
2448
Adam Cohen2801caf2011-05-13 20:57:39 -07002449 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002450 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002451 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2452 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2453 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2454
Adam Cohenc51934b2011-07-26 21:07:43 -07002455 FolderInfo info = (FolderInfo) fi.getTag();
2456 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2457 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002458 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2459 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002460 }
2461
Adam Cohen268c4752012-06-06 17:47:33 -07002462 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2463 copyFolderIconToImage(fi);
2464 fi.setVisibility(View.INVISIBLE);
2465
Michael Jurka2ecf9952012-06-18 12:52:28 -07002466 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002467 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002468 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2469 oa.start();
2470 }
2471
Adam Cohen268c4752012-06-06 17:47:33 -07002472 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002473 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002474 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2475 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2476 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2477
Adam Cohen268c4752012-06-06 17:47:33 -07002478 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002479
Adam Cohen268c4752012-06-06 17:47:33 -07002480 // We remove and re-draw the FolderIcon in-case it has changed
2481 mDragLayer.removeView(mFolderIconImageView);
2482 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002483 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002484 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002485 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002486 oa.addListener(new AnimatorListenerAdapter() {
2487 @Override
2488 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002489 if (cl != null) {
2490 cl.clearFolderLeaveBehind();
2491 // Remove the ImageView copy of the FolderIcon and make the original visible.
2492 mDragLayer.removeView(mFolderIconImageView);
2493 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002494 }
2495 }
2496 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002497 oa.start();
2498 }
2499
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002500 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002501 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502 * is animated relative to the specified View. If the View is null, no animation
2503 * is played.
2504 *
2505 * @param folderInfo The FolderInfo describing the folder to open.
2506 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002507 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002508 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002509 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002510
Adam Cohena9cf38f2011-05-02 15:36:58 -07002511 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002512
Adam Cohen4554ee12011-08-03 16:13:21 -07002513 // Just verify that the folder hasn't already been added to the DragLayer.
2514 // There was a one-off crash where the folder had a parent already.
2515 if (folder.getParent() == null) {
2516 mDragLayer.addView(folder);
2517 mDragController.addDropTarget((DropTarget) folder);
2518 } else {
2519 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2520 folder.getParent() + ").");
2521 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002522 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002523 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002524
2525 // Notify the accessibility manager that this folder "window" has appeared and occluded
2526 // the workspace items
2527 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2528 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002529 }
2530
2531 public void closeFolder() {
2532 Folder folder = mWorkspace.getOpenFolder();
2533 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002534 if (folder.isEditingName()) {
2535 folder.dismissEditingName();
2536 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002537 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002538
2539 // Dismiss the folder cling
2540 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002541 }
2542 }
2543
2544 void closeFolder(Folder folder) {
2545 folder.getInfo().opened = false;
2546
2547 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2548 if (parent != null) {
2549 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2550 shrinkAndFadeInFolderIcon(fi);
2551 }
2552 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002553
2554 // Notify the accessibility manager that this folder "window" has disappeard and no
2555 // longer occludeds the workspace items
2556 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 }
2558
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002559 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002560 if (!isDraggingEnabled()) return false;
2561 if (isWorkspaceLocked()) return false;
2562 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002563
Adam Cohen1697b792013-09-17 19:08:21 -07002564 if (v instanceof Workspace) {
2565 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002566 if (mWorkspace.enterOverviewMode()) {
2567 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2568 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2569 return true;
2570 } else {
2571 return false;
2572 }
Adam Cohen1697b792013-09-17 19:08:21 -07002573 }
Adam Cohen1697b792013-09-17 19:08:21 -07002574 }
2575
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002576 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002577 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002578 }
2579
Michael Jurka0280c3b2010-09-17 15:00:07 -07002580 resetAddInfo();
2581 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002582 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002583 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002584 return true;
2585 }
2586
Winson Chung3d503fb2011-07-13 17:25:49 -07002587 // The hotseat touch handling does not go through Workspace, and we always allow long press
2588 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002589 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002590 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2591 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002592 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002593 // User long pressed on empty space
2594 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2595 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2596 // Disabling reordering until we sort out some issues.
2597 if (mWorkspace.isInOverviewMode()) {
2598 mWorkspace.startReordering(v);
2599 } else {
2600 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002601 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002602 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002603 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002604 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002605 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002606 }
2607 }
2608 }
2609 return true;
2610 }
2611
Winson Chung3d503fb2011-07-13 17:25:49 -07002612 boolean isHotseatLayout(View layout) {
2613 return mHotseat != null && layout != null &&
2614 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2615 }
2616 Hotseat getHotseat() {
2617 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002618 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002619 View getOverviewPanel() {
2620 return mOverviewPanel;
2621 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002622 SearchDropTargetBar getSearchBar() {
2623 return mSearchDropTargetBar;
2624 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002625
Winson Chung3d503fb2011-07-13 17:25:49 -07002626 /**
2627 * Returns the CellLayout of the specified container at the specified screen.
2628 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002629 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002630 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2631 if (mHotseat != null) {
2632 return mHotseat.getLayout();
2633 } else {
2634 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002635 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002636 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002637 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002638 }
2639 }
2640
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002641 Workspace getWorkspace() {
2642 return mWorkspace;
2643 }
2644
Daniel Sandler843e8602010-06-07 14:59:01 -04002645 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002646 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002647 }
2648
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002649 /**
2650 * Helper method for the cameraZoomIn/cameraZoomOut animations
2651 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002652 * @param scaleFactor The scale factor used for the zoom
2653 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002654 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002655 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002656 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002657 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002658
Craig Mautner360310b2012-10-26 15:13:08 -07002659 private void setWorkspaceBackground(boolean workspace) {
2660 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002661 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002662 }
2663
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002664 void updateWallpaperVisibility(boolean visible) {
2665 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2666 int curflags = getWindow().getAttributes().flags
2667 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2668 if (wpflags != curflags) {
2669 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2670 }
Craig Mautner360310b2012-10-26 15:13:08 -07002671 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002672 }
2673
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002674 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2675 if (v instanceof LauncherTransitionable) {
2676 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2677 }
2678 }
2679
Michael Jurkabed61d22012-02-14 22:51:29 -08002680 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2681 if (v instanceof LauncherTransitionable) {
2682 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2683 }
Winson Chung70442722012-02-10 15:43:22 -08002684
2685 // Update the workspace transition step as well
2686 dispatchOnLauncherTransitionStep(v, 0f);
2687 }
2688
2689 private void dispatchOnLauncherTransitionStep(View v, float t) {
2690 if (v instanceof LauncherTransitionable) {
2691 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2692 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002693 }
2694
2695 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2696 if (v instanceof LauncherTransitionable) {
2697 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2698 }
Winson Chung70442722012-02-10 15:43:22 -08002699
2700 // Update the workspace transition step as well
2701 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002702 }
2703
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002704 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002705 * Things to test when changing the following seven functions.
2706 * - Home from workspace
2707 * - from center screen
2708 * - from other screens
2709 * - Home from all apps
2710 * - from center screen
2711 * - from other screens
2712 * - Back from all apps
2713 * - from center screen
2714 * - from other screens
2715 * - Launch app from workspace and quit
2716 * - with back
2717 * - with home
2718 * - Launch app from all apps and quit
2719 * - with back
2720 * - with home
2721 * - Go to a screen that's not the default, then all
2722 * apps, and launch and app, and go back
2723 * - with back
2724 * -with home
2725 * - On workspace, long press power and go back
2726 * - with back
2727 * - with home
2728 * - On all apps, long press power and go back
2729 * - with back
2730 * - with home
2731 * - On workspace, power off
2732 * - On all apps, power off
2733 * - Launch an app and turn off the screen while in that app
2734 * - Go back with home key
2735 * - Go back with back key TODO: make this not go to workspace
2736 * - From all apps
2737 * - From workspace
2738 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2739 * - From all apps
2740 * - From the center workspace
2741 * - From another workspace
2742 */
2743
2744 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002745 * Zoom the camera out from the workspace to reveal 'toView'.
2746 * Assumes that the view to show is anchored at either the very top or very bottom
2747 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002748 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002749 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002750 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2751 showAppsCustomizeHelper(animated, springLoaded, contentType);
2752 }
2753 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2754 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002755 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002756 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002757 mStateAnimation.cancel();
2758 mStateAnimation = null;
2759 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002760 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002761
Winson Chungf0ea4d32011-06-06 14:27:16 -07002762 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2763 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2764 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002765 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002766 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002767 final int startDelay =
2768 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002769
Michael Jurkab3e22d92011-10-31 15:58:33 -07002770 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002771
Michael Jurkad74c9842011-07-10 12:44:21 -07002772 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002773 Animator workspaceAnim =
2774 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002775 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2776 // Set the content type for the all apps space
2777 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2778 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002779
2780 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002781 toView.setScaleX(scale);
2782 toView.setScaleY(scale);
2783 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2784 scaleAnim.
2785 scaleX(1f).scaleY(1f).
2786 setDuration(duration).
2787 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002788
Winson Chungf0ea4d32011-06-06 14:27:16 -07002789 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002790 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002791 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002792 .ofFloat(toView, "alpha", 0f, 1f)
2793 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002794 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002795 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2796 @Override
2797 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002798 if (animation == null) {
2799 throw new RuntimeException("animation is null");
2800 }
Winson Chung70442722012-02-10 15:43:22 -08002801 float t = (Float) animation.getAnimatedValue();
2802 dispatchOnLauncherTransitionStep(fromView, t);
2803 dispatchOnLauncherTransitionStep(toView, t);
2804 }
2805 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002806
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002807 // toView should appear right at the end of the workspace shrink
2808 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002809 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002810 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002811 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002812
2813 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002814 boolean animationCancelled = false;
2815
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002816 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002817 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002818 // Prepare the position
2819 toView.setTranslationX(0.0f);
2820 toView.setTranslationY(0.0f);
2821 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002822 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002823 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002824 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002825 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002826 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2827 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002828
Winson Chungc7d2b602012-05-16 17:02:20 -07002829 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002830 if (mSearchDropTargetBar != null) {
2831 mSearchDropTargetBar.hideSearchBar(false);
2832 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002833 }
2834
Adam Cohencff6af82011-09-13 14:51:53 -07002835 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002836 public void onAnimationCancel(Animator animation) {
2837 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002838 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002839 });
2840
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002841 if (workspaceAnim != null) {
2842 mStateAnimation.play(workspaceAnim);
2843 }
Michael Jurka1899a362011-11-03 13:50:45 -07002844
2845 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002846
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002847 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2848 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849
2850 // If any of the objects being animated haven't been measured/laid out
2851 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002852 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853 (mWorkspace.getMeasuredWidth() == 0) ||
2854 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002856 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002858 final AnimatorSet stateAnimation = mStateAnimation;
2859 final Runnable startAnimRunnable = new Runnable() {
2860 public void run() {
2861 // Check that mStateAnimation hasn't changed while
2862 // we waited for a layout/draw pass
2863 if (mStateAnimation != stateAnimation)
2864 return;
2865 setPivotsForZoom(toView, scale);
2866 dispatchOnLauncherTransitionStart(fromView, animated, false);
2867 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002868 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002869 }
2870 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002871 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002872 final ViewTreeObserver observer = toView.getViewTreeObserver();
2873 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2874 public void onGlobalLayout() {
2875 startAnimRunnable.run();
2876 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2877 }
2878 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002879 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002880 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002881 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002882 } else {
2883 toView.setTranslationX(0.0f);
2884 toView.setTranslationY(0.0f);
2885 toView.setScaleX(1.0f);
2886 toView.setScaleY(1.0f);
2887 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002888 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002889
Daniel Sandlere4f98912013-06-25 15:13:26 -04002890 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002891 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002892 if (mSearchDropTargetBar != null) {
2893 mSearchDropTargetBar.hideSearchBar(false);
2894 }
Michael Jurkaabded662011-03-04 12:06:57 -08002895 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002896 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002897 dispatchOnLauncherTransitionStart(fromView, animated, false);
2898 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002899 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002900 dispatchOnLauncherTransitionStart(toView, animated, false);
2901 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002902 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002903 }
2904
2905 /**
2906 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002907 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002908 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002909 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002910 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2911 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002912
Michael Jurkab3e22d92011-10-31 15:58:33 -07002913 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002914 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002915 mStateAnimation.cancel();
2916 mStateAnimation = null;
2917 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002918 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002919
Winson Chungf0ea4d32011-06-06 14:27:16 -07002920 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002921 final int fadeOutDuration =
2922 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002923 final float scaleFactor = (float)
2924 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2925 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002926 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002927 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002928 if (toState == State.WORKSPACE) {
2929 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2930 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002931 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002932 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2933 workspaceAnim = mWorkspace.getChangeStateAnimation(
2934 Workspace.State.SPRING_LOADED, animated);
2935 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002936
Michael Jurkab3e22d92011-10-31 15:58:33 -07002937 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002938 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002939 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002940 final LauncherViewPropertyAnimator scaleAnim =
2941 new LauncherViewPropertyAnimator(fromView);
2942 scaleAnim.
2943 scaleX(scaleFactor).scaleY(scaleFactor).
2944 setDuration(duration).
2945 setInterpolator(new Workspace.ZoomInInterpolator());
2946
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002947 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002948 .ofFloat(fromView, "alpha", 1f, 0f)
2949 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002950 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002951 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2952 @Override
2953 public void onAnimationUpdate(ValueAnimator animation) {
2954 float t = 1f - (Float) animation.getAnimatedValue();
2955 dispatchOnLauncherTransitionStep(fromView, t);
2956 dispatchOnLauncherTransitionStep(toView, t);
2957 }
2958 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002959
Michael Jurka2ecf9952012-06-18 12:52:28 -07002960 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002961
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002962 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2963 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002964 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002965
2966 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002967 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002968 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002969 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002970 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2971 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002972 if (onCompleteRunnable != null) {
2973 onCompleteRunnable.run();
2974 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002975 mAppsCustomizeContent.updateCurrentPageScroll();
2976 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002977 }
2978 });
2979
Winson Chungf0ea4d32011-06-06 14:27:16 -07002980 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002981 if (workspaceAnim != null) {
2982 mStateAnimation.play(workspaceAnim);
2983 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002984 dispatchOnLauncherTransitionStart(fromView, animated, true);
2985 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002986 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002987 } else {
2988 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002989 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002990 dispatchOnLauncherTransitionStart(fromView, animated, true);
2991 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002992 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002993 dispatchOnLauncherTransitionStart(toView, animated, true);
2994 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002995 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002996 }
2997
Michael Jurkae326f182011-11-21 14:05:46 -08002998 @Override
2999 public void onTrimMemory(int level) {
3000 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003001 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003002 mAppsCustomizeTabHost.onTrimMemory();
3003 }
3004 }
3005
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003006 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003007 showWorkspace(animated, null);
3008 }
3009
3010 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003011 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003012 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003013 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003014 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003015
Winson Chungc7d2b602012-05-16 17:02:20 -07003016 // Show the search bar (only animate if we were showing the drop target bar in spring
3017 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003018 if (mSearchDropTargetBar != null) {
3019 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3020 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003021
Michael Jurkab3e22d92011-10-31 15:58:33 -07003022 // Set focus to the AppsCustomize button
3023 if (mAllAppsButton != null) {
3024 mAllAppsButton.requestFocus();
3025 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003026 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003027
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003028 // Change the state *after* we've called all the transition code
3029 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003030
Winson Chung5fb63472011-02-02 17:03:37 -08003031 // Resume the auto-advance of widgets
3032 mUserPresent = true;
3033 updateRunning();
3034
alanv1d4fde62012-10-17 13:15:47 -07003035 // Send an accessibility event to announce the context change
3036 getWindow().getDecorView()
3037 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003038
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003039 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003040 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003041 }
3042
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003043 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003044 }
3045
Winson Chungc58497e2013-09-03 17:48:37 -07003046 void showAllApps(boolean animated,
3047 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 if (mState != State.WORKSPACE) return;
3049
Winson Chungc58497e2013-09-03 17:48:37 -07003050 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051 mAppsCustomizeTabHost.requestFocus();
3052
Michael Jurkab3e22d92011-10-31 15:58:33 -07003053 // Change the state *after* we've called all the transition code
3054 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003055 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003056
3057 // Pause the auto-advance of widgets until we are out of AllApps
3058 mUserPresent = false;
3059 updateRunning();
3060 closeFolder();
3061
3062 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003063 getWindow().getDecorView()
3064 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003065 }
3066
Adam Cohen7777d962011-08-18 18:58:38 -07003067 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003068 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003069 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003070 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003071 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003072 }
Adam Cohen7777d962011-08-18 18:58:38 -07003073
Adam Cohened66b2b2012-01-23 17:28:51 -08003074 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3075 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003076 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3077
Winson Chunge7a03942011-08-05 15:05:12 -07003078 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003079 @Override
3080 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003081 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003082 // Before we show workspace, hide all apps again because
3083 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3084 // clean up our state transition functions
3085 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003086 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003087 } else {
3088 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003089 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003090 }
3091 }, (extendedDelay ?
3092 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3093 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3094 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003095
Michael Jurkad3ef3062010-11-23 16:23:58 -08003096 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003097 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003098 final boolean animated = true;
3099 final boolean springLoaded = true;
3100 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003101 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003102 }
3103 // Otherwise, we are not in spring loaded mode, so don't do anything.
3104 }
3105
Michael Jurkab3e22d92011-10-31 15:58:33 -07003106 void lockAllApps() {
3107 // TODO
3108 }
3109
3110 void unlockAllApps() {
3111 // TODO
3112 }
3113
Winson Chungf0ea4d32011-06-06 14:27:16 -07003114 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003115 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003116 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003117 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003118 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003119 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003120 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003121 int duration = 0;
3122 if (mSearchDropTargetBar != null) {
3123 duration = mSearchDropTargetBar.getTransitionInDuration();
3124 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003125 mHotseat.animate().alpha(1f).setDuration(duration);
3126 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003127 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003128 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003129 }
3130 }
3131 }
3132
3133 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003134 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003135 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003136 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003137 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003138 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003139 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003140 int duration = 0;
3141 if (mSearchDropTargetBar != null) {
3142 duration = mSearchDropTargetBar.getTransitionOutDuration();
3143 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003144 mHotseat.animate().alpha(0f).setDuration(duration);
3145 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003146 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003147 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003148 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003149 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003150 }
3151
Patrick Dubroy5f445422011-02-18 14:35:21 -08003152 /**
3153 * Add an item from all apps or customize onto the given workspace screen.
3154 * If layout is null, add to the current screen.
3155 */
3156 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003157 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003158 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003159 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003160 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003161
Winson Chungdff8ebb2011-09-08 17:25:31 -07003162 /** Maps the current orientation to an index for referencing orientation correct global icons */
3163 private int getCurrentOrientationIndexForGlobalIcons() {
3164 // default - 0, landscape - 1
3165 switch (getResources().getConfiguration().orientation) {
3166 case Configuration.ORIENTATION_LANDSCAPE:
3167 return 1;
3168 default:
3169 return 0;
3170 }
3171 }
3172
Michael Jurkaae65ee32012-04-30 11:45:54 -07003173 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003174 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003175 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003176 // Look for the toolbar icon specified in the activity meta-data
3177 Bundle metaData = packageManager.getActivityInfo(
3178 activityName, PackageManager.GET_META_DATA).metaData;
3179 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003180 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003181 if (iconResId != 0) {
3182 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003183 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003184 }
3185 }
3186 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003187 // This can happen if the activity defines an invalid drawable
3188 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3189 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003190 } catch (Resources.NotFoundException nfe) {
3191 // This can happen if the activity defines an invalid drawable
3192 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3193 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003194 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003195 return null;
3196 }
3197
3198 // if successful in getting icon, return it; otherwise, set button to use default drawable
3199 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003200 int buttonId, ComponentName activityName, int fallbackDrawableId,
3201 String toolbarResourceName) {
3202 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003203 Resources r = getResources();
3204 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3205 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003206
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003207 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003208 // If we were unable to find the icon via the meta-data, use a generic one
3209 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003210 toolbarIcon = r.getDrawable(fallbackDrawableId);
3211 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003212 if (button != null) {
3213 button.setCompoundDrawables(toolbarIcon, null, null, null);
3214 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003215 return null;
3216 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003217 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003218 if (button != null) {
3219 button.setCompoundDrawables(toolbarIcon, null, null, null);
3220 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003221 return toolbarIcon.getConstantState();
3222 }
3223 }
3224
3225 // if successful in getting icon, return it; otherwise, set button to use default drawable
3226 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003227 int buttonId, ComponentName activityName, int fallbackDrawableId,
3228 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003229 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003230 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003231
Michael Jurka19e0fc52011-07-22 18:00:21 -07003232 if (button != null) {
3233 // If we were unable to find the icon via the meta-data, use a
3234 // generic one
3235 if (toolbarIcon == null) {
3236 button.setImageResource(fallbackDrawableId);
3237 } else {
3238 button.setImageDrawable(toolbarIcon);
3239 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003240 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003241
3242 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3243
Michael Jurka0423dcf2010-10-05 14:56:18 -07003244 }
3245
Winson Chung1b884092012-06-08 17:13:02 -07003246 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003247 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003248 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003249 }
3250
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003251 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003252 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003253 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003254 }
3255
Winson Chungbb185bd2011-11-21 12:31:42 -08003256 private void invalidatePressedFocusedStates(View container, View button) {
3257 if (container instanceof HolographicLinearLayout) {
3258 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3259 layout.invalidatePressedFocusedStates();
3260 } else if (button instanceof HolographicImageView) {
3261 HolographicImageView view = (HolographicImageView) button;
3262 view.invalidatePressedFocusedStates();
3263 }
3264 }
3265
Cristina Stancu476493b2013-08-07 17:20:14 +01003266 public View getQsbBar() {
3267 if (mQsbBar == null) {
3268 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3269 }
3270 return mQsbBar;
3271 }
3272
3273 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003274 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003275 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003276 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003277 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003278
Winson Chung1cad91e2011-05-25 17:41:01 -07003279 final SearchManager searchManager =
3280 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3281 ComponentName activityName = searchManager.getGlobalSearchActivity();
3282 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003283 int coi = getCurrentOrientationIndexForGlobalIcons();
3284 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003285 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3286 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3287 if (sGlobalSearchIcon[coi] == null) {
3288 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3289 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3290 TOOLBAR_ICON_METADATA_NAME);
3291 }
3292
Winson Chungc51db6a2011-10-05 11:44:49 -07003293 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3294 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003295 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003296 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003297 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003298 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003299 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3300 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003301 if (searchButton != null) searchButton.setVisibility(View.GONE);
3302 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003303 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003304 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003305 }
3306 }
3307
Cristina Stancu476493b2013-08-07 17:20:14 +01003308 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003309 final View searchButtonContainer = findViewById(R.id.search_button_container);
3310 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003311 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003312 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003313 }
3314
Cristina Stancu476493b2013-08-07 17:20:14 +01003315 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003316 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003317 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003318
Winson Chungc51db6a2011-10-05 11:44:49 -07003319 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003320 final SearchManager searchManager =
3321 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3322 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3323
3324 ComponentName activityName = null;
3325 if (globalSearchActivity != null) {
3326 // Check if the global search activity handles voice search
3327 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3328 intent.setPackage(globalSearchActivity.getPackageName());
3329 activityName = intent.resolveActivity(getPackageManager());
3330 }
3331
3332 if (activityName == null) {
3333 // Fallback: check if an activity other than the global search activity
3334 // resolves this
3335 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3336 activityName = intent.resolveActivity(getPackageManager());
3337 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003338 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003339 int coi = getCurrentOrientationIndexForGlobalIcons();
3340 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003341 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3342 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3343 if (sVoiceSearchIcon[coi] == null) {
3344 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3345 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3346 TOOLBAR_ICON_METADATA_NAME);
3347 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003348 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003349 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003350 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003351 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003352 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003353 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003354 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003355 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003356 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003357 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003358 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003359 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003360
Cristina Stancu476493b2013-08-07 17:20:14 +01003361 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003362 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3363 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003364 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003365 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003366 }
3367
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003368 public void setVoiceButtonProxyVisible(boolean visible) {
3369 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3370 if (voiceButtonProxy != null) {
3371 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3372 }
3373 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003374 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003375 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003376 */
3377 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003378 final View marketButton = findViewById(R.id.market_button);
3379 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3380 // Find the app market activity by resolving an intent.
3381 // (If multiple app markets are installed, it will return the ResolverActivity.)
3382 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003383 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003384 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003385 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003386 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003387 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3388 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003389 marketButton.setVisibility(View.VISIBLE);
3390 } else {
3391 // We should hide and disable the view so that we don't try and restore the visibility
3392 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3393 marketButton.setVisibility(View.GONE);
3394 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003395 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003396 }
3397
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003398 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003399 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3400 Resources r = getResources();
3401 Drawable marketIconDrawable = d.newDrawable(r);
3402 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3403 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3404 marketIconDrawable.setBounds(0, 0, w, h);
3405
3406 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003407 }
3408
Michael Jurkad7c28052012-04-27 15:43:36 -07003409 @Override
3410 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003411 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003412 final List<CharSequence> text = event.getText();
3413 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003414 // Populate event with a fake title based on the current state.
3415 if (mState == State.APPS_CUSTOMIZE) {
3416 text.add(getString(R.string.all_apps_button_label));
3417 } else {
3418 text.add(getString(R.string.all_apps_home_button_label));
3419 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003420 return result;
3421 }
3422
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003423 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003424 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003425 */
3426 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3427 @Override
3428 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003429 closeSystemDialogs();
3430 }
3431 }
3432
3433 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003434 * Receives notifications whenever the appwidgets are reset.
3435 */
3436 private class AppWidgetResetObserver extends ContentObserver {
3437 public AppWidgetResetObserver() {
3438 super(new Handler());
3439 }
3440
3441 @Override
3442 public void onChange(boolean selfChange) {
3443 onAppWidgetReset();
3444 }
3445 }
3446
3447 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003448 * If the activity is currently paused, signal that we need to run the passed Runnable
3449 * in onResume.
3450 *
3451 * This needs to be called from incoming places where resources might have been loaded
3452 * while we are paused. That is becaues the Configuration might be wrong
3453 * when we're not running, and if it comes back to what it was when we
3454 * were paused, we are not restarted.
3455 *
3456 * Implementation of the method from LauncherModel.Callbacks.
3457 *
3458 * @return true if we are currently paused. The caller might be able to
3459 * skip some work in that case since we will come back again.
3460 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003461 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003462 if (mPaused) {
3463 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003464 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003465 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003466 }
3467 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003468 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003469 return true;
3470 } else {
3471 return false;
3472 }
3473 }
3474
Michael Jurkac402cd92013-05-20 15:49:32 +02003475 private boolean waitUntilResume(Runnable run) {
3476 return waitUntilResume(run, false);
3477 }
3478
Michael Jurka1e2f4652013-07-08 18:03:46 -07003479 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003480 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003481 }
3482
Michael Jurka7607c2f2013-04-03 14:33:19 -07003483 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003484 * If the activity is currently paused, signal that we need to re-run the loader
3485 * in onResume.
3486 *
3487 * This needs to be called from incoming places where resources might have been loaded
3488 * while we are paused. That is becaues the Configuration might be wrong
3489 * when we're not running, and if it comes back to what it was when we
3490 * were paused, we are not restarted.
3491 *
3492 * Implementation of the method from LauncherModel.Callbacks.
3493 *
3494 * @return true if we are currently paused. The caller might be able to
3495 * skip some work in that case since we will come back again.
3496 */
3497 public boolean setLoadOnResume() {
3498 if (mPaused) {
3499 Log.i(TAG, "setLoadOnResume");
3500 mOnResumeNeedsLoad = true;
3501 return true;
3502 } else {
3503 return false;
3504 }
3505 }
3506
3507 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003508 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003509 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003510 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003511 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003512 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003513 } else {
3514 return SCREEN_COUNT / 2;
3515 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003516 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003517
Joe Onorato9c1289c2009-08-17 11:03:03 -04003518 /**
3519 * Refreshes the shortcuts shown on the workspace.
3520 *
3521 * Implementation of the method from LauncherModel.Callbacks.
3522 */
3523 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003524 // If we're starting binding all over again, clear any bind calls we'd postponed in
3525 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3526 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003527 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003528
Winson Chungd64d1762013-08-20 14:37:16 -07003529 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003530 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003531 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003532
Michael Jurka05bf6442011-11-30 20:28:53 -08003533 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003534 if (mHotseat != null) {
3535 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003536 }
3537 }
3538
Adam Cohendcd297f2013-06-18 13:13:40 -07003539 @Override
3540 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003541 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003542
Adam Cohen5084cba2013-09-03 12:01:16 -07003543 // If there are no screens, we need to have an empty screen
3544 if (orderedScreenIds.size() == 0) {
3545 mWorkspace.addExtraEmptyScreen();
3546 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003547
3548 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003549 // setCurrentPage() so ensure that all pages are added before calling this).
3550 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003551 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3552 mWorkspace.createCustomContentPage();
3553 }
Winson Chung64359a52013-07-08 17:17:08 -07003554 }
3555
3556 @Override
3557 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003558 int count = orderedScreenIds.size();
3559 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003560 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003561 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003562 }
3563
Adam Cohen39a06042013-07-19 14:30:12 -07003564 private boolean shouldShowWeightWatcher() {
3565 String spKey = LauncherAppState.getSharedPreferencesKey();
3566 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003567 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003568
3569 return show;
3570 }
3571
Adam Cohen4caf2982013-08-20 18:54:31 -07003572 private boolean emailSent() {
3573 String spKey = LauncherAppState.getSharedPreferencesKey();
3574 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3575 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3576 return show;
3577 }
3578
3579 private void setEmailSent(boolean sent) {
3580 String spKey = LauncherAppState.getSharedPreferencesKey();
3581 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3582
3583 SharedPreferences.Editor editor = sp.edit();
3584 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3585 editor.commit();
3586 }
3587
Adam Cohen39a06042013-07-19 14:30:12 -07003588 private void toggleShowWeightWatcher() {
3589 String spKey = LauncherAppState.getSharedPreferencesKey();
3590 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3591 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3592
3593 show = !show;
3594
3595 SharedPreferences.Editor editor = sp.edit();
3596 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3597 editor.commit();
3598
3599 if (mWeightWatcher != null) {
3600 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3601 }
3602 }
3603
Winson Chungd64d1762013-08-20 14:37:16 -07003604 public void bindAppsAdded(final ArrayList<Long> newScreens,
3605 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003606 final ArrayList<ItemInfo> addAnimated,
3607 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003608 Runnable r = new Runnable() {
3609 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003610 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003611 }
3612 };
3613 if (waitUntilResume(r)) {
3614 return;
3615 }
3616
Winson Chungd64d1762013-08-20 14:37:16 -07003617 // Add the new screens
3618 bindAddScreens(newScreens);
3619
3620 // We add the items without animation on non-visible pages, and with
3621 // animations on the new page (which we will try and snap to).
3622 if (!addNotAnimated.isEmpty()) {
3623 bindItems(addNotAnimated, 0,
3624 addNotAnimated.size(), false);
3625 }
3626 if (!addAnimated.isEmpty()) {
3627 bindItems(addAnimated, 0,
3628 addAnimated.size(), true);
3629 }
Winson Chungc58497e2013-09-03 17:48:37 -07003630
3631 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3632 addedApps != null && mAppsCustomizeContent != null) {
3633 mAppsCustomizeContent.addApps(addedApps);
3634 }
Winson Chungd64d1762013-08-20 14:37:16 -07003635 }
3636
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003637 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003638 * Bind the items start-end from the list.
3639 *
3640 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003641 */
Winson Chung64359a52013-07-08 17:17:08 -07003642 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3643 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003644 Runnable r = new Runnable() {
3645 public void run() {
3646 bindItems(shortcuts, start, end, forceAnimateIcons);
3647 }
3648 };
3649 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003650 return;
3651 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003652
Winson Chungf0c6ae02012-03-21 16:10:31 -07003653 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003654 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3655 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003656 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003657 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003658 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003659 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003660 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003661
3662 // Short circuit if we are loading dock items for a configuration which has no dock
3663 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3664 mHotseat == null) {
3665 continue;
3666 }
3667
Joe Onorato9c1289c2009-08-17 11:03:03 -04003668 switch (item.itemType) {
3669 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3670 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003671 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003672 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003673
Winson Chung64359a52013-07-08 17:17:08 -07003674 /*
3675 * TODO: FIX collision case
3676 */
Winson Chungce376632013-07-11 16:12:41 -07003677 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3678 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3679 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3680 throw new RuntimeException("OCCUPIED");
3681 }
Winson Chung64359a52013-07-08 17:17:08 -07003682 }
3683
Adam Cohendcd297f2013-06-18 13:13:40 -07003684 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3685 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003686 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003687 // Animate all the applications up now
3688 shortcut.setAlpha(0f);
3689 shortcut.setScaleX(0f);
3690 shortcut.setScaleY(0f);
3691 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003692 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003694 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003695 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003696 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003697 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003698 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003699 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3700 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003701 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003702 default:
3703 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003704 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003705 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003706
Winson Chung997a9232013-07-24 15:33:46 -07003707 if (animateIcons) {
3708 // Animate to the correct page
3709 if (newShortcutsScreenId > -1) {
3710 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003711 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003712 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003713 // We post the animation slightly delayed to prevent slowdowns
3714 // when we are loading right after we return to launcher.
3715 mWorkspace.postDelayed(new Runnable() {
3716 public void run() {
3717 mWorkspace.snapToPage(newScreenIndex);
3718 mWorkspace.postDelayed(new Runnable() {
3719 public void run() {
3720 anim.playTogether(bounceAnims);
3721 anim.start();
3722 }
3723 }, NEW_APPS_ANIMATION_DELAY);
3724 }
3725 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003726 }
3727 }
Winson Chung64359a52013-07-08 17:17:08 -07003728 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003729 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003730 }
3731
Joe Onorato9c1289c2009-08-17 11:03:03 -04003732 /**
3733 * Implementation of the method from LauncherModel.Callbacks.
3734 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003735 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003736 Runnable r = new Runnable() {
3737 public void run() {
3738 bindFolders(folders);
3739 }
3740 };
3741 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003742 return;
3743 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003744 sFolders.clear();
3745 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003746 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747
3748 /**
3749 * Add the views for a widget to the workspace.
3750 *
3751 * Implementation of the method from LauncherModel.Callbacks.
3752 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003753 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003754 Runnable r = new Runnable() {
3755 public void run() {
3756 bindAppWidget(item);
3757 }
3758 };
3759 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003760 return;
3761 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003762
Daniel Sandler843e8602010-06-07 14:59:01 -04003763 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3764 if (DEBUG_WIDGETS) {
3765 Log.d(TAG, "bindAppWidget: " + item);
3766 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767 final Workspace workspace = mWorkspace;
3768
3769 final int appWidgetId = item.appWidgetId;
3770 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003771 if (DEBUG_WIDGETS) {
3772 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3773 }
3774
Joe Onorato9c1289c2009-08-17 11:03:03 -04003775 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3776
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003778 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003779
Adam Cohendcd297f2013-06-18 13:13:40 -07003780 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003781 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003782 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3783
Joe Onorato9c1289c2009-08-17 11:03:03 -04003784 workspace.requestLayout();
3785
Daniel Sandler843e8602010-06-07 14:59:01 -04003786 if (DEBUG_WIDGETS) {
3787 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3788 + (SystemClock.uptimeMillis()-start) + "ms");
3789 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003790 }
3791
Adam Cohen1462de32012-07-24 22:34:36 -07003792 public void onPageBoundSynchronously(int page) {
3793 mSynchronouslyBoundPages.add(page);
3794 }
3795
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 /**
3797 * Callback saying that there aren't any more items to bind.
3798 *
3799 * Implementation of the method from LauncherModel.Callbacks.
3800 */
Adam Cohene25af792013-06-06 23:08:25 -07003801 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003802 Runnable r = new Runnable() {
3803 public void run() {
3804 finishBindingItems(upgradePath);
3805 }
3806 };
3807 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003808 return;
3809 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003810 if (mSavedState != null) {
3811 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003812 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003813 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003814 mSavedState = null;
3815 }
3816
Adam Cohen1462de32012-07-24 22:34:36 -07003817 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003819 // If we received the result of any pending adds while the loader was running (e.g. the
3820 // widget configuration forced an orientation change), process them now.
3821 for (int i = 0; i < sPendingAddList.size(); i++) {
3822 completeAdd(sPendingAddList.get(i));
3823 }
3824 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003825
Winson Chungc51db6a2011-10-05 11:44:49 -07003826 // Update the market app icon as necessary (the other icons will be managed in response to
3827 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003828 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003829
Winson Chungf0c6ae02012-03-21 16:10:31 -07003830 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003831 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003832 mWorkspace.getUniqueComponents(true, null);
3833 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003834 }
Adam Cohen99894d92013-06-14 11:22:59 -07003835
Adam Cohen66a01fd2013-06-11 12:48:00 -07003836 mWorkspace.post(new Runnable() {
3837 @Override
3838 public void run() {
3839 onFinishBindingItems();
3840 }
3841 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003842 }
3843
Winson Chunga0b7e862013-09-05 16:03:15 -07003844 public boolean isAllAppsButtonRank(int rank) {
3845 if (mHotseat != null) {
3846 return mHotseat.isAllAppsButtonRank(rank);
3847 }
3848 return false;
3849 }
3850
Winson Chunga2413752012-04-03 14:22:34 -07003851 private boolean canRunNewAppsAnimation() {
3852 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3853 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3854 }
3855
Winson Chungc9168342013-06-26 14:54:55 -07003856 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3857 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3858 PropertyValuesHolder.ofFloat("alpha", 1f),
3859 PropertyValuesHolder.ofFloat("scaleX", 1f),
3860 PropertyValuesHolder.ofFloat("scaleY", 1f));
3861 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3862 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3863 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3864 return bounceAnim;
3865 }
3866
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003867 @Override
3868 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003869 boolean searchVisible = updateGlobalSearchIcon();
3870 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003871 if (mSearchDropTargetBar != null) {
3872 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3873 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003874 }
3875
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003876 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003877 * Add the icons for all apps.
3878 *
3879 * Implementation of the method from LauncherModel.Callbacks.
3880 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003881 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003882 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3883 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3884 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3885 getHotseat().addAllAppsFolder(mIconCache, apps,
3886 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3887 }
3888 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003889 }
Winson Chungc58497e2013-09-03 17:48:37 -07003890 } else {
3891 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3892 mAppsCustomizeContent != null) {
3893 mAppsCustomizeContent.setApps(apps);
3894 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003895 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003896 }
3897
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003898 @Override
3899 public boolean shouldShowApp(ResolveInfo app) {
3900 return true;
3901 }
3902
Joe Onorato9c1289c2009-08-17 11:03:03 -04003903 /**
3904 * A package was updated.
3905 *
3906 * Implementation of the method from LauncherModel.Callbacks.
3907 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003908 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003909 Runnable r = new Runnable() {
3910 public void run() {
3911 bindAppsUpdated(apps);
3912 }
3913 };
3914 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003915 return;
3916 }
3917
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003918 if (mWorkspace != null) {
3919 mWorkspace.updateShortcuts(apps);
3920 }
Winson Chungc58497e2013-09-03 17:48:37 -07003921
3922 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3923 mAppsCustomizeContent != null) {
3924 mAppsCustomizeContent.updateApps(apps);
3925 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003926 }
3927
3928 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003929 * A package was uninstalled. We take both the super set of packageNames
3930 * in addition to specific applications to remove, the reason being that
3931 * this can be called when a package is updated as well. In that scenario,
3932 * we only remove specific components from the workspace, where as
3933 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003934 *
3935 * Implementation of the method from LauncherModel.Callbacks.
3936 */
Winson Chung83892cc2013-05-01 16:53:33 -07003937 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003938 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003939 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003940 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003941 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003942 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003943 }
Winson Chungd64d1762013-08-20 14:37:16 -07003944 };
3945 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003946 return;
3947 }
3948
Winson Chung64359a52013-07-08 17:17:08 -07003949 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003950 mWorkspace.removeItemsByPackageName(packageNames);
3951 } else {
3952 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003953 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003954
Winson Chunga1820962011-10-03 16:31:06 -07003955 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003956 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003957
3958 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3959 mAppsCustomizeContent != null) {
3960 mAppsCustomizeContent.removeApps(appInfos);
3961 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003962 }
Joe Onoratobe386092009-11-17 17:32:16 -08003963
3964 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003965 * A number of packages were updated.
3966 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003967 private ArrayList<Object> mWidgetsAndShortcuts;
3968 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003969 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003970 bindPackagesUpdated(mWidgetsAndShortcuts);
3971 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003972 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003973 };
3974
3975 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3976 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3977 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003978 return;
3979 }
3980
Winson Chung64359a52013-07-08 17:17:08 -07003981 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003982 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3983 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003984 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003985 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003986 }
3987
Winson Chung400438b2011-01-16 17:53:48 -08003988 private int mapConfigurationOriActivityInfoOri(int configOri) {
3989 final Display d = getWindowManager().getDefaultDisplay();
3990 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3991 switch (d.getRotation()) {
3992 case Surface.ROTATION_0:
3993 case Surface.ROTATION_180:
3994 // We are currently in the same basic orientation as the natural orientation
3995 naturalOri = configOri;
3996 break;
3997 case Surface.ROTATION_90:
3998 case Surface.ROTATION_270:
3999 // We are currently in the other basic orientation to the natural orientation
4000 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4001 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4002 break;
4003 }
4004
4005 int[] oriMap = {
4006 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4007 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4008 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4009 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4010 };
4011 // Since the map starts at portrait, we need to offset if this device's natural orientation
4012 // is landscape.
4013 int indexOffset = 0;
4014 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4015 indexOffset = 1;
4016 }
4017 return oriMap[(d.getRotation() + indexOffset) % 4];
4018 }
Adam Cohen446e9402011-09-15 18:21:21 -07004019
Winson Chung4b919f82012-05-01 10:44:08 -07004020 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004021 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004022 getResources().getBoolean(R.bool.allow_rotation);
4023 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004024 }
Winson Chung4b919f82012-05-01 10:44:08 -07004025 public void lockScreenOrientation() {
4026 if (isRotationEnabled()) {
4027 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4028 .getConfiguration().orientation));
4029 }
4030 }
4031 public void unlockScreenOrientation(boolean immediate) {
4032 if (isRotationEnabled()) {
4033 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004034 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004035 } else {
4036 mHandler.postDelayed(new Runnable() {
4037 public void run() {
4038 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4039 }
4040 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004041 }
Winson Chung4b919f82012-05-01 10:44:08 -07004042 }
Winson Chung400438b2011-01-16 17:53:48 -08004043 }
4044
Winson Chung82f55532011-08-09 14:14:23 -07004045 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004046 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004047 if (DISABLE_CLINGS) {
4048 return false;
4049 }
4050
Brett Chabot2a9e2282011-08-23 15:03:13 -07004051 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004052 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004053
Michael Jurkae233a8b2013-03-19 13:49:20 +01004054 // Restricted secondary users (child mode) will potentially have very few apps
4055 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004056// boolean supportsLimitedUsers =
4057// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4058// Account[] accounts = AccountManager.get(this).getAccounts();
4059// if (supportsLimitedUsers && accounts.length == 0) {
4060// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4061// Bundle restrictions = um.getUserRestrictions();
4062// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4063// return false;
4064// }
4065// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004066 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004067 }
Michael Jurka22143132012-10-04 17:42:38 +02004068
Winson Chungfa545132013-09-26 17:45:32 -07004069 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004070 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004071 Cling cling = (Cling) findViewById(clingId);
4072 View scrim = null;
4073 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004074 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004075 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004076 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004077 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004078 cling.show(animate, SHOW_CLING_DURATION);
4079
4080 if (dimNavBarVisibilty) {
4081 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4082 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004083 }
4084 }
4085 return cling;
4086 }
Michael Jurka22143132012-10-04 17:42:38 +02004087
Winson Chungaf40f202013-09-18 18:26:31 -07004088 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4089 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004090 // To catch cases where siblings of top-level views are made invisible, just check whether
4091 // the cling is directly set to GONE before dismissing it.
4092 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004093 final Runnable cleanUpClingCb = new Runnable() {
4094 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004095 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004096 // We should update the shared preferences on a background thread
4097 new Thread("dismissClingThread") {
4098 public void run() {
4099 SharedPreferences.Editor editor = mSharedPrefs.edit();
4100 editor.putBoolean(flag, true);
4101 editor.commit();
4102 }
4103 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004104 if (postAnimationCb != null) {
4105 postAnimationCb.run();
4106 }
4107 }
4108 };
4109 if (duration <= 0) {
4110 cleanUpClingCb.run();
4111 } else {
4112 cling.hide(duration, cleanUpClingCb);
4113 }
Michael Jurka22143132012-10-04 17:42:38 +02004114 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004115
4116 if (restoreNavBarVisibilty) {
4117 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4118 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4119 }
Winson Chung82f55532011-08-09 14:14:23 -07004120 }
4121 }
Michael Jurka22143132012-10-04 17:42:38 +02004122
Winson Chung9d9d74f2011-09-19 11:49:12 -07004123 private void removeCling(int id) {
4124 final View cling = findViewById(id);
4125 if (cling != null) {
4126 final ViewGroup parent = (ViewGroup) cling.getParent();
4127 parent.post(new Runnable() {
4128 @Override
4129 public void run() {
4130 parent.removeView(cling);
4131 }
4132 });
Michael Jurka22143132012-10-04 17:42:38 +02004133 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004134 }
4135 }
Michael Jurka974c3862012-05-22 22:00:31 -07004136
4137 private boolean skipCustomClingIfNoAccounts() {
4138 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4139 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4140 if (customCling) {
4141 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004142 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004143 Account[] accounts = am.getAccountsByType("com.google");
4144 return accounts.length == 0;
4145 }
4146 return false;
4147 }
4148
Winson Chungaf40f202013-09-18 18:26:31 -07004149 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004150 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004151 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004152 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004153 // If we're not using the default workspace layout, replace workspace cling
4154 // with a custom workspace cling (usually specified in an overlay)
4155 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004156 if (!DISABLE_CUSTOM_CLINGS) {
4157 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4158 getResources().getBoolean(R.bool.config_useCustomClings)) {
4159 // Use a custom cling
4160 View cling = findViewById(R.id.workspace_cling);
4161 ViewGroup clingParent = (ViewGroup) cling.getParent();
4162 int clingIndex = clingParent.indexOfChild(cling);
4163 clingParent.removeViewAt(clingIndex);
4164 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4165 clingParent.addView(customCling, clingIndex);
4166 customCling.setId(R.id.workspace_cling);
4167 }
4168 }
4169 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4170 if (cling != null) {
4171 String sbHintStr = getFirstRunClingSearchBarHint();
4172 String ccHintStr = getFirstRunCustomContentHint();
4173 if (!sbHintStr.isEmpty()) {
4174 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4175 sbHint.setText(sbHintStr);
4176 sbHint.setVisibility(View.VISIBLE);
4177 }
4178 if (!ccHintStr.isEmpty()) {
4179 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4180 ccHint.setText(ccHintStr);
4181 ccHint.setVisibility(View.VISIBLE);
4182 }
Michael Jurka45355c42012-10-08 13:21:35 +02004183 }
Winson Chungfa545132013-09-26 17:45:32 -07004184 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004185 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004186 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004187 }
4188 }
Winson Chungaf40f202013-09-18 18:26:31 -07004189
Winson Chunge6eabff2013-09-24 11:01:23 -07004190 protected String getFirstRunClingSearchBarHint() {
4191 return "";
4192 }
4193 protected String getFirstRunCustomContentHint() {
4194 return "";
4195 }
4196
Winson Chungaf40f202013-09-18 18:26:31 -07004197 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004198 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004199 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004200 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004201 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004202 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004203 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004204 }
4205 }
4206 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004207 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004208 if (isClingsEnabled() &&
4209 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004210 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4211 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004212 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004213 } else {
4214 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004215 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004216 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004217 }
Michael Jurka104c4562013-07-08 18:03:46 -07004218 protected SharedPreferences getSharedPrefs() {
4219 return mSharedPrefs;
4220 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004221 public boolean isFolderClingVisible() {
4222 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004223 if (cling != null) {
4224 return cling.getVisibility() == View.VISIBLE;
4225 }
4226 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004227 }
Winson Chungaf40f202013-09-18 18:26:31 -07004228 public void dismissFirstRunCling(View v) {
4229 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4230 Runnable cb = new Runnable() {
4231 public void run() {
4232 // Show the workspace cling next
4233 showFirstRunWorkspaceCling();
4234 }
4235 };
4236 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4237 DISMISS_CLING_DURATION, false);
4238 }
Winson Chung82f55532011-08-09 14:14:23 -07004239 public void dismissWorkspaceCling(View v) {
4240 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004241 Runnable cb = null;
4242 if (v == null) {
4243 cb = new Runnable() {
4244 public void run() {
4245 mWorkspace.enterOverviewMode();
4246 }
4247 };
4248 }
4249 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4250 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004251 }
4252 public void dismissFolderCling(View v) {
4253 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004254 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4255 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004256 }
4257
Winson Chung80baf5a2010-08-09 16:03:15 -07004258 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004259 * Prints out out state for debugging.
4260 */
4261 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004262 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004263 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004264 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4265 Log.d(TAG, "mRestoring=" + mRestoring);
4266 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4267 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004268 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004269 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004270
Winson Chung785d2eb2011-04-14 16:08:02 -07004271 if (mAppsCustomizeContent != null) {
4272 mAppsCustomizeContent.dumpState();
4273 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004274 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004275 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004276
4277 @Override
4278 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4279 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004280 synchronized (sDumpLogs) {
4281 writer.println(" ");
4282 writer.println("Debug logs: ");
4283 for (int i = 0; i < sDumpLogs.size(); i++) {
4284 writer.println(" " + sDumpLogs.get(i));
4285 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004286 }
4287 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004288
4289 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004290 if (DEBUG_DUMP_LOG) {
4291 synchronized (sDumpLogs) {
4292 Log.d(TAG, "");
4293 Log.d(TAG, "*********************");
4294 Log.d(TAG, "Launcher debug logs: ");
4295 for (int i = 0; i < sDumpLogs.size(); i++) {
4296 Log.d(TAG, " " + sDumpLogs.get(i));
4297 }
4298 Log.d(TAG, "*********************");
4299 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004300 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004301 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004302 }
4303
4304 public static void addDumpLog(String tag, String log, boolean debugLog) {
4305 if (debugLog) {
4306 Log.d(tag, log);
4307 }
Winson Chungede41292013-09-19 16:27:36 -07004308 if (DEBUG_DUMP_LOG) {
4309 sDateStamp.setTime(System.currentTimeMillis());
4310 synchronized (sDumpLogs) {
4311 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004312 }
Winson Chungede41292013-09-19 16:27:36 -07004313 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004314 }
4315
Winson Chungede41292013-09-19 16:27:36 -07004316 public void dumpLogsToLocalData() {
4317 if (DEBUG_DUMP_LOG) {
4318 new Thread("DumpLogsToLocalData") {
4319 @Override
4320 public void run() {
4321 boolean success = false;
4322 sDateStamp.setTime(sRunStart);
4323 String FILENAME = sDateStamp.getMonth() + "-"
4324 + sDateStamp.getDay() + "_"
4325 + sDateStamp.getHours() + "-"
4326 + sDateStamp.getMinutes() + "_"
4327 + sDateStamp.getSeconds() + ".txt";
4328
4329 FileOutputStream fos = null;
4330 File outFile = null;
4331 try {
4332 outFile = new File(getFilesDir(), FILENAME);
4333 outFile.createNewFile();
4334 fos = new FileOutputStream(outFile);
4335 } catch (Exception e) {
4336 e.printStackTrace();
4337 }
4338 if (fos != null) {
4339 PrintWriter writer = new PrintWriter(fos);
4340
4341 writer.println(" ");
4342 writer.println("Debug logs: ");
4343 synchronized (sDumpLogs) {
4344 for (int i = 0; i < sDumpLogs.size(); i++) {
4345 writer.println(" " + sDumpLogs.get(i));
4346 }
4347 }
4348 writer.close();
4349 }
4350 try {
4351 if (fos != null) {
4352 fos.close();
4353 success = true;
4354 }
4355 } catch (IOException e) {
4356 e.printStackTrace();
4357 }
4358 }
4359 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004360 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004361 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004362}
Michael Jurka2763be32011-02-24 11:19:57 -08004363
Michael Jurkaabded662011-03-04 12:06:57 -08004364interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004365 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004366 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004367 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004368 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004369 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004370}