blob: 11772fde7b3f26c0e50e7a9c070720328d2a205b [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 Sandler6053b8002013-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
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Winson Chungd64a6662013-09-30 11:06:59 -0700302 private Intent mAppMarketIntent = null;
303 private static final boolean DISABLE_MARKET_BUTTON = true;
304
Craig Mautner360310b2012-10-26 15:13:08 -0700305 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700306
Adam Cohen1462de32012-07-24 22:34:36 -0700307 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
308
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700309 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700310 static Date sDateStamp = new Date();
311 static DateFormat sDateFormat =
312 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
313 static long sRunStart = System.currentTimeMillis();
314 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700315
Winson Chung46353de2012-02-16 14:05:10 -0800316 // We only want to get the SharedPreferences once since it does an FS stat each time we get
317 // it from the context.
318 private SharedPreferences mSharedPrefs;
319
Adam Cohene25af792013-06-06 23:08:25 -0700320 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
321
Winson Chungf0c6ae02012-03-21 16:10:31 -0700322 // Holds the page that we need to animate to, and the icon views that we need to animate up
323 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700324 private ImageView mFolderIconImageView;
325 private Bitmap mFolderIconBitmap;
326 private Canvas mFolderIconCanvas;
327 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700328
Michael Jurkaddd62e92011-02-16 17:49:14 -0800329 private BubbleTextView mWaitingForResume;
330
Michael Jurka22143132012-10-04 17:42:38 +0200331 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
332 = new HideFromAccessibilityHelper();
333
Michael Jurkac1f5d262011-09-30 19:32:27 -0700334 private Runnable mBuildLayersRunnable = new Runnable() {
335 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700336 if (mWorkspace != null) {
337 mWorkspace.buildPageHardwareLayers();
338 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700339 }
340 };
341
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800342 private static ArrayList<PendingAddArguments> sPendingAddList
343 = new ArrayList<PendingAddArguments>();
344
Michael Jurka0a457bf2012-11-19 14:05:05 -0800345 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
346
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800347 private static class PendingAddArguments {
348 int requestCode;
349 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700350 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700351 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352 int cellX;
353 int cellY;
354 }
355
Daniel Sandlerff02d492013-08-05 02:12:05 -0400356 private Stats mStats;
357
Michael Jurka0a457bf2012-11-19 14:05:05 -0800358 private static boolean isPropertyEnabled(String propertyName) {
359 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700360 }
361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 @Override
363 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700364 if (DEBUG_STRICT_MODE) {
365 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
366 .detectDiskReads()
367 .detectDiskWrites()
368 .detectNetwork() // or .detectAll() for all detectable problems
369 .penaltyLog()
370 .build());
371 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
372 .detectLeakedSqlLiteObjects()
373 .detectLeakedClosableObjects()
374 .penaltyLog()
375 .penaltyDeath()
376 .build());
377 }
378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400381 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400382 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700383
384 // Determine the dynamic grid properties
385 Point smallestSize = new Point();
386 Point largestSize = new Point();
387 Point realSize = new Point();
388 Display display = getWindowManager().getDefaultDisplay();
389 display.getCurrentSizeRange(smallestSize, largestSize);
390 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700391 DisplayMetrics dm = new DisplayMetrics();
392 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700393 // Lazy-initialize the dynamic grid
394 DeviceProfile grid = app.initDynamicGrid(this,
395 Math.min(smallestSize.x, smallestSize.y),
396 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700397 realSize.x, realSize.y,
398 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700399
400 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400401 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700402 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800403 mModel = app.setLauncher(this);
404 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400405 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700407
Daniel Sandlerff02d492013-08-05 02:12:05 -0400408 mStats = new Stats(this);
409
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700411 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
412 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700413
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700414 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
415 // this also ensures that any synchronous binding below doesn't re-trigger another
416 // LauncherModel load.
417 mPaused = false;
418
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200420 android.os.Debug.startMethodTracing(
421 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 }
423
424 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 setContentView(R.layout.launcher);
426 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100427 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800429 registerContentObservers();
430
Joe Onorato7c312c12009-08-13 21:36:53 -0700431 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 mSavedState = savedInstanceState;
434 restoreState(mSavedState);
435
Winson Chunga12a2502010-12-20 14:41:35 -0800436 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700437 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200438 mAppsCustomizeContent.onPackagesUpdated(
439 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700440 }
Winson Chunga12a2502010-12-20 14:41:35 -0800441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 if (PROFILE_STARTUP) {
443 android.os.Debug.stopMethodTracing();
444 }
445
446 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700447 if (sPausedFromUserAction) {
448 // If the user leaves launcher, then we should just load items asynchronously when
449 // they return.
450 mModel.startLoader(true, -1);
451 } else {
452 // We only load the page synchronously if the user rotates (or triggers a
453 // configuration change) while launcher is in the foreground
454 mModel.startLoader(true, mWorkspace.getCurrentPage());
455 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 }
457
458 // For handling default keys
459 mDefaultKeySsb = new SpannableStringBuilder();
460 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800461
462 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
463 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800464
Adam Cohenf9426d52012-06-04 17:26:21 -0700465 updateGlobalIcons();
466
467 // On large interfaces, we want the screen to auto-rotate based on the current orientation
468 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700469
470 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700471 }
472
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 protected void onUserLeaveHint() {
474 super.onUserLeaveHint();
475 sPausedFromUserAction = true;
476 }
477
Winson Chung98ca0f72013-07-29 12:58:51 -0700478 /** To be overriden by subclasses to hint to Launcher that we have custom content */
479 protected boolean hasCustomContentToLeft() {
480 return false;
481 }
482
Dave Hawkeya8881582013-09-17 15:55:33 -0600483 /**
484 * To be overridden by subclasses to create the custom content and call
485 * {@link #addToCustomContentPage}. This will only be invoked if
486 * {@link #hasCustomContentToLeft()} is {@code true}.
487 */
488 protected void addCustomContentToLeft() {
489 }
490
491 /**
492 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
493 * ensure the custom content page is added or removed if necessary.
494 */
495 protected void invalidateHasCustomContentToLeft() {
496 if (mWorkspace.getScreenOrder().isEmpty()) {
497 // Not bound yet, wait for bindScreens to be called.
498 return;
499 }
500
501 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
502 // Create the custom content page and call the subclass to populate it.
503 mWorkspace.createCustomContentPage();
504 addCustomContentToLeft();
505 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
506 mWorkspace.removeCustomContentPage();
507 }
508 }
509
Adam Cohenf9426d52012-06-04 17:26:21 -0700510 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700511 boolean searchVisible = false;
512 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800513 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700514 int coi = getCurrentOrientationIndexForGlobalIcons();
515 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
516 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700517 if (!DISABLE_MARKET_BUTTON) {
518 updateAppMarketIcon();
519 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700520 searchVisible = updateGlobalSearchIcon();
521 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700522 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700523 if (sGlobalSearchIcon[coi] != null) {
524 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700525 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700526 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700527 if (sVoiceSearchIcon[coi] != null) {
528 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700529 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700530 }
Winson Chungd64a6662013-09-30 11:06:59 -0700531 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700532 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800533 }
Winson Chungadf0c182012-08-23 14:59:07 -0700534 if (mSearchDropTargetBar != null) {
535 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
536 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800537 }
Romain Guycbb89e42009-06-08 15:52:54 -0700538
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700540 if (sLocaleConfiguration == null) {
541 new AsyncTask<Void, Void, LocaleConfiguration>() {
542 @Override
543 protected LocaleConfiguration doInBackground(Void... unused) {
544 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
545 readConfiguration(Launcher.this, localeConfiguration);
546 return localeConfiguration;
547 }
548
549 @Override
550 protected void onPostExecute(LocaleConfiguration result) {
551 sLocaleConfiguration = result;
552 checkForLocaleChange(); // recursive, but now with a locale configuration
553 }
554 }.execute();
555 return;
556 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700557
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final Configuration configuration = getResources().getConfiguration();
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final String locale = configuration.locale.toString();
562
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700563 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final int mcc = configuration.mcc;
565
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700566 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567 final int mnc = configuration.mnc;
568
Romain Guy84f296c2009-11-04 15:00:44 -0800569 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570
Romain Guy84f296c2009-11-04 15:00:44 -0800571 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700572 sLocaleConfiguration.locale = locale;
573 sLocaleConfiguration.mcc = mcc;
574 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700575
Joe Onorato0589f0f2010-02-08 13:44:00 -0800576 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700577
578 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
579 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700580 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700581 public void run() {
582 writeConfiguration(Launcher.this, localeConfiguration);
583 }
584 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700585 }
586 }
587
588 private static class LocaleConfiguration {
589 public String locale;
590 public int mcc = -1;
591 public int mnc = -1;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
Romain Guy98d01652009-06-30 16:21:04 -0700594 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
595 DataInputStream in = null;
596 try {
597 in = new DataInputStream(context.openFileInput(PREFERENCES));
598 configuration.locale = in.readUTF();
599 configuration.mcc = in.readInt();
600 configuration.mnc = in.readInt();
601 } catch (FileNotFoundException e) {
602 // Ignore
603 } catch (IOException e) {
604 // Ignore
605 } finally {
606 if (in != null) {
607 try {
608 in.close();
609 } catch (IOException e) {
610 // Ignore
611 }
612 }
613 }
614 }
615
616 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
617 DataOutputStream out = null;
618 try {
619 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
620 out.writeUTF(configuration.locale);
621 out.writeInt(configuration.mcc);
622 out.writeInt(configuration.mnc);
623 out.flush();
624 } catch (FileNotFoundException e) {
625 // Ignore
626 } catch (IOException e) {
627 //noinspection ResultOfMethodCallIgnored
628 context.getFileStreamPath(PREFERENCES).delete();
629 } finally {
630 if (out != null) {
631 try {
632 out.close();
633 } catch (IOException e) {
634 // Ignore
635 }
636 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800637 }
638 }
639
Anton Hanssona2f665f2013-09-26 12:18:32 +0100640 public Stats getStats() {
641 return mStats;
642 }
643
Bjorn Bringertc459e522013-06-07 19:36:01 +0100644 public LayoutInflater getInflater() {
645 return mInflater;
646 }
647
Adam Cohen716b51e2011-06-30 12:09:54 -0700648 public DragLayer getDragLayer() {
649 return mDragLayer;
650 }
651
Winson Chung36a62fe2012-05-06 18:04:42 -0700652 boolean isDraggingEnabled() {
653 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
654 // that is subsequently removed from the workspace in startBinding().
655 return !mModel.isLoadingWorkspace();
656 }
657
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 static int getScreen() {
659 synchronized (sLock) {
660 return sScreen;
661 }
662 }
663
664 static void setScreen(int screen) {
665 synchronized (sLock) {
666 sScreen = screen;
667 }
668 }
669
Winson Chung557d6ed2011-07-08 15:34:52 -0700670 /**
671 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
672 * a configuration step, this allows the proper animations to run after other transitions.
673 */
674 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700675 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800676 switch (args.requestCode) {
677 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700678 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700679 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800680 break;
681 case REQUEST_PICK_SHORTCUT:
682 processShortcut(args.intent);
683 break;
684 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700685 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700686 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700687 result = true;
688 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800689 case REQUEST_CREATE_APPWIDGET:
690 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700691 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700692 result = true;
693 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800694 }
Michael Jurka27614d22012-04-02 06:40:22 -0700695 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
696 // if you turned the screen off and then back while in All Apps, Launcher would not
697 // return to the workspace. Clearing mAddInfo.container here fixes this issue
698 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700699 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800700 }
701
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700703 protected void onActivityResult(
704 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700705 // Reset the startActivity waiting flag
706 mWaitingForResult = false;
707
Michael Jurka8b805b12012-04-18 14:23:14 -0700708 if (requestCode == REQUEST_BIND_APPWIDGET) {
709 int appWidgetId = data != null ?
710 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
711 if (resultCode == RESULT_CANCELED) {
712 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
713 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700714 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700715 }
716 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200717 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
718 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
719 mWorkspace.exitOverviewMode(false);
720 }
721 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700722 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200723
Winson Chung557d6ed2011-07-08 15:34:52 -0700724 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800725 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
726 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700727
Adam Cohened66b2b2012-01-23 17:28:51 -0800728 // We have special handling for widgets
729 if (isWidgetDrop) {
730 int appWidgetId = data != null ?
731 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700732 if (appWidgetId < 0) {
733 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
734 "widget configuration activity.");
735 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
736 } else {
737 completeTwoStageWidgetDrop(resultCode, appWidgetId);
738 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800739 return;
740 }
741
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 // The pattern used here is that a user PICKs a specific application,
743 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700744
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
746 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700747 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 final PendingAddArguments args = new PendingAddArguments();
749 args.requestCode = requestCode;
750 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700751 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700752 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700753 args.cellX = mPendingAddInfo.cellX;
754 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800755 if (isWorkspaceLocked()) {
756 sPendingAddList.add(args);
757 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700758 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800759 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800760 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800761 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700762 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
764 null);
765 }
766
767 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700768 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700769 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800770 Runnable onCompleteRunnable = null;
771 int animationType = 0;
772
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700773 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800774 if (resultCode == RESULT_OK) {
775 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
776 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700777 mPendingAddWidgetInfo);
778 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 onCompleteRunnable = new Runnable() {
780 @Override
781 public void run() {
782 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700783 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800784 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
785 null);
786 }
787 };
788 } else if (resultCode == RESULT_CANCELED) {
789 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
790 onCompleteRunnable = new Runnable() {
791 @Override
792 public void run() {
793 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
794 null);
795 }
796 };
797 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700798 if (mDragLayer.getAnimatedView() != null) {
799 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
800 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
801 animationType, boundWidget, true);
802 } else {
803 // The animated view may be null in the case of a rotation during widget configuration
804 onCompleteRunnable.run();
805 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800806 }
807
808 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700809 protected void onStop() {
810 super.onStop();
811 FirstFrameAnimatorHelper.setIsVisible(false);
812 }
813
814 @Override
815 protected void onStart() {
816 super.onStart();
817 FirstFrameAnimatorHelper.setIsVisible(true);
818 }
819
820 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200822 long startTime = 0;
823 if (DEBUG_RESUME_TIME) {
824 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400825 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200826 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700828
Winson Chung4a2afa32012-07-19 14:53:05 -0700829 // Restore the previous launcher state
830 if (mOnResumeState == State.WORKSPACE) {
831 showWorkspace(false);
832 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700833 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700834 }
835 mOnResumeState = State.NONE;
836
Craig Mautner360310b2012-10-26 15:13:08 -0700837 // Background was set to gradient in onPause(), restore to black if in all apps.
838 setWorkspaceBackground(mState == State.WORKSPACE);
839
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800840 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700841 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700842 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400843 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700844 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400845 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700846 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700848 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200849 // We might have postponed some bind calls until onResume (see waitUntilResume) --
850 // execute them here
851 long startTimeCallbacks = 0;
852 if (DEBUG_RESUME_TIME) {
853 startTimeCallbacks = System.currentTimeMillis();
854 }
855
856 if (mAppsCustomizeContent != null) {
857 mAppsCustomizeContent.setBulkBind(true);
858 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700859 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
860 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200861 }
862 if (mAppsCustomizeContent != null) {
863 mAppsCustomizeContent.setBulkBind(false);
864 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700865 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200866 if (DEBUG_RESUME_TIME) {
867 Log.d(TAG, "Time spent processing callbacks in onResume: " +
868 (System.currentTimeMillis() - startTimeCallbacks));
869 }
Michael Jurka447bf842013-05-15 14:52:15 +0200870 }
Michael Jurka54554252013-08-01 12:52:23 +0200871 if (mOnResumeCallbacks.size() > 0) {
872 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
873 mOnResumeCallbacks.get(i).run();
874 }
875 mOnResumeCallbacks.clear();
876 }
Winson Chunge4e50662012-01-23 14:45:13 -0800877
878 // Reset the pressed state of icons that were locked in the press state while activities
879 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800880 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800881 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800882 mWaitingForResume.setStayPressed(false);
883 }
Winson Chunge4e50662012-01-23 14:45:13 -0800884 if (mAppsCustomizeContent != null) {
885 // Resets the previous all apps icon press state
886 mAppsCustomizeContent.resetDrawableState();
887 }
Winson Chung780fe592013-09-26 14:48:44 -0700888 // Reset AllApps to its initial state
889 if (mAppsCustomizeTabHost != null) {
890 mAppsCustomizeTabHost.reset();
891 }
Adam Cohen06dff352012-06-01 17:17:08 -0700892 // It is possible that widgets can receive updates while launcher is not in the foreground.
893 // Consequently, the widgets will be inflated in the orientation of the foreground activity
894 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
895 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700896 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700897
Winson Chung780fe592013-09-26 14:48:44 -0700898 // Process any items that were added while Launcher was away.
899 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
900
Adam Cohenf9426d52012-06-04 17:26:21 -0700901 // Again, as with the above scenario, it's possible that one or more of the global icons
902 // were updated in the wrong orientation.
903 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200904 if (DEBUG_RESUME_TIME) {
905 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
906 }
Adam Cohen06dff352012-06-01 17:17:08 -0700907 }
908
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800909 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700910 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700911 // Ensure that items added to Launcher are queued until Launcher returns
912 InstallShortcutReceiver.enableInstallQueue();
913
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700914 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700915 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800916 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700917 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700918 }
Romain Guycbb89e42009-06-08 15:52:54 -0700919
Adam Cohen66a01fd2013-06-11 12:48:00 -0700920 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600921 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
922 addCustomContentToLeft();
923 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700924 }
925
Adam Cohenbffe7452013-07-22 18:21:45 -0700926 QSBScroller mQsbScroller = new QSBScroller() {
927 int scrollY = 0;
928
929 @Override
930 public void setScrollY(int scroll) {
931 scrollY = scroll;
932
933 if (mWorkspace.isOnOrMovingToCustomContent()) {
934 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100935 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700936 }
937 }
938 };
939
940 public void resetQSBScroll() {
941 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100942 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700943 }
944
945 public interface CustomContentCallbacks {
946 // Custom content is completely shown
947 public void onShow();
948
949 // Custom content is completely hidden
950 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700951
952 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
953 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700954 }
955
Adam Cohen30bacb22013-08-29 14:25:25 -0700956 protected void startSettings() {
957 }
958
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 public interface QSBScroller {
960 public void setScrollY(int scrollY);
961 }
962
Adam Cohen66a01fd2013-06-11 12:48:00 -0700963 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700964 public QSBScroller addToCustomContentPage(View customContent) {
965 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700966 }
967
Winson Chung98ca0f72013-07-29 12:58:51 -0700968 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700969 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700970 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700971 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700972 }
973
Adam Cohenedb40762013-07-18 16:45:45 -0700974 // The custom content needs to offset its content to account for the QSB
975 public int getTopOffsetForCustomContent() {
976 return mWorkspace.getPaddingTop();
977 }
978
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700979 @Override
980 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400981 // Flag the loader to stop early before switching
982 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700983 if (mAppsCustomizeContent != null) {
984 mAppsCustomizeContent.surrender();
985 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800986 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700987 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700988
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800989 // We can't hide the IME if it was forced open. So don't bother
990 /*
991 @Override
992 public void onWindowFocusChanged(boolean hasFocus) {
993 super.onWindowFocusChanged(hasFocus);
994
995 if (hasFocus) {
996 final InputMethodManager inputManager = (InputMethodManager)
997 getSystemService(Context.INPUT_METHOD_SERVICE);
998 WindowManager.LayoutParams lp = getWindow().getAttributes();
999 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1000 android.os.Handler()) {
1001 protected void onReceiveResult(int resultCode, Bundle resultData) {
1002 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1003 }
1004 });
1005 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1006 }
1007 }
1008 */
1009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 private boolean acceptFilter() {
1011 final InputMethodManager inputManager = (InputMethodManager)
1012 getSystemService(Context.INPUT_METHOD_SERVICE);
1013 return !inputManager.isFullscreenMode();
1014 }
1015
1016 @Override
1017 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001018 final int uniChar = event.getUnicodeChar();
1019 final boolean handled = super.onKeyDown(keyCode, event);
1020 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1021 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1023 keyCode, event);
1024 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001025 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001026 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001027 // showSearchDialog()
1028 // If there are multiple keystrokes before the search dialog takes focus,
1029 // onSearchRequested() will be called for every keystroke,
1030 // but it is idempotent, so it's fine.
1031 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 }
1033 }
1034
Joe Onorato8a9625e2010-01-28 15:55:35 -08001035 // Eat the long press event so the keyboard doesn't come up.
1036 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1037 return true;
1038 }
1039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 return handled;
1041 }
1042
Karl Rosaen138a0412009-04-23 19:00:21 -07001043 private String getTypedText() {
1044 return mDefaultKeySsb.toString();
1045 }
1046
1047 private void clearTypedText() {
1048 mDefaultKeySsb.clear();
1049 mDefaultKeySsb.clearSpans();
1050 Selection.setSelection(mDefaultKeySsb, 0);
1051 }
1052
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001054 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1055 * State
1056 */
1057 private static State intToState(int stateOrdinal) {
1058 State state = State.WORKSPACE;
1059 final State[] stateValues = State.values();
1060 for (int i = 0; i < stateValues.length; i++) {
1061 if (stateValues[i].ordinal() == stateOrdinal) {
1062 state = stateValues[i];
1063 break;
1064 }
1065 }
1066 return state;
1067 }
1068
1069 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070 * Restores the previous state, if it exists.
1071 *
1072 * @param savedState The previous state.
1073 */
1074 private void restoreState(Bundle savedState) {
1075 if (savedState == null) {
1076 return;
1077 }
1078
Michael Jurka883f55b2010-10-21 15:47:14 -07001079 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001080 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001081 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001082 }
1083
Winson Chungf0c6ae02012-03-21 16:10:31 -07001084 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001086 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 }
1088
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001090 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001091
Winson Chung3d503fb2011-07-13 17:25:49 -07001092 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1093 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001094 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001095 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1096 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001097 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1098 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1099 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001100 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 mRestoring = true;
1102 }
1103
1104 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1105 if (renameFolder) {
1106 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001107 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108 mRestoring = true;
1109 }
Winson Chunga12a2502010-12-20 14:41:35 -08001110
Winson Chung785d2eb2011-04-14 16:08:02 -07001111 // Restore the AppsCustomize tab
1112 if (mAppsCustomizeTabHost != null) {
1113 String curTab = savedState.getString("apps_customize_currentTab");
1114 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001115 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001117 mAppsCustomizeContent.loadAssociatedPages(
1118 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001119 }
1120
Winson Chung5afbf7b2011-07-25 11:53:08 -07001121 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1122 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001123 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124 }
1125
1126 /**
1127 * Finds all the views we need and configure them properly.
1128 */
1129 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001130 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001131
Craig Mautner360310b2012-10-26 15:13:08 -07001132 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001133 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1134 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001135
John Spurlock77e1f472013-09-11 10:09:51 -04001136 mLauncherView.setSystemUiVisibility(
1137 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001138 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139
Winson Chung4c98d922011-05-31 16:50:48 -07001140 // Setup the drag layer
1141 mDragLayer.setup(this, dragController);
1142
Winson Chung3d503fb2011-07-13 17:25:49 -07001143 // Setup the hotseat
1144 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1145 if (mHotseat != null) {
1146 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001147 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001148 }
1149
Adam Cohenf358a4b2013-07-23 16:47:31 -07001150 mOverviewPanel = findViewById(R.id.overview_panel);
1151 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1152 @Override
1153 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001154 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001155 }
1156 });
1157 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1158 @Override
1159 public void onClick(View arg0) {
1160 startWallpaper();
1161 }
1162 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001163 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1164 @Override
1165 public void onClick(View arg0) {
1166 startSettings();
1167 }
1168 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001169 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001170
Winson Chung4c98d922011-05-31 16:50:48 -07001171 // Setup the workspace
1172 mWorkspace.setHapticFeedbackEnabled(false);
1173 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001174 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001175 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001176
Winson Chungf0ea4d32011-06-06 14:27:16 -07001177 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001178 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001179
Winson Chungf0ea4d32011-06-06 14:27:16 -07001180 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001181 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001182 mAppsCustomizeContent = (AppsCustomizePagedView)
1183 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1184 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001185
Winson Chung3d503fb2011-07-13 17:25:49 -07001186 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001187 dragController.setDragScoller(mWorkspace);
1188 dragController.setScrollView(mDragLayer);
1189 dragController.setMoveTarget(mWorkspace);
1190 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001191 if (mSearchDropTargetBar != null) {
1192 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001193 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001194
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001195 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001197 mWeightWatcher = new WeightWatcher(this);
1198 mWeightWatcher.setAlpha(0.5f);
1199 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001200 new FrameLayout.LayoutParams(
1201 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001202 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001203 Gravity.BOTTOM)
1204 );
Adam Cohen39a06042013-07-19 14:30:12 -07001205
1206 boolean show = shouldShowWeightWatcher();
1207 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001208 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 /**
1212 * Creates a view representing a shortcut.
1213 *
1214 * @param info The data structure describing the shortcut.
1215 *
1216 * @return A View inflated from R.layout.application.
1217 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001218 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001220 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221 }
1222
1223 /**
1224 * Creates a view representing a shortcut inflated from the specified resource.
1225 *
1226 * @param layoutResId The id of the XML layout used to create the shortcut.
1227 * @param parent The group the shortcut belongs to.
1228 * @param info The data structure describing the shortcut.
1229 *
1230 * @return A View inflated from layoutResId.
1231 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001232 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001233 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1234 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 return favorite;
1237 }
1238
1239 /**
1240 * Add an application shortcut to the workspace.
1241 *
1242 * @param data The intent describing the application.
1243 * @param cellInfo The position on screen where to create the shortcut.
1244 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001245 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001246 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001247 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001248
Adam Cohenfbba09b2011-07-18 21:43:05 -07001249 // First we check if we already know the exact location where we want to add this item.
1250 if (cellX >= 0 && cellY >= 0) {
1251 cellXY[0] = cellX;
1252 cellXY[1] = cellY;
1253 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001254 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001255 return;
1256 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001258 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001259
Romain Guy73b979d2009-06-09 12:57:21 -07001260 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001261 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001263 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001264 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001265 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001266 } else {
1267 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 }
1269 }
Romain Guycbb89e42009-06-08 15:52:54 -07001270
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001271 /**
1272 * Add a shortcut to the workspace.
1273 *
1274 * @param data The intent describing the shortcut.
1275 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001278 int cellY) {
1279 int[] cellXY = mTmpAddItemCellCoordinates;
1280 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001281 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001282
Michael Jurkad3ef3062010-11-23 16:23:58 -08001283 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001284
Adam Cohen558baaf2011-08-15 15:22:57 -07001285 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001286 if (info == null) {
1287 return;
1288 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001289 final View view = createShortcut(info);
1290
Adam Cohenfbba09b2011-07-18 21:43:05 -07001291 // First we check if we already know the exact location where we want to add this item.
1292 if (cellX >= 0 && cellY >= 0) {
1293 cellXY[0] = cellX;
1294 cellXY[1] = cellY;
1295 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001296
1297 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001298 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001299 true, null,null)) {
1300 return;
1301 }
1302 DragObject dragObject = new DragObject();
1303 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001304 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1305 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001306 return;
1307 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001308 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001309 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001310 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001311 foundCellSpan = (result != null);
1312 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001313 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001314 }
1315
1316 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001317 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001318 return;
1319 }
1320
Adam Cohendcd297f2013-06-18 13:13:40 -07001321 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322
1323 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001324 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001325 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 }
1327 }
1328
Adam Cohen2f093b62012-04-30 18:59:53 -07001329 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1330 int minHeight) {
1331 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001332 // We want to account for the extra amount of padding that we are adding to the widget
1333 // to ensure that it gets the full amount of space that it has requested
1334 int requiredWidth = minWidth + padding.left + padding.right;
1335 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001336 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1340 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001341 }
1342
Adam Cohen2f093b62012-04-30 18:59:53 -07001343 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1344 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001345 }
1346
Adam Cohen2f093b62012-04-30 18:59:53 -07001347 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1348 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001349 }
1350
Adam Cohen2f093b62012-04-30 18:59:53 -07001351 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1352 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001353 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001354 }
1355
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001359 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001360 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001362 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001363 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1364 if (appWidgetInfo == null) {
1365 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1366 }
Romain Guycbb89e42009-06-08 15:52:54 -07001367
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001368 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001369 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001370
Adam Cohen2f093b62012-04-30 18:59:53 -07001371 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1372 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001373
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001375 // We have saved the position to which the widget was dragged-- this really only matters
1376 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 int[] cellXY = mTmpAddItemCellCoordinates;
1378 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001379 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001380 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001381 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1382 cellXY[0] = mPendingAddInfo.cellX;
1383 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001384 spanXY[0] = mPendingAddInfo.spanX;
1385 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001386 foundCellSpan = true;
1387 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001389 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001390 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1391 spanXY[1], cellXY, finalSpan);
1392 spanXY[0] = finalSpan[0];
1393 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001394 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001395 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001396 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001397 }
1398
Michael Jurka0280c3b2010-09-17 15:00:07 -07001399 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001400 if (appWidgetId != -1) {
1401 // Deleting an app widget ID is a void call but writes to disk before returning
1402 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001403 new Thread("deleteAppWidgetId") {
1404 public void run() {
1405 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1406 }
1407 }.start();
1408 }
Winson Chung93eef082012-03-23 15:59:27 -07001409 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001410 return;
1411 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001413 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001414 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1415 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 launcherInfo.spanX = spanXY[0];
1417 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001418 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1419 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001420
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001421 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001422 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423
1424 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001425 if (hostView == null) {
1426 // Perform actual inflation because we're live
1427 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1428 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1429 } else {
1430 // The AppWidgetHostView has already been inflated and instantiated
1431 launcherInfo.hostView = hostView;
1432 }
Romain Guycbb89e42009-06-08 15:52:54 -07001433
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001435 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001436 launcherInfo.notifyWidgetSizeChanged(this);
1437
Adam Cohendcd297f2013-06-18 13:13:40 -07001438 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001439 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001440
1441 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001442 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001443 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444 }
Romain Guycbb89e42009-06-08 15:52:54 -07001445
Adam Cohended9f8d2010-11-03 13:25:16 -07001446 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1447 @Override
1448 public void onReceive(Context context, Intent intent) {
1449 final String action = intent.getAction();
1450 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1451 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001452 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001453 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001454
Winson Chungc100e8e2011-08-09 16:02:43 -07001455 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001456 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001457 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001458 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001459 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001460 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1461 mUserPresent = true;
1462 updateRunning();
1463 }
1464 }
1465 };
1466
1467 @Override
1468 public void onAttachedToWindow() {
1469 super.onAttachedToWindow();
1470
1471 // Listen for broadcasts related to user-presence
1472 final IntentFilter filter = new IntentFilter();
1473 filter.addAction(Intent.ACTION_SCREEN_OFF);
1474 filter.addAction(Intent.ACTION_USER_PRESENT);
1475 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001476 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001477 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001478 mVisible = true;
1479 }
1480
1481 @Override
1482 public void onDetachedFromWindow() {
1483 super.onDetachedFromWindow();
1484 mVisible = false;
1485
Adam Cohend113e0c2010-11-11 10:48:05 -08001486 if (mAttached) {
1487 unregisterReceiver(mReceiver);
1488 mAttached = false;
1489 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001490 updateRunning();
1491 }
1492
1493 public void onWindowVisibilityChanged(int visibility) {
1494 mVisible = visibility == View.VISIBLE;
1495 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001496 // The following code used to be in onResume, but it turns out onResume is called when
1497 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1498 // is a more appropriate event to handle
1499 if (mVisible) {
1500 mAppsCustomizeTabHost.onWindowVisible();
1501 if (!mWorkspaceLoading) {
1502 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001503 // We want to let Launcher draw itself at least once before we force it to build
1504 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 // apps is nice and speedy.
1506 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001507 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001508 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001509 if (mStarted) return;
1510 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001511 // We delay the layer building a bit in order to give
1512 // other message processing a time to run. In particular
1513 // this avoids a delay in hiding the IME if it was
1514 // currently shown, because doing that may involve
1515 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001516 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001517 final ViewTreeObserver.OnDrawListener listener = this;
1518 mWorkspace.post(new Runnable() {
1519 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001520 if (mWorkspace != null &&
1521 mWorkspace.getViewTreeObserver() != null) {
1522 mWorkspace.getViewTreeObserver().
1523 removeOnDrawListener(listener);
1524 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001525 }
1526 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001527 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001528 }
1529 });
1530 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001531 // When Launcher comes back to foreground, a different Activity might be responsible for
1532 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001533 if (!DISABLE_MARKET_BUTTON) {
1534 updateAppMarketIcon();
1535 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001536 clearTypedText();
1537 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001538 }
1539
1540 private void sendAdvanceMessage(long delay) {
1541 mHandler.removeMessages(ADVANCE_MSG);
1542 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1543 mHandler.sendMessageDelayed(msg, delay);
1544 mAutoAdvanceSentTime = System.currentTimeMillis();
1545 }
1546
1547 private void updateRunning() {
1548 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1549 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1550 mAutoAdvanceRunning = autoAdvanceRunning;
1551 if (autoAdvanceRunning) {
1552 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1553 sendAdvanceMessage(delay);
1554 } else {
1555 if (!mWidgetsToAdvance.isEmpty()) {
1556 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1557 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1558 }
1559 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001560 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001561 }
1562 }
1563 }
1564
1565 private final Handler mHandler = new Handler() {
1566 @Override
1567 public void handleMessage(Message msg) {
1568 if (msg.what == ADVANCE_MSG) {
1569 int i = 0;
1570 for (View key: mWidgetsToAdvance.keySet()) {
1571 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1572 final int delay = mAdvanceStagger * i;
1573 if (v instanceof Advanceable) {
1574 postDelayed(new Runnable() {
1575 public void run() {
1576 ((Advanceable) v).advance();
1577 }
1578 }, delay);
1579 }
1580 i++;
1581 }
1582 sendAdvanceMessage(mAdvanceInterval);
1583 }
1584 }
1585 };
1586
1587 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001588 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001589 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1590 if (v instanceof Advanceable) {
1591 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001592 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001593 updateRunning();
1594 }
1595 }
1596
1597 void removeWidgetToAutoAdvance(View hostView) {
1598 if (mWidgetsToAdvance.containsKey(hostView)) {
1599 mWidgetsToAdvance.remove(hostView);
1600 updateRunning();
1601 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001602 }
1603
Joe Onorato9c1289c2009-08-17 11:03:03 -04001604 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001605 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001606 launcherInfo.hostView = null;
1607 }
1608
Winson Chung93eef082012-03-23 15:59:27 -07001609 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1610 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1611 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001612 }
1613
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001614 public LauncherAppWidgetHost getAppWidgetHost() {
1615 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001616 }
Romain Guycbb89e42009-06-08 15:52:54 -07001617
Winson Chunga9abd0e2010-10-27 17:18:37 -07001618 public LauncherModel getModel() {
1619 return mModel;
1620 }
1621
Bjorn Bringertc459e522013-06-07 19:36:01 +01001622 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001623 getWindow().closeAllPanels();
1624
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001625 // Whatever we were doing is hereby canceled.
1626 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001627 }
1628
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001629 @Override
1630 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001631 long startTime = 0;
1632 if (DEBUG_RESUME_TIME) {
1633 startTime = System.currentTimeMillis();
1634 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 super.onNewIntent(intent);
1636
1637 // Close the menu
1638 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001639 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001640 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001641
Jamie Genniscb222e82012-10-23 15:44:26 -07001642 final boolean alreadyOnHome =
1643 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001644 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001645
Jamie Genniscb222e82012-10-23 15:44:26 -07001646 Runnable processIntent = new Runnable() {
1647 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001648 if (mWorkspace == null) {
1649 // Can be cases where mWorkspace is null, this prevents a NPE
1650 return;
1651 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001652 Folder openFolder = mWorkspace.getOpenFolder();
1653 // In all these cases, only animate if we're already on home
1654 mWorkspace.exitWidgetResizeMode();
1655 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1656 openFolder == null) {
1657 mWorkspace.moveToDefaultScreen(true);
1658 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001659
Jamie Genniscb222e82012-10-23 15:44:26 -07001660 closeFolder();
1661 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001662
Jamie Genniscb222e82012-10-23 15:44:26 -07001663 // If we are already on home, then just animate back to the workspace,
1664 // otherwise, just wait until onResume to set the state back to Workspace
1665 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001666 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001667 } else {
1668 mOnResumeState = State.WORKSPACE;
1669 }
1670
1671 final View v = getWindow().peekDecorView();
1672 if (v != null && v.getWindowToken() != null) {
1673 InputMethodManager imm = (InputMethodManager)getSystemService(
1674 INPUT_METHOD_SERVICE);
1675 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1676 }
1677
Winson Chung7819a562013-09-19 15:55:45 -07001678 // Reset the apps customize page
1679 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001680 mAppsCustomizeTabHost.reset();
1681 }
1682 }
1683 };
1684
1685 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1686 // Delay processing of the intent to allow the status bar animation to finish
1687 // first in order to avoid janky animations.
1688 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001689 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001690 // Process the intent immediately.
1691 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001692 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001693
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 }
Michael Jurka447bf842013-05-15 14:52:15 +02001695 if (DEBUG_RESUME_TIME) {
1696 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1697 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 }
1699
Adam Cohen040a5d22013-09-16 17:09:33 -07001700 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1701 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001702 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001703 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001704 }
1705 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001706 protected void showWorkspaceAndExitOverviewMode() {
1707 showWorkspaceAndExitOverviewMode(true);
1708 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001711 public void onRestoreInstanceState(Bundle state) {
1712 super.onRestoreInstanceState(state);
1713 for (int page: mSynchronouslyBoundPages) {
1714 mWorkspace.restoreInstanceStateForChild(page);
1715 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 }
1717
1718 @Override
1719 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001720 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001721 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722
Michael Jurka883f55b2010-10-21 15:47:14 -07001723 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001724 // We close any open folder since it will not be re-opened, and we need to make sure
1725 // this state is reflected.
1726 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727
Adam Cohendcd297f2013-06-18 13:13:40 -07001728 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001729 mWaitingForResult) {
1730 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001731 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001732 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1733 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001734 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1735 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1736 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 }
1738
1739 if (mFolderInfo != null && mWaitingForResult) {
1740 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1741 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1742 }
Michael Jurka946ad472010-07-09 18:05:18 -07001743
Winson Chung785d2eb2011-04-14 16:08:02 -07001744 // Save the current AppsCustomize tab
1745 if (mAppsCustomizeTabHost != null) {
1746 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1747 if (currentTabTag != null) {
1748 outState.putString("apps_customize_currentTab", currentTabTag);
1749 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001750 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1751 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001752 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
1754
1755 @Override
1756 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001758
Winson Chunge7a03942011-08-05 15:05:12 -07001759 // Remove all pending runnables
1760 mHandler.removeMessages(ADVANCE_MSG);
1761 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001762 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001763
Winson Chungcd2b0142011-06-08 16:02:26 -07001764 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001765 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001766 mModel.stopLoader();
1767 app.setLauncher(null);
1768
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001770 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001772 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001773 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001774 mAppWidgetHost = null;
1775
1776 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001777
1778 TextKeyListener.getInstance().release();
1779
Winson Chung81b52252012-08-27 15:34:29 -07001780 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1781 // to prevent leaking Launcher activities on orientation change.
1782 if (mModel != null) {
1783 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1784 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001785
1786 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001787 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001788
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001789 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001790 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1791 mWorkspace.removeAllViews();
1792 mWorkspace = null;
1793 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001794
Michael Jurka2ecf9952012-06-18 12:52:28 -07001795 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 }
1797
Adam Cohena9cf38f2011-05-02 15:36:58 -07001798 public DragController getDragController() {
1799 return mDragController;
1800 }
1801
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 @Override
1803 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001804 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 super.startActivityForResult(intent, requestCode);
1806 }
1807
Winson Chung70d72102011-08-12 11:24:35 -07001808 /**
1809 * Indicates that we want global search for this activity by setting the globalSearch
1810 * argument for {@link #startSearch} to true.
1811 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001813 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001815
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001816 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001817
Karl Rosaen138a0412009-04-23 19:00:21 -07001818 if (initialQuery == null) {
1819 // Use any text typed in the launcher as the initial query
1820 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001821 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 if (appSearchData == null) {
1823 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001824 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 }
Winson Chungadf0c182012-08-23 14:59:07 -07001826 Rect sourceBounds = new Rect();
1827 if (mSearchDropTargetBar != null) {
1828 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1829 }
Romain Guycbb89e42009-06-08 15:52:54 -07001830
Bjorn Bringertc459e522013-06-07 19:36:01 +01001831 startSearch(initialQuery, selectInitialQuery,
1832 appSearchData, sourceBounds);
1833 }
1834
1835 public void startSearch(String initialQuery,
1836 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001837 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001838 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001839 }
1840
1841 /**
1842 * Starts the global search activity. This code is a copied from SearchManager
1843 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001844 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001845 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001846 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001847 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1848 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1849 if (globalSearchActivity == null) {
1850 Log.w(TAG, "No global search activity found.");
1851 return;
1852 }
1853 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1854 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1855 intent.setComponent(globalSearchActivity);
1856 // Make sure that we have a Bundle to put source in
1857 if (appSearchData == null) {
1858 appSearchData = new Bundle();
1859 } else {
1860 appSearchData = new Bundle(appSearchData);
1861 }
1862 // Set source to package name of app that starts global search, if not set already.
1863 if (!appSearchData.containsKey("source")) {
1864 appSearchData.putString("source", getPackageName());
1865 }
1866 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1867 if (!TextUtils.isEmpty(initialQuery)) {
1868 intent.putExtra(SearchManager.QUERY, initialQuery);
1869 }
1870 if (selectInitialQuery) {
1871 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1872 }
1873 intent.setSourceBounds(sourceBounds);
1874 try {
1875 startActivity(intent);
1876 } catch (ActivityNotFoundException ex) {
1877 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1878 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 }
1880
Winson Chung70d72102011-08-12 11:24:35 -07001881 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001882 public boolean onPrepareOptionsMenu(Menu menu) {
1883 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001884 if (!mWorkspace.isInOverviewMode()) {
1885 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001886 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001887 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001890 @Override
1891 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001892 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001893 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001894 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001895 }
1896
Joe Onorato9c1289c2009-08-17 11:03:03 -04001897 public boolean isWorkspaceLocked() {
1898 return mWorkspaceLoading || mWaitingForResult;
1899 }
1900
Michael Jurka0280c3b2010-09-17 15:00:07 -07001901 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001903 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001904 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1905 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001906 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001907 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001908 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001909
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001910 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1911 AppWidgetProviderInfo appWidgetInfo) {
1912 if (appWidgetInfo.configure != null) {
1913 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001914
Bjorn Bringert7984c942009-12-09 15:38:25 +00001915 // Launch over to configure widget, if needed
1916 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001917 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001918 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001919 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001921 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001922 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001923 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001924 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001925 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 }
1927 }
Romain Guycbb89e42009-06-08 15:52:54 -07001928
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001929 protected void moveToCustomContentScreen(boolean animate) {
1930 mWorkspace.moveToCustomContentScreen(animate);
1931 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001932 /**
1933 * Process a shortcut drop.
1934 *
1935 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001936 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001937 * @param cell The cell it should be added to, optional
1938 * @param position The location on the screen where it was dropped, optional
1939 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001940 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001941 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001942 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001943 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001944 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001945 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001946
1947 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001948 mPendingAddInfo.cellX = cell[0];
1949 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001950 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001951
1952 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1953 createShortcutIntent.setComponent(componentName);
1954 processShortcut(createShortcutIntent);
1955 }
1956
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957 /**
1958 * Process a widget drop.
1959 *
1960 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001961 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001962 * @param cell The cell it should be added to, optional
1963 * @param position The location on the screen where it was dropped, optional
1964 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001965 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001966 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001967 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001968 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001969 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001970 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001971 mPendingAddInfo.minSpanX = info.minSpanX;
1972 mPendingAddInfo.minSpanY = info.minSpanY;
1973
Adam Cohenfbba09b2011-07-18 21:43:05 -07001974 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001975 mPendingAddInfo.cellX = cell[0];
1976 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001977 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001978 if (span != null) {
1979 mPendingAddInfo.spanX = span[0];
1980 mPendingAddInfo.spanY = span[1];
1981 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001982
Adam Cohened66b2b2012-01-23 17:28:51 -08001983 AppWidgetHostView hostView = info.boundWidget;
1984 int appWidgetId;
1985 if (hostView != null) {
1986 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001987 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001988 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001989 // In this case, we either need to start an activity to get permission to bind
1990 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001991 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001992 Bundle options = info.bindOptions;
1993
1994 boolean success = false;
1995 if (options != null) {
1996 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1997 info.componentName, options);
1998 } else {
1999 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2000 info.componentName);
2001 }
2002 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002003 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002004 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002005 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002006 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2007 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2008 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002009 // TODO: we need to make sure that this accounts for the options bundle.
2010 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002011 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2012 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002013 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002014 }
2015
Joe Onoratodeb98af2010-02-19 14:59:39 -08002016 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002017 // Handle case where user selected "Applications"
2018 String applicationName = getResources().getString(R.string.group_applications);
2019 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002020
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002021 if (applicationName != null && applicationName.equals(shortcutName)) {
2022 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2023 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002024
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002025 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2026 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002027 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002028 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002029 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002030 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002031 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002032 }
2033
Winson Chung24ab2f12010-09-16 14:10:47 -07002034 void processWallpaper(Intent intent) {
2035 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2036 }
2037
Adam Cohendcd297f2013-06-18 13:13:40 -07002038 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002039 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002040 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 folderInfo.title = getText(R.string.folder_name);
2042
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002044 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002045 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002046 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047
2048 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002049 FolderIcon newFolder =
2050 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002051 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002052 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002053 // Force measure the new folder icon
2054 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2055 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002056 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 }
Romain Guycbb89e42009-06-08 15:52:54 -07002058
Joe Onorato9c1289c2009-08-17 11:03:03 -04002059 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002060 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002061 }
2062
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002063 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002064 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002066 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002067 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 }
2069
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002070 protected ComponentName getWallpaperPickerComponent() {
2071 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2072 }
2073
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002074 /**
2075 * Registers various content observers. The current implementation registers
2076 * only a favorites observer to keep track of the favorites applications.
2077 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002078 private void registerContentObservers() {
2079 ContentResolver resolver = getContentResolver();
2080 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2081 true, mWidgetObserver);
2082 }
2083
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002084 @Override
2085 public boolean dispatchKeyEvent(KeyEvent event) {
2086 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2087 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002089 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002090 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002091 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002092 dumpState();
2093 return true;
2094 }
2095 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002096 }
2097 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2098 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002099 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002100 return true;
2101 }
2102 }
2103
2104 return super.dispatchKeyEvent(event);
2105 }
2106
Joe Onorato88ec0992009-11-19 13:16:06 -08002107 @Override
2108 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002109 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002110 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002111 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002112 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002113 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002114 Folder openFolder = mWorkspace.getOpenFolder();
2115 if (openFolder.isEditingName()) {
2116 openFolder.dismissEditingName();
2117 } else {
2118 closeFolder();
2119 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002120 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002121 mWorkspace.exitWidgetResizeMode();
2122
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002123 // Back button is a no-op here, but give at least some feedback for the button press
2124 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002125 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002126 }
2127
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002129 * Re-listen when widgets are reset.
2130 */
2131 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002132 if (mAppWidgetHost != null) {
2133 mAppWidgetHost.startListening();
2134 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002135 }
2136
2137 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 * Launches the intent referred by the clicked shortcut.
2139 *
2140 * @param v The view representing the clicked shortcut.
2141 */
2142 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002143 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2144 // view has detached (it's possible for this to happen if the view is removed mid touch).
2145 if (v.getWindowToken() == null) {
2146 return;
2147 }
2148
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002149 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002150 return;
2151 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002152
Adam Cohen1697b792013-09-17 19:08:21 -07002153 if (v instanceof Workspace) {
2154 if (mWorkspace.isInOverviewMode()) {
2155 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002156 }
2157 return;
2158 }
2159
2160 if (v instanceof CellLayout) {
2161 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002162 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002163 }
2164 }
2165
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002167 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002168 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002169 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2170 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002171
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002172 // Check for special shortcuts
2173 if (intent.getComponent() != null) {
2174 final String shortcutClass = intent.getComponent().getClassName();
2175
2176 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002177 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002178 return;
2179 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2180 MemoryDumpActivity.startDump(this);
2181 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002182 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2183 toggleShowWeightWatcher();
2184 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002185 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002186 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002187
2188 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002189 int[] pos = new int[2];
2190 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002191 intent.setSourceBounds(new Rect(pos[0], pos[1],
2192 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002193
2194 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002195
Daniel Sandlerff02d492013-08-05 02:12:05 -04002196 mStats.recordLaunch(intent, shortcut);
2197
Michael Jurkaddd62e92011-02-16 17:49:14 -08002198 if (success && v instanceof BubbleTextView) {
2199 mWaitingForResume = (BubbleTextView) v;
2200 mWaitingForResume.setStayPressed(true);
2201 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002203 if (v instanceof FolderIcon) {
2204 FolderIcon fi = (FolderIcon) v;
2205 handleFolderClick(fi);
2206 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002207 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002208 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002209 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002210 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002211 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002213 }
2214 }
2215
Michael Jurka0e260592010-06-30 17:07:39 -07002216 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002217 return false;
2218 }
2219
Michael Jurkaaf442092010-06-10 17:01:57 -07002220 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002221 * Event handler for the search button
2222 *
2223 * @param v The view that was clicked.
2224 */
2225 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002226 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2227
Amith Yamasania135ba82011-08-09 17:42:01 -07002228 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002229 }
2230
2231 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002232 * Event handler for the voice button
2233 *
2234 * @param v The view that was clicked.
2235 */
2236 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002237 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002238
Bjorn Bringertc459e522013-06-07 19:36:01 +01002239 startVoice();
2240 }
2241
2242 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002243 try {
2244 final SearchManager searchManager =
2245 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2246 ComponentName activityName = searchManager.getGlobalSearchActivity();
2247 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002248 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002249 if (activityName != null) {
2250 intent.setPackage(activityName.getPackageName());
2251 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002252 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002253 } catch (ActivityNotFoundException e) {
2254 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002255 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002256 startActivitySafely(null, intent, "onClickVoiceButton");
2257 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002258 }
2259
2260 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002261 * Event handler for the "grid" button that appears on the home screen, which
2262 * enters all apps mode.
2263 *
2264 * @param v The view that was clicked.
2265 */
2266 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002267 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002268 }
2269
2270 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002271 // Provide the same haptic feedback that the system offers for virtual keys.
2272 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002273 }
2274
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002275 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002276 if (!DISABLE_MARKET_BUTTON) {
2277 if (mAppMarketIntent != null) {
2278 startActivitySafely(v, mAppMarketIntent, "app market");
2279 } else {
2280 Log.e(TAG, "Invalid app market intent.");
2281 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002282 }
2283 }
2284
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002285 /**
2286 * Called when the user stops interacting with the launcher.
2287 * This implies that the user is now on the homescreen and is not doing housekeeping.
2288 */
2289 protected void onInteractionEnd() {}
2290
2291 /**
2292 * Called when the user starts interacting with the launcher.
2293 * The possible interactions are:
2294 * - open all apps
2295 * - reorder an app shortcut, or a widget
2296 * - open the overview mode.
2297 * This is a good time to stop doing things that only make sense
2298 * when the user is on the homescreen and not doing housekeeping.
2299 */
2300 protected void onInteractionBegin() {}
2301
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002302 void startApplicationDetailsActivity(ComponentName componentName) {
2303 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002304 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2305 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002306 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002307 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002308 }
2309
Michael Jurka1e2f4652013-07-08 18:03:46 -07002310 // returns true if the activity was started
2311 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002312 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002313 // System applications cannot be installed. For now, show a toast explaining that.
2314 // We may give them the option of disabling apps this way.
2315 int messageId = R.string.uninstall_system_app_text;
2316 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002317 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002318 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002319 String packageName = componentName.getPackageName();
2320 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002321 Intent intent = new Intent(
2322 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002323 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2324 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002325 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002326 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002327 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002328 }
2329
Michael Jurka86a720e2012-05-09 11:23:23 -07002330 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002331 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002332
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002333 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002334 // Only launch using the new animation if the shortcut has not opted out (this is a
2335 // private contract between launcher and may be ignored in the future).
2336 boolean useLaunchAnimation = (v != null) &&
2337 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2338 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002339 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2340 v.getMeasuredWidth(), v.getMeasuredHeight());
2341
2342 startActivity(intent, opts.toBundle());
2343 } else {
2344 startActivity(intent);
2345 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002346 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002347 } catch (SecurityException e) {
2348 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002349 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002351 "or use the exported attribute for this activity. "
2352 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002353 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002354 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002355 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002356
Michael Jurka86a720e2012-05-09 11:23:23 -07002357 boolean startActivitySafely(View v, Intent intent, Object tag) {
2358 boolean success = false;
2359 try {
2360 success = startActivity(v, intent, tag);
2361 } catch (ActivityNotFoundException e) {
2362 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2363 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2364 }
2365 return success;
2366 }
2367
Adam Cohena9cf38f2011-05-02 15:36:58 -07002368 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002369 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002370 Folder openFolder = mWorkspace.getFolderForTag(info);
2371
2372 // If the folder info reports that the associated folder is open, then verify that
2373 // it is actually opened. There have been a few instances where this gets out of sync.
2374 if (info.opened && openFolder == null) {
2375 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002376 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002377 info.opened = false;
2378 }
2379
Adam Cohenfb91f302012-06-11 15:45:18 -07002380 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002381 // Close any open folder
2382 closeFolder();
2383 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002384 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 } else {
2386 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 int folderScreen;
2388 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002389 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 // .. and close it
2391 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002392 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002393 // Close any folder open on the current screen
2394 closeFolder();
2395 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002396 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002397 }
2398 }
2399 }
2400 }
2401
Adam Cohen268c4752012-06-06 17:47:33 -07002402 /**
2403 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2404 * in the DragLayer in the exact absolute location of the original FolderIcon.
2405 */
2406 private void copyFolderIconToImage(FolderIcon fi) {
2407 final int width = fi.getMeasuredWidth();
2408 final int height = fi.getMeasuredHeight();
2409
2410 // Lazy load ImageView, Bitmap and Canvas
2411 if (mFolderIconImageView == null) {
2412 mFolderIconImageView = new ImageView(this);
2413 }
2414 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2415 mFolderIconBitmap.getHeight() != height) {
2416 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2417 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2418 }
2419
2420 DragLayer.LayoutParams lp;
2421 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2422 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2423 } else {
2424 lp = new DragLayer.LayoutParams(width, height);
2425 }
2426
Adam Cohen307fe232012-08-16 17:55:58 -07002427 // The layout from which the folder is being opened may be scaled, adjust the starting
2428 // view size by this scale factor.
2429 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002430 lp.customPosition = true;
2431 lp.x = mRectForFolderAnimation.left;
2432 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002433 lp.width = (int) (scale * width);
2434 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002435
2436 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2437 fi.draw(mFolderIconCanvas);
2438 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002439 if (fi.getFolder() != null) {
2440 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2441 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002442 }
Adam Cohen268c4752012-06-06 17:47:33 -07002443 // Just in case this image view is still in the drag layer from a previous animation,
2444 // we remove it and re-add it.
2445 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2446 mDragLayer.removeView(mFolderIconImageView);
2447 }
2448 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002449 if (fi.getFolder() != null) {
2450 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002451 }
Adam Cohen268c4752012-06-06 17:47:33 -07002452 }
2453
Adam Cohen2801caf2011-05-13 20:57:39 -07002454 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002455 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002456 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2457 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2458 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2459
Adam Cohenc51934b2011-07-26 21:07:43 -07002460 FolderInfo info = (FolderInfo) fi.getTag();
2461 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2462 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002463 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2464 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002465 }
2466
Adam Cohen268c4752012-06-06 17:47:33 -07002467 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2468 copyFolderIconToImage(fi);
2469 fi.setVisibility(View.INVISIBLE);
2470
Michael Jurka2ecf9952012-06-18 12:52:28 -07002471 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002472 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002473 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2474 oa.start();
2475 }
2476
Adam Cohen268c4752012-06-06 17:47:33 -07002477 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002478 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002479 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2480 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2481 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2482
Adam Cohen268c4752012-06-06 17:47:33 -07002483 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002484
Adam Cohen268c4752012-06-06 17:47:33 -07002485 // We remove and re-draw the FolderIcon in-case it has changed
2486 mDragLayer.removeView(mFolderIconImageView);
2487 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002488 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002489 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002490 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002491 oa.addListener(new AnimatorListenerAdapter() {
2492 @Override
2493 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002494 if (cl != null) {
2495 cl.clearFolderLeaveBehind();
2496 // Remove the ImageView copy of the FolderIcon and make the original visible.
2497 mDragLayer.removeView(mFolderIconImageView);
2498 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002499 }
2500 }
2501 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002502 oa.start();
2503 }
2504
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002505 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002506 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002507 * is animated relative to the specified View. If the View is null, no animation
2508 * is played.
2509 *
2510 * @param folderInfo The FolderInfo describing the folder to open.
2511 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002512 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002513 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002514 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002515
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002517
Adam Cohen4554ee12011-08-03 16:13:21 -07002518 // Just verify that the folder hasn't already been added to the DragLayer.
2519 // There was a one-off crash where the folder had a parent already.
2520 if (folder.getParent() == null) {
2521 mDragLayer.addView(folder);
2522 mDragController.addDropTarget((DropTarget) folder);
2523 } else {
2524 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2525 folder.getParent() + ").");
2526 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002527 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002528 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002529
2530 // Notify the accessibility manager that this folder "window" has appeared and occluded
2531 // the workspace items
2532 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2533 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002534 }
2535
2536 public void closeFolder() {
2537 Folder folder = mWorkspace.getOpenFolder();
2538 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002539 if (folder.isEditingName()) {
2540 folder.dismissEditingName();
2541 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002542 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002543
2544 // Dismiss the folder cling
2545 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002546 }
2547 }
2548
2549 void closeFolder(Folder folder) {
2550 folder.getInfo().opened = false;
2551
2552 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2553 if (parent != null) {
2554 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2555 shrinkAndFadeInFolderIcon(fi);
2556 }
2557 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002558
2559 // Notify the accessibility manager that this folder "window" has disappeard and no
2560 // longer occludeds the workspace items
2561 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002562 }
2563
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002565 if (!isDraggingEnabled()) return false;
2566 if (isWorkspaceLocked()) return false;
2567 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002568
Adam Cohen1697b792013-09-17 19:08:21 -07002569 if (v instanceof Workspace) {
2570 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002571 if (mWorkspace.enterOverviewMode()) {
2572 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2573 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2574 return true;
2575 } else {
2576 return false;
2577 }
Adam Cohen1697b792013-09-17 19:08:21 -07002578 }
Adam Cohen1697b792013-09-17 19:08:21 -07002579 }
2580
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002581 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002582 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002583 }
2584
Michael Jurka0280c3b2010-09-17 15:00:07 -07002585 resetAddInfo();
2586 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002587 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002588 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002589 return true;
2590 }
2591
Winson Chung3d503fb2011-07-13 17:25:49 -07002592 // The hotseat touch handling does not go through Workspace, and we always allow long press
2593 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002594 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002595 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2596 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002597 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002598 // User long pressed on empty space
2599 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2600 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2601 // Disabling reordering until we sort out some issues.
2602 if (mWorkspace.isInOverviewMode()) {
2603 mWorkspace.startReordering(v);
2604 } else {
2605 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002606 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002607 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002608 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002609 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002610 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002611 }
2612 }
2613 }
2614 return true;
2615 }
2616
Winson Chung3d503fb2011-07-13 17:25:49 -07002617 boolean isHotseatLayout(View layout) {
2618 return mHotseat != null && layout != null &&
2619 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2620 }
2621 Hotseat getHotseat() {
2622 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002623 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002624 View getOverviewPanel() {
2625 return mOverviewPanel;
2626 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002627 SearchDropTargetBar getSearchBar() {
2628 return mSearchDropTargetBar;
2629 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002630
Winson Chung3d503fb2011-07-13 17:25:49 -07002631 /**
2632 * Returns the CellLayout of the specified container at the specified screen.
2633 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002634 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002635 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2636 if (mHotseat != null) {
2637 return mHotseat.getLayout();
2638 } else {
2639 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002640 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002641 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002642 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002643 }
2644 }
2645
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002646 Workspace getWorkspace() {
2647 return mWorkspace;
2648 }
2649
Daniel Sandler843e8602010-06-07 14:59:01 -04002650 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002651 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002652 }
2653
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002654 /**
2655 * Helper method for the cameraZoomIn/cameraZoomOut animations
2656 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002657 * @param scaleFactor The scale factor used for the zoom
2658 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002659 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002660 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002661 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002662 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002663
Craig Mautner360310b2012-10-26 15:13:08 -07002664 private void setWorkspaceBackground(boolean workspace) {
2665 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002666 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002667 }
2668
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002669 void updateWallpaperVisibility(boolean visible) {
2670 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2671 int curflags = getWindow().getAttributes().flags
2672 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2673 if (wpflags != curflags) {
2674 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2675 }
Craig Mautner360310b2012-10-26 15:13:08 -07002676 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002677 }
2678
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002679 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2680 if (v instanceof LauncherTransitionable) {
2681 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2682 }
2683 }
2684
Michael Jurkabed61d22012-02-14 22:51:29 -08002685 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2686 if (v instanceof LauncherTransitionable) {
2687 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2688 }
Winson Chung70442722012-02-10 15:43:22 -08002689
2690 // Update the workspace transition step as well
2691 dispatchOnLauncherTransitionStep(v, 0f);
2692 }
2693
2694 private void dispatchOnLauncherTransitionStep(View v, float t) {
2695 if (v instanceof LauncherTransitionable) {
2696 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2697 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002698 }
2699
2700 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2701 if (v instanceof LauncherTransitionable) {
2702 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2703 }
Winson Chung70442722012-02-10 15:43:22 -08002704
2705 // Update the workspace transition step as well
2706 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002707 }
2708
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002709 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002710 * Things to test when changing the following seven functions.
2711 * - Home from workspace
2712 * - from center screen
2713 * - from other screens
2714 * - Home from all apps
2715 * - from center screen
2716 * - from other screens
2717 * - Back from all apps
2718 * - from center screen
2719 * - from other screens
2720 * - Launch app from workspace and quit
2721 * - with back
2722 * - with home
2723 * - Launch app from all apps and quit
2724 * - with back
2725 * - with home
2726 * - Go to a screen that's not the default, then all
2727 * apps, and launch and app, and go back
2728 * - with back
2729 * -with home
2730 * - On workspace, long press power and go back
2731 * - with back
2732 * - with home
2733 * - On all apps, long press power and go back
2734 * - with back
2735 * - with home
2736 * - On workspace, power off
2737 * - On all apps, power off
2738 * - Launch an app and turn off the screen while in that app
2739 * - Go back with home key
2740 * - Go back with back key TODO: make this not go to workspace
2741 * - From all apps
2742 * - From workspace
2743 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2744 * - From all apps
2745 * - From the center workspace
2746 * - From another workspace
2747 */
2748
2749 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002750 * Zoom the camera out from the workspace to reveal 'toView'.
2751 * Assumes that the view to show is anchored at either the very top or very bottom
2752 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002753 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002754 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002755 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2756 showAppsCustomizeHelper(animated, springLoaded, contentType);
2757 }
2758 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2759 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002760 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002761 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002762 mStateAnimation.cancel();
2763 mStateAnimation = null;
2764 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002765 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002766
Winson Chungf0ea4d32011-06-06 14:27:16 -07002767 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2768 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2769 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002770 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002771 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002772 final int startDelay =
2773 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002774
Michael Jurkab3e22d92011-10-31 15:58:33 -07002775 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002776
Michael Jurkad74c9842011-07-10 12:44:21 -07002777 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002778 Animator workspaceAnim =
2779 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002780 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2781 // Set the content type for the all apps space
2782 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2783 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002784
2785 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002786 toView.setScaleX(scale);
2787 toView.setScaleY(scale);
2788 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2789 scaleAnim.
2790 scaleX(1f).scaleY(1f).
2791 setDuration(duration).
2792 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002793
Winson Chungf0ea4d32011-06-06 14:27:16 -07002794 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002795 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002796 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002797 .ofFloat(toView, "alpha", 0f, 1f)
2798 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002799 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002800 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2801 @Override
2802 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002803 if (animation == null) {
2804 throw new RuntimeException("animation is null");
2805 }
Winson Chung70442722012-02-10 15:43:22 -08002806 float t = (Float) animation.getAnimatedValue();
2807 dispatchOnLauncherTransitionStep(fromView, t);
2808 dispatchOnLauncherTransitionStep(toView, t);
2809 }
2810 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002811
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002812 // toView should appear right at the end of the workspace shrink
2813 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002814 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002815 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002816 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002817
2818 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002819 boolean animationCancelled = false;
2820
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002821 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002822 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002823 // Prepare the position
2824 toView.setTranslationX(0.0f);
2825 toView.setTranslationY(0.0f);
2826 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002827 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002828 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002829 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002830 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002831 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2832 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002833
Winson Chungc7d2b602012-05-16 17:02:20 -07002834 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002835 if (mSearchDropTargetBar != null) {
2836 mSearchDropTargetBar.hideSearchBar(false);
2837 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002838 }
2839
Adam Cohencff6af82011-09-13 14:51:53 -07002840 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002841 public void onAnimationCancel(Animator animation) {
2842 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002843 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002844 });
2845
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002846 if (workspaceAnim != null) {
2847 mStateAnimation.play(workspaceAnim);
2848 }
Michael Jurka1899a362011-11-03 13:50:45 -07002849
2850 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002852 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2853 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002854
2855 // If any of the objects being animated haven't been measured/laid out
2856 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002857 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002858 (mWorkspace.getMeasuredWidth() == 0) ||
2859 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002860 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002861 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002862
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002863 final AnimatorSet stateAnimation = mStateAnimation;
2864 final Runnable startAnimRunnable = new Runnable() {
2865 public void run() {
2866 // Check that mStateAnimation hasn't changed while
2867 // we waited for a layout/draw pass
2868 if (mStateAnimation != stateAnimation)
2869 return;
2870 setPivotsForZoom(toView, scale);
2871 dispatchOnLauncherTransitionStart(fromView, animated, false);
2872 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002873 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002874 }
2875 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002876 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002877 final ViewTreeObserver observer = toView.getViewTreeObserver();
2878 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2879 public void onGlobalLayout() {
2880 startAnimRunnable.run();
2881 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2882 }
2883 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002884 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002885 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002886 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002887 } else {
2888 toView.setTranslationX(0.0f);
2889 toView.setTranslationY(0.0f);
2890 toView.setScaleX(1.0f);
2891 toView.setScaleY(1.0f);
2892 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002893 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002894
Daniel Sandlere4f98912013-06-25 15:13:26 -04002895 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002896 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002897 if (mSearchDropTargetBar != null) {
2898 mSearchDropTargetBar.hideSearchBar(false);
2899 }
Michael Jurkaabded662011-03-04 12:06:57 -08002900 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002901 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002902 dispatchOnLauncherTransitionStart(fromView, animated, false);
2903 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002904 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002905 dispatchOnLauncherTransitionStart(toView, animated, false);
2906 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002907 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002908 }
2909
2910 /**
2911 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002912 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002913 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002914 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002915 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2916 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002917
Michael Jurkab3e22d92011-10-31 15:58:33 -07002918 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002919 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002920 mStateAnimation.cancel();
2921 mStateAnimation = null;
2922 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002923 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002924
Winson Chungf0ea4d32011-06-06 14:27:16 -07002925 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002926 final int fadeOutDuration =
2927 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002928 final float scaleFactor = (float)
2929 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2930 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002931 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002932 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002933 if (toState == State.WORKSPACE) {
2934 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2935 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002936 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002937 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2938 workspaceAnim = mWorkspace.getChangeStateAnimation(
2939 Workspace.State.SPRING_LOADED, animated);
2940 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002941
Michael Jurkab3e22d92011-10-31 15:58:33 -07002942 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002943 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002944 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002945 final LauncherViewPropertyAnimator scaleAnim =
2946 new LauncherViewPropertyAnimator(fromView);
2947 scaleAnim.
2948 scaleX(scaleFactor).scaleY(scaleFactor).
2949 setDuration(duration).
2950 setInterpolator(new Workspace.ZoomInInterpolator());
2951
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002952 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002953 .ofFloat(fromView, "alpha", 1f, 0f)
2954 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002955 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002956 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2957 @Override
2958 public void onAnimationUpdate(ValueAnimator animation) {
2959 float t = 1f - (Float) animation.getAnimatedValue();
2960 dispatchOnLauncherTransitionStep(fromView, t);
2961 dispatchOnLauncherTransitionStep(toView, t);
2962 }
2963 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002964
Michael Jurka2ecf9952012-06-18 12:52:28 -07002965 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002966
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002967 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2968 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002969 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002970
2971 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002972 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002973 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002974 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002975 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2976 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002977 if (onCompleteRunnable != null) {
2978 onCompleteRunnable.run();
2979 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002980 mAppsCustomizeContent.updateCurrentPageScroll();
2981 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002982 }
2983 });
2984
Winson Chungf0ea4d32011-06-06 14:27:16 -07002985 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002986 if (workspaceAnim != null) {
2987 mStateAnimation.play(workspaceAnim);
2988 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002989 dispatchOnLauncherTransitionStart(fromView, animated, true);
2990 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002991 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002992 } else {
2993 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002994 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002995 dispatchOnLauncherTransitionStart(fromView, animated, true);
2996 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002997 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002998 dispatchOnLauncherTransitionStart(toView, animated, true);
2999 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003000 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003001 }
3002
Michael Jurkae326f182011-11-21 14:05:46 -08003003 @Override
3004 public void onTrimMemory(int level) {
3005 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003006 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003007 mAppsCustomizeTabHost.onTrimMemory();
3008 }
3009 }
3010
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003011 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003012 showWorkspace(animated, null);
3013 }
3014
3015 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003016 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003017 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003018 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003019 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003020
Winson Chungc7d2b602012-05-16 17:02:20 -07003021 // Show the search bar (only animate if we were showing the drop target bar in spring
3022 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003023 if (mSearchDropTargetBar != null) {
3024 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3025 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003026
Michael Jurkab3e22d92011-10-31 15:58:33 -07003027 // Set focus to the AppsCustomize button
3028 if (mAllAppsButton != null) {
3029 mAllAppsButton.requestFocus();
3030 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003031 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003032
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003033 // Change the state *after* we've called all the transition code
3034 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003035
Winson Chung5fb63472011-02-02 17:03:37 -08003036 // Resume the auto-advance of widgets
3037 mUserPresent = true;
3038 updateRunning();
3039
alanv1d4fde62012-10-17 13:15:47 -07003040 // Send an accessibility event to announce the context change
3041 getWindow().getDecorView()
3042 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003043
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003044 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003045 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003046 }
3047
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003048 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003049 }
3050
Winson Chungc58497e2013-09-03 17:48:37 -07003051 void showAllApps(boolean animated,
3052 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003053 if (mState != State.WORKSPACE) return;
3054
Winson Chungc58497e2013-09-03 17:48:37 -07003055 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003056 mAppsCustomizeTabHost.requestFocus();
3057
Michael Jurkab3e22d92011-10-31 15:58:33 -07003058 // Change the state *after* we've called all the transition code
3059 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003060 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003061
3062 // Pause the auto-advance of widgets until we are out of AllApps
3063 mUserPresent = false;
3064 updateRunning();
3065 closeFolder();
3066
3067 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003068 getWindow().getDecorView()
3069 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003070 }
3071
Adam Cohen7777d962011-08-18 18:58:38 -07003072 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003073 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003074 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003075 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003076 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003077 }
Adam Cohen7777d962011-08-18 18:58:38 -07003078
Adam Cohened66b2b2012-01-23 17:28:51 -08003079 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3080 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003081 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3082
Winson Chunge7a03942011-08-05 15:05:12 -07003083 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003084 @Override
3085 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003086 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003087 // Before we show workspace, hide all apps again because
3088 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3089 // clean up our state transition functions
3090 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003091 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003092 } else {
3093 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003094 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003095 }
3096 }, (extendedDelay ?
3097 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3098 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3099 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003100
Michael Jurkad3ef3062010-11-23 16:23:58 -08003101 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003102 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003103 final boolean animated = true;
3104 final boolean springLoaded = true;
3105 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003106 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003107 }
3108 // Otherwise, we are not in spring loaded mode, so don't do anything.
3109 }
3110
Michael Jurkab3e22d92011-10-31 15:58:33 -07003111 void lockAllApps() {
3112 // TODO
3113 }
3114
3115 void unlockAllApps() {
3116 // TODO
3117 }
3118
Winson Chungf0ea4d32011-06-06 14:27:16 -07003119 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003120 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003121 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003122 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003123 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003124 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003125 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003126 int duration = 0;
3127 if (mSearchDropTargetBar != null) {
3128 duration = mSearchDropTargetBar.getTransitionInDuration();
3129 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003130 mHotseat.animate().alpha(1f).setDuration(duration);
3131 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003132 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003133 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003134 }
3135 }
3136 }
3137
3138 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003139 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003140 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003142 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003143 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003144 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003145 int duration = 0;
3146 if (mSearchDropTargetBar != null) {
3147 duration = mSearchDropTargetBar.getTransitionOutDuration();
3148 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003149 mHotseat.animate().alpha(0f).setDuration(duration);
3150 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003151 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003152 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003154 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003155 }
3156
Patrick Dubroy5f445422011-02-18 14:35:21 -08003157 /**
3158 * Add an item from all apps or customize onto the given workspace screen.
3159 * If layout is null, add to the current screen.
3160 */
3161 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003162 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003163 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003164 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003165 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003166
Winson Chungdff8ebb2011-09-08 17:25:31 -07003167 /** Maps the current orientation to an index for referencing orientation correct global icons */
3168 private int getCurrentOrientationIndexForGlobalIcons() {
3169 // default - 0, landscape - 1
3170 switch (getResources().getConfiguration().orientation) {
3171 case Configuration.ORIENTATION_LANDSCAPE:
3172 return 1;
3173 default:
3174 return 0;
3175 }
3176 }
3177
Michael Jurkaae65ee32012-04-30 11:45:54 -07003178 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003179 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003180 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003181 // Look for the toolbar icon specified in the activity meta-data
3182 Bundle metaData = packageManager.getActivityInfo(
3183 activityName, PackageManager.GET_META_DATA).metaData;
3184 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003185 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003186 if (iconResId != 0) {
3187 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003188 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003189 }
3190 }
3191 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003192 // This can happen if the activity defines an invalid drawable
3193 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3194 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003195 } catch (Resources.NotFoundException nfe) {
3196 // This can happen if the activity defines an invalid drawable
3197 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3198 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003199 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003200 return null;
3201 }
3202
3203 // if successful in getting icon, return it; otherwise, set button to use default drawable
3204 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003205 int buttonId, ComponentName activityName, int fallbackDrawableId,
3206 String toolbarResourceName) {
3207 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003208 Resources r = getResources();
3209 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3210 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003211
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003212 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003213 // If we were unable to find the icon via the meta-data, use a generic one
3214 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003215 toolbarIcon = r.getDrawable(fallbackDrawableId);
3216 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003217 if (button != null) {
3218 button.setCompoundDrawables(toolbarIcon, null, null, null);
3219 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003220 return null;
3221 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003222 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003223 if (button != null) {
3224 button.setCompoundDrawables(toolbarIcon, null, null, null);
3225 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003226 return toolbarIcon.getConstantState();
3227 }
3228 }
3229
3230 // if successful in getting icon, return it; otherwise, set button to use default drawable
3231 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003232 int buttonId, ComponentName activityName, int fallbackDrawableId,
3233 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003234 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003235 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003236
Michael Jurka19e0fc52011-07-22 18:00:21 -07003237 if (button != null) {
3238 // If we were unable to find the icon via the meta-data, use a
3239 // generic one
3240 if (toolbarIcon == null) {
3241 button.setImageResource(fallbackDrawableId);
3242 } else {
3243 button.setImageDrawable(toolbarIcon);
3244 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003245 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003246
3247 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3248
Michael Jurka0423dcf2010-10-05 14:56:18 -07003249 }
3250
Winson Chung1b884092012-06-08 17:13:02 -07003251 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003252 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003253 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003254 }
3255
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003256 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003257 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003258 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003259 }
3260
Winson Chungbb185bd2011-11-21 12:31:42 -08003261 private void invalidatePressedFocusedStates(View container, View button) {
3262 if (container instanceof HolographicLinearLayout) {
3263 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3264 layout.invalidatePressedFocusedStates();
3265 } else if (button instanceof HolographicImageView) {
3266 HolographicImageView view = (HolographicImageView) button;
3267 view.invalidatePressedFocusedStates();
3268 }
3269 }
3270
Cristina Stancu476493b2013-08-07 17:20:14 +01003271 public View getQsbBar() {
3272 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003273 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3274 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003275 }
3276 return mQsbBar;
3277 }
3278
3279 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003280 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003281 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003282 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003283 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003284
Winson Chung1cad91e2011-05-25 17:41:01 -07003285 final SearchManager searchManager =
3286 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3287 ComponentName activityName = searchManager.getGlobalSearchActivity();
3288 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003289 int coi = getCurrentOrientationIndexForGlobalIcons();
3290 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003291 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3292 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3293 if (sGlobalSearchIcon[coi] == null) {
3294 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3295 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3296 TOOLBAR_ICON_METADATA_NAME);
3297 }
3298
Winson Chungc51db6a2011-10-05 11:44:49 -07003299 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3300 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003301 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003302 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003303 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003304 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003305 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3306 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003307 if (searchButton != null) searchButton.setVisibility(View.GONE);
3308 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003309 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003310 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003311 }
3312 }
3313
Cristina Stancu476493b2013-08-07 17:20:14 +01003314 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003315 final View searchButtonContainer = findViewById(R.id.search_button_container);
3316 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003317 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003318 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003319 }
3320
Cristina Stancu476493b2013-08-07 17:20:14 +01003321 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003322 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003323 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003324
Winson Chungc51db6a2011-10-05 11:44:49 -07003325 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003326 final SearchManager searchManager =
3327 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3328 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3329
3330 ComponentName activityName = null;
3331 if (globalSearchActivity != null) {
3332 // Check if the global search activity handles voice search
3333 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3334 intent.setPackage(globalSearchActivity.getPackageName());
3335 activityName = intent.resolveActivity(getPackageManager());
3336 }
3337
3338 if (activityName == null) {
3339 // Fallback: check if an activity other than the global search activity
3340 // resolves this
3341 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3342 activityName = intent.resolveActivity(getPackageManager());
3343 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003344 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003345 int coi = getCurrentOrientationIndexForGlobalIcons();
3346 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003347 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3348 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3349 if (sVoiceSearchIcon[coi] == null) {
3350 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3351 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3352 TOOLBAR_ICON_METADATA_NAME);
3353 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003354 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003355 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003356 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003357 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003358 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003359 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003360 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003361 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003362 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003363 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003364 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003365 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003366
Cristina Stancu476493b2013-08-07 17:20:14 +01003367 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003368 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3369 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003370 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003371 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003372 }
3373
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003374 public void setVoiceButtonProxyVisible(boolean visible) {
3375 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3376 if (voiceButtonProxy != null) {
3377 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3378 }
3379 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003380 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003381 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003382 */
3383 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003384 if (!DISABLE_MARKET_BUTTON) {
3385 final View marketButton = findViewById(R.id.market_button);
3386 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3387 // Find the app market activity by resolving an intent.
3388 // (If multiple app markets are installed, it will return the ResolverActivity.)
3389 ComponentName activityName = intent.resolveActivity(getPackageManager());
3390 if (activityName != null) {
3391 int coi = getCurrentOrientationIndexForGlobalIcons();
3392 mAppMarketIntent = intent;
3393 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3394 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3395 TOOLBAR_ICON_METADATA_NAME);
3396 marketButton.setVisibility(View.VISIBLE);
3397 } else {
3398 // We should hide and disable the view so that we don't try and restore the visibility
3399 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3400 marketButton.setVisibility(View.GONE);
3401 marketButton.setEnabled(false);
3402 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003403 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003404 }
3405
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003406 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003407 if (!DISABLE_MARKET_BUTTON) {
3408 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3409 Resources r = getResources();
3410 Drawable marketIconDrawable = d.newDrawable(r);
3411 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3412 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3413 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003414
Winson Chungd64a6662013-09-30 11:06:59 -07003415 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3416 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003417 }
3418
Michael Jurkad7c28052012-04-27 15:43:36 -07003419 @Override
3420 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003421 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003422 final List<CharSequence> text = event.getText();
3423 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003424 // Populate event with a fake title based on the current state.
3425 if (mState == State.APPS_CUSTOMIZE) {
3426 text.add(getString(R.string.all_apps_button_label));
3427 } else {
3428 text.add(getString(R.string.all_apps_home_button_label));
3429 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003430 return result;
3431 }
3432
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003433 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003434 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003435 */
3436 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3437 @Override
3438 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003439 closeSystemDialogs();
3440 }
3441 }
3442
3443 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003444 * Receives notifications whenever the appwidgets are reset.
3445 */
3446 private class AppWidgetResetObserver extends ContentObserver {
3447 public AppWidgetResetObserver() {
3448 super(new Handler());
3449 }
3450
3451 @Override
3452 public void onChange(boolean selfChange) {
3453 onAppWidgetReset();
3454 }
3455 }
3456
3457 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003458 * If the activity is currently paused, signal that we need to run the passed Runnable
3459 * in onResume.
3460 *
3461 * This needs to be called from incoming places where resources might have been loaded
3462 * while we are paused. That is becaues the Configuration might be wrong
3463 * when we're not running, and if it comes back to what it was when we
3464 * were paused, we are not restarted.
3465 *
3466 * Implementation of the method from LauncherModel.Callbacks.
3467 *
3468 * @return true if we are currently paused. The caller might be able to
3469 * skip some work in that case since we will come back again.
3470 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003471 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003472 if (mPaused) {
3473 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003474 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003475 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003476 }
3477 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003478 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003479 return true;
3480 } else {
3481 return false;
3482 }
3483 }
3484
Michael Jurkac402cd92013-05-20 15:49:32 +02003485 private boolean waitUntilResume(Runnable run) {
3486 return waitUntilResume(run, false);
3487 }
3488
Michael Jurka1e2f4652013-07-08 18:03:46 -07003489 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003490 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003491 }
3492
Michael Jurka7607c2f2013-04-03 14:33:19 -07003493 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003494 * If the activity is currently paused, signal that we need to re-run the loader
3495 * in onResume.
3496 *
3497 * This needs to be called from incoming places where resources might have been loaded
3498 * while we are paused. That is becaues the Configuration might be wrong
3499 * when we're not running, and if it comes back to what it was when we
3500 * were paused, we are not restarted.
3501 *
3502 * Implementation of the method from LauncherModel.Callbacks.
3503 *
3504 * @return true if we are currently paused. The caller might be able to
3505 * skip some work in that case since we will come back again.
3506 */
3507 public boolean setLoadOnResume() {
3508 if (mPaused) {
3509 Log.i(TAG, "setLoadOnResume");
3510 mOnResumeNeedsLoad = true;
3511 return true;
3512 } else {
3513 return false;
3514 }
3515 }
3516
3517 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003518 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003519 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003520 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003521 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003522 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003523 } else {
3524 return SCREEN_COUNT / 2;
3525 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003526 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003527
Joe Onorato9c1289c2009-08-17 11:03:03 -04003528 /**
3529 * Refreshes the shortcuts shown on the workspace.
3530 *
3531 * Implementation of the method from LauncherModel.Callbacks.
3532 */
3533 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003534 // If we're starting binding all over again, clear any bind calls we'd postponed in
3535 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3536 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003537 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003538
Winson Chungd64d1762013-08-20 14:37:16 -07003539 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003540 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003541 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003542
Michael Jurka05bf644e2011-11-30 20:28:53 -08003543 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003544 if (mHotseat != null) {
3545 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003546 }
3547 }
3548
Adam Cohendcd297f2013-06-18 13:13:40 -07003549 @Override
3550 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003551 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003552
Adam Cohen5084cba2013-09-03 12:01:16 -07003553 // If there are no screens, we need to have an empty screen
3554 if (orderedScreenIds.size() == 0) {
3555 mWorkspace.addExtraEmptyScreen();
3556 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003557
3558 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003559 // setCurrentPage() so ensure that all pages are added before calling this).
3560 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003561 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3562 mWorkspace.createCustomContentPage();
3563 }
Winson Chung64359a52013-07-08 17:17:08 -07003564 }
3565
3566 @Override
3567 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003568 int count = orderedScreenIds.size();
3569 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003570 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003571 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003572 }
3573
Adam Cohen39a06042013-07-19 14:30:12 -07003574 private boolean shouldShowWeightWatcher() {
3575 String spKey = LauncherAppState.getSharedPreferencesKey();
3576 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003577 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003578
3579 return show;
3580 }
3581
Adam Cohen4caf2982013-08-20 18:54:31 -07003582 private boolean emailSent() {
3583 String spKey = LauncherAppState.getSharedPreferencesKey();
3584 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3585 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3586 return show;
3587 }
3588
3589 private void setEmailSent(boolean sent) {
3590 String spKey = LauncherAppState.getSharedPreferencesKey();
3591 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3592
3593 SharedPreferences.Editor editor = sp.edit();
3594 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3595 editor.commit();
3596 }
3597
Adam Cohen39a06042013-07-19 14:30:12 -07003598 private void toggleShowWeightWatcher() {
3599 String spKey = LauncherAppState.getSharedPreferencesKey();
3600 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3601 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3602
3603 show = !show;
3604
3605 SharedPreferences.Editor editor = sp.edit();
3606 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3607 editor.commit();
3608
3609 if (mWeightWatcher != null) {
3610 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3611 }
3612 }
3613
Winson Chungd64d1762013-08-20 14:37:16 -07003614 public void bindAppsAdded(final ArrayList<Long> newScreens,
3615 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003616 final ArrayList<ItemInfo> addAnimated,
3617 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003618 Runnable r = new Runnable() {
3619 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003620 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003621 }
3622 };
3623 if (waitUntilResume(r)) {
3624 return;
3625 }
3626
Winson Chungd64d1762013-08-20 14:37:16 -07003627 // Add the new screens
3628 bindAddScreens(newScreens);
3629
3630 // We add the items without animation on non-visible pages, and with
3631 // animations on the new page (which we will try and snap to).
3632 if (!addNotAnimated.isEmpty()) {
3633 bindItems(addNotAnimated, 0,
3634 addNotAnimated.size(), false);
3635 }
3636 if (!addAnimated.isEmpty()) {
3637 bindItems(addAnimated, 0,
3638 addAnimated.size(), true);
3639 }
Winson Chungc58497e2013-09-03 17:48:37 -07003640
3641 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3642 addedApps != null && mAppsCustomizeContent != null) {
3643 mAppsCustomizeContent.addApps(addedApps);
3644 }
Winson Chungd64d1762013-08-20 14:37:16 -07003645 }
3646
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003647 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003648 * Bind the items start-end from the list.
3649 *
3650 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003651 */
Winson Chung64359a52013-07-08 17:17:08 -07003652 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3653 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003654 Runnable r = new Runnable() {
3655 public void run() {
3656 bindItems(shortcuts, start, end, forceAnimateIcons);
3657 }
3658 };
3659 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003660 return;
3661 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003662
Winson Chungf0c6ae02012-03-21 16:10:31 -07003663 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003664 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3665 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003666 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003667 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003668 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003669 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003670 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003671
3672 // Short circuit if we are loading dock items for a configuration which has no dock
3673 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3674 mHotseat == null) {
3675 continue;
3676 }
3677
Joe Onorato9c1289c2009-08-17 11:03:03 -04003678 switch (item.itemType) {
3679 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3680 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003681 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003682 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003683
Winson Chung64359a52013-07-08 17:17:08 -07003684 /*
3685 * TODO: FIX collision case
3686 */
Winson Chungce376632013-07-11 16:12:41 -07003687 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3688 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3689 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3690 throw new RuntimeException("OCCUPIED");
3691 }
Winson Chung64359a52013-07-08 17:17:08 -07003692 }
3693
Adam Cohendcd297f2013-06-18 13:13:40 -07003694 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3695 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003696 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003697 // Animate all the applications up now
3698 shortcut.setAlpha(0f);
3699 shortcut.setScaleX(0f);
3700 shortcut.setScaleY(0f);
3701 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003702 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003703 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003704 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003705 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003706 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003707 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003708 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003709 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3710 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003711 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003712 default:
3713 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003714 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003715 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003716
Winson Chung997a9232013-07-24 15:33:46 -07003717 if (animateIcons) {
3718 // Animate to the correct page
3719 if (newShortcutsScreenId > -1) {
3720 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003721 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003722 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003723 // We post the animation slightly delayed to prevent slowdowns
3724 // when we are loading right after we return to launcher.
3725 mWorkspace.postDelayed(new Runnable() {
3726 public void run() {
3727 mWorkspace.snapToPage(newScreenIndex);
3728 mWorkspace.postDelayed(new Runnable() {
3729 public void run() {
3730 anim.playTogether(bounceAnims);
3731 anim.start();
3732 }
3733 }, NEW_APPS_ANIMATION_DELAY);
3734 }
3735 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003736 }
3737 }
Winson Chung64359a52013-07-08 17:17:08 -07003738 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003739 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003740 }
3741
Joe Onorato9c1289c2009-08-17 11:03:03 -04003742 /**
3743 * Implementation of the method from LauncherModel.Callbacks.
3744 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003745 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003746 Runnable r = new Runnable() {
3747 public void run() {
3748 bindFolders(folders);
3749 }
3750 };
3751 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003752 return;
3753 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003754 sFolders.clear();
3755 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003756 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003757
3758 /**
3759 * Add the views for a widget to the workspace.
3760 *
3761 * Implementation of the method from LauncherModel.Callbacks.
3762 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003763 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003764 Runnable r = new Runnable() {
3765 public void run() {
3766 bindAppWidget(item);
3767 }
3768 };
3769 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003770 return;
3771 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003772
Daniel Sandler843e8602010-06-07 14:59:01 -04003773 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3774 if (DEBUG_WIDGETS) {
3775 Log.d(TAG, "bindAppWidget: " + item);
3776 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777 final Workspace workspace = mWorkspace;
3778
3779 final int appWidgetId = item.appWidgetId;
3780 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003781 if (DEBUG_WIDGETS) {
3782 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3783 }
3784
Joe Onorato9c1289c2009-08-17 11:03:03 -04003785 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3786
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003788 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003789
Adam Cohendcd297f2013-06-18 13:13:40 -07003790 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003791 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003792 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3793
Joe Onorato9c1289c2009-08-17 11:03:03 -04003794 workspace.requestLayout();
3795
Daniel Sandler843e8602010-06-07 14:59:01 -04003796 if (DEBUG_WIDGETS) {
3797 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3798 + (SystemClock.uptimeMillis()-start) + "ms");
3799 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003800 }
3801
Adam Cohen1462de32012-07-24 22:34:36 -07003802 public void onPageBoundSynchronously(int page) {
3803 mSynchronouslyBoundPages.add(page);
3804 }
3805
Joe Onorato9c1289c2009-08-17 11:03:03 -04003806 /**
3807 * Callback saying that there aren't any more items to bind.
3808 *
3809 * Implementation of the method from LauncherModel.Callbacks.
3810 */
Adam Cohene25af792013-06-06 23:08:25 -07003811 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003812 Runnable r = new Runnable() {
3813 public void run() {
3814 finishBindingItems(upgradePath);
3815 }
3816 };
3817 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003818 return;
3819 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003820 if (mSavedState != null) {
3821 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003822 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003823 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003824 mSavedState = null;
3825 }
3826
Adam Cohen1462de32012-07-24 22:34:36 -07003827 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003828
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003829 // If we received the result of any pending adds while the loader was running (e.g. the
3830 // widget configuration forced an orientation change), process them now.
3831 for (int i = 0; i < sPendingAddList.size(); i++) {
3832 completeAdd(sPendingAddList.get(i));
3833 }
3834 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003835
Winson Chungc51db6a2011-10-05 11:44:49 -07003836 // Update the market app icon as necessary (the other icons will be managed in response to
3837 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003838 if (!DISABLE_MARKET_BUTTON) {
3839 updateAppMarketIcon();
3840 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003841
Winson Chungf0c6ae02012-03-21 16:10:31 -07003842 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003843 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003844 mWorkspace.getUniqueComponents(true, null);
3845 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003846 }
Adam Cohen99894d92013-06-14 11:22:59 -07003847
Adam Cohen66a01fd2013-06-11 12:48:00 -07003848 mWorkspace.post(new Runnable() {
3849 @Override
3850 public void run() {
3851 onFinishBindingItems();
3852 }
3853 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003854 }
3855
Winson Chunga0b7e862013-09-05 16:03:15 -07003856 public boolean isAllAppsButtonRank(int rank) {
3857 if (mHotseat != null) {
3858 return mHotseat.isAllAppsButtonRank(rank);
3859 }
3860 return false;
3861 }
3862
Winson Chunga2413752012-04-03 14:22:34 -07003863 private boolean canRunNewAppsAnimation() {
3864 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3865 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3866 }
3867
Winson Chungc9168342013-06-26 14:54:55 -07003868 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3869 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3870 PropertyValuesHolder.ofFloat("alpha", 1f),
3871 PropertyValuesHolder.ofFloat("scaleX", 1f),
3872 PropertyValuesHolder.ofFloat("scaleY", 1f));
3873 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3874 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3875 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3876 return bounceAnim;
3877 }
3878
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003879 @Override
3880 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003881 boolean searchVisible = updateGlobalSearchIcon();
3882 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003883 if (mSearchDropTargetBar != null) {
3884 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3885 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003886 }
3887
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003888 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003889 * Add the icons for all apps.
3890 *
3891 * Implementation of the method from LauncherModel.Callbacks.
3892 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003893 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003894 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3895 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3896 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3897 getHotseat().addAllAppsFolder(mIconCache, apps,
3898 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3899 }
3900 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003901 }
Winson Chungc58497e2013-09-03 17:48:37 -07003902 } else {
3903 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3904 mAppsCustomizeContent != null) {
3905 mAppsCustomizeContent.setApps(apps);
3906 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003907 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003908 }
3909
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003910 @Override
3911 public boolean shouldShowApp(ResolveInfo app) {
3912 return true;
3913 }
3914
Joe Onorato9c1289c2009-08-17 11:03:03 -04003915 /**
3916 * A package was updated.
3917 *
3918 * Implementation of the method from LauncherModel.Callbacks.
3919 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003920 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003921 Runnable r = new Runnable() {
3922 public void run() {
3923 bindAppsUpdated(apps);
3924 }
3925 };
3926 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003927 return;
3928 }
3929
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003930 if (mWorkspace != null) {
3931 mWorkspace.updateShortcuts(apps);
3932 }
Winson Chungc58497e2013-09-03 17:48:37 -07003933
3934 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3935 mAppsCustomizeContent != null) {
3936 mAppsCustomizeContent.updateApps(apps);
3937 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003938 }
3939
3940 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003941 * A package was uninstalled. We take both the super set of packageNames
3942 * in addition to specific applications to remove, the reason being that
3943 * this can be called when a package is updated as well. In that scenario,
3944 * we only remove specific components from the workspace, where as
3945 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003946 *
3947 * Implementation of the method from LauncherModel.Callbacks.
3948 */
Winson Chung83892cc2013-05-01 16:53:33 -07003949 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003950 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003951 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003952 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003953 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003954 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003955 }
Winson Chungd64d1762013-08-20 14:37:16 -07003956 };
3957 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003958 return;
3959 }
3960
Winson Chung64359a52013-07-08 17:17:08 -07003961 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003962 mWorkspace.removeItemsByPackageName(packageNames);
3963 } else {
3964 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003965 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003966
Winson Chunga1820962011-10-03 16:31:06 -07003967 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003968 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003969
3970 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3971 mAppsCustomizeContent != null) {
3972 mAppsCustomizeContent.removeApps(appInfos);
3973 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003974 }
Joe Onoratobe386092009-11-17 17:32:16 -08003975
3976 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003977 * A number of packages were updated.
3978 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003979 private ArrayList<Object> mWidgetsAndShortcuts;
3980 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003981 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003982 bindPackagesUpdated(mWidgetsAndShortcuts);
3983 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003984 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003985 };
3986
3987 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3988 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3989 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003990 return;
3991 }
3992
Winson Chung64359a52013-07-08 17:17:08 -07003993 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003994 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3995 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003996 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003997 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003998 }
3999
Winson Chung400438b2011-01-16 17:53:48 -08004000 private int mapConfigurationOriActivityInfoOri(int configOri) {
4001 final Display d = getWindowManager().getDefaultDisplay();
4002 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4003 switch (d.getRotation()) {
4004 case Surface.ROTATION_0:
4005 case Surface.ROTATION_180:
4006 // We are currently in the same basic orientation as the natural orientation
4007 naturalOri = configOri;
4008 break;
4009 case Surface.ROTATION_90:
4010 case Surface.ROTATION_270:
4011 // We are currently in the other basic orientation to the natural orientation
4012 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4013 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4014 break;
4015 }
4016
4017 int[] oriMap = {
4018 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4019 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4020 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4021 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4022 };
4023 // Since the map starts at portrait, we need to offset if this device's natural orientation
4024 // is landscape.
4025 int indexOffset = 0;
4026 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4027 indexOffset = 1;
4028 }
4029 return oriMap[(d.getRotation() + indexOffset) % 4];
4030 }
Adam Cohen446e9402011-09-15 18:21:21 -07004031
Winson Chung4b919f82012-05-01 10:44:08 -07004032 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004033 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004034 getResources().getBoolean(R.bool.allow_rotation);
4035 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004036 }
Winson Chung4b919f82012-05-01 10:44:08 -07004037 public void lockScreenOrientation() {
4038 if (isRotationEnabled()) {
4039 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4040 .getConfiguration().orientation));
4041 }
4042 }
4043 public void unlockScreenOrientation(boolean immediate) {
4044 if (isRotationEnabled()) {
4045 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004046 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004047 } else {
4048 mHandler.postDelayed(new Runnable() {
4049 public void run() {
4050 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4051 }
4052 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004053 }
Winson Chung4b919f82012-05-01 10:44:08 -07004054 }
Winson Chung400438b2011-01-16 17:53:48 -08004055 }
4056
Winson Chung82f55532011-08-09 14:14:23 -07004057 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004058 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004059 if (DISABLE_CLINGS) {
4060 return false;
4061 }
4062
Brett Chabot2a9e2282011-08-23 15:03:13 -07004063 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004064 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004065
Michael Jurkae233a8b2013-03-19 13:49:20 +01004066 // Restricted secondary users (child mode) will potentially have very few apps
4067 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004068// boolean supportsLimitedUsers =
4069// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4070// Account[] accounts = AccountManager.get(this).getAccounts();
4071// if (supportsLimitedUsers && accounts.length == 0) {
4072// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4073// Bundle restrictions = um.getUserRestrictions();
4074// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4075// return false;
4076// }
4077// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004078 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004079 }
Michael Jurka22143132012-10-04 17:42:38 +02004080
Winson Chungfa545132013-09-26 17:45:32 -07004081 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004082 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004083 Cling cling = (Cling) findViewById(clingId);
4084 View scrim = null;
4085 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004086 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004087 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004088 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004089 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004090 cling.show(animate, SHOW_CLING_DURATION);
4091
4092 if (dimNavBarVisibilty) {
4093 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4094 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004095 }
4096 }
4097 return cling;
4098 }
Michael Jurka22143132012-10-04 17:42:38 +02004099
Winson Chungaf40f202013-09-18 18:26:31 -07004100 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4101 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004102 // To catch cases where siblings of top-level views are made invisible, just check whether
4103 // the cling is directly set to GONE before dismissing it.
4104 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004105 final Runnable cleanUpClingCb = new Runnable() {
4106 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004107 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004108 // We should update the shared preferences on a background thread
4109 new Thread("dismissClingThread") {
4110 public void run() {
4111 SharedPreferences.Editor editor = mSharedPrefs.edit();
4112 editor.putBoolean(flag, true);
4113 editor.commit();
4114 }
4115 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004116 if (postAnimationCb != null) {
4117 postAnimationCb.run();
4118 }
4119 }
4120 };
4121 if (duration <= 0) {
4122 cleanUpClingCb.run();
4123 } else {
4124 cling.hide(duration, cleanUpClingCb);
4125 }
Michael Jurka22143132012-10-04 17:42:38 +02004126 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004127
4128 if (restoreNavBarVisibilty) {
4129 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4130 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4131 }
Winson Chung82f55532011-08-09 14:14:23 -07004132 }
4133 }
Michael Jurka22143132012-10-04 17:42:38 +02004134
Winson Chung9d9d74f2011-09-19 11:49:12 -07004135 private void removeCling(int id) {
4136 final View cling = findViewById(id);
4137 if (cling != null) {
4138 final ViewGroup parent = (ViewGroup) cling.getParent();
4139 parent.post(new Runnable() {
4140 @Override
4141 public void run() {
4142 parent.removeView(cling);
4143 }
4144 });
Michael Jurka22143132012-10-04 17:42:38 +02004145 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004146 }
4147 }
Michael Jurka974c3862012-05-22 22:00:31 -07004148
4149 private boolean skipCustomClingIfNoAccounts() {
4150 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4151 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4152 if (customCling) {
4153 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004154 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004155 Account[] accounts = am.getAccountsByType("com.google");
4156 return accounts.length == 0;
4157 }
4158 return false;
4159 }
4160
Winson Chungaf40f202013-09-18 18:26:31 -07004161 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004162 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004163 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004164 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004165 // If we're not using the default workspace layout, replace workspace cling
4166 // with a custom workspace cling (usually specified in an overlay)
4167 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004168 if (!DISABLE_CUSTOM_CLINGS) {
4169 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4170 getResources().getBoolean(R.bool.config_useCustomClings)) {
4171 // Use a custom cling
4172 View cling = findViewById(R.id.workspace_cling);
4173 ViewGroup clingParent = (ViewGroup) cling.getParent();
4174 int clingIndex = clingParent.indexOfChild(cling);
4175 clingParent.removeViewAt(clingIndex);
4176 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4177 clingParent.addView(customCling, clingIndex);
4178 customCling.setId(R.id.workspace_cling);
4179 }
4180 }
4181 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4182 if (cling != null) {
4183 String sbHintStr = getFirstRunClingSearchBarHint();
4184 String ccHintStr = getFirstRunCustomContentHint();
4185 if (!sbHintStr.isEmpty()) {
4186 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4187 sbHint.setText(sbHintStr);
4188 sbHint.setVisibility(View.VISIBLE);
4189 }
4190 if (!ccHintStr.isEmpty()) {
4191 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4192 ccHint.setText(ccHintStr);
4193 ccHint.setVisibility(View.VISIBLE);
4194 }
Michael Jurka45355c42012-10-08 13:21:35 +02004195 }
Winson Chungfa545132013-09-26 17:45:32 -07004196 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004197 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004198 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004199 }
4200 }
Winson Chungaf40f202013-09-18 18:26:31 -07004201
Winson Chunge6eabff2013-09-24 11:01:23 -07004202 protected String getFirstRunClingSearchBarHint() {
4203 return "";
4204 }
4205 protected String getFirstRunCustomContentHint() {
4206 return "";
4207 }
4208
Winson Chungaf40f202013-09-18 18:26:31 -07004209 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004210 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004211 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004212 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004213 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004214 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004215 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004216 }
4217 }
4218 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004219 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004220 if (isClingsEnabled() &&
4221 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004222 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4223 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004224 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004225 } else {
4226 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004227 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004228 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004229 }
Michael Jurka104c4562013-07-08 18:03:46 -07004230 protected SharedPreferences getSharedPrefs() {
4231 return mSharedPrefs;
4232 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004233 public boolean isFolderClingVisible() {
4234 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004235 if (cling != null) {
4236 return cling.getVisibility() == View.VISIBLE;
4237 }
4238 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004239 }
Winson Chungaf40f202013-09-18 18:26:31 -07004240 public void dismissFirstRunCling(View v) {
4241 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4242 Runnable cb = new Runnable() {
4243 public void run() {
4244 // Show the workspace cling next
4245 showFirstRunWorkspaceCling();
4246 }
4247 };
4248 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4249 DISMISS_CLING_DURATION, false);
4250 }
Winson Chung82f55532011-08-09 14:14:23 -07004251 public void dismissWorkspaceCling(View v) {
4252 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004253 Runnable cb = null;
4254 if (v == null) {
4255 cb = new Runnable() {
4256 public void run() {
4257 mWorkspace.enterOverviewMode();
4258 }
4259 };
4260 }
4261 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4262 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004263 }
4264 public void dismissFolderCling(View v) {
4265 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004266 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4267 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004268 }
4269
Winson Chung80baf5a2010-08-09 16:03:15 -07004270 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004271 * Prints out out state for debugging.
4272 */
4273 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004274 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004275 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004276 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4277 Log.d(TAG, "mRestoring=" + mRestoring);
4278 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4279 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004280 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004281 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004282
Winson Chung785d2eb2011-04-14 16:08:02 -07004283 if (mAppsCustomizeContent != null) {
4284 mAppsCustomizeContent.dumpState();
4285 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004286 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004287 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004288
4289 @Override
4290 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4291 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004292 synchronized (sDumpLogs) {
4293 writer.println(" ");
4294 writer.println("Debug logs: ");
4295 for (int i = 0; i < sDumpLogs.size(); i++) {
4296 writer.println(" " + sDumpLogs.get(i));
4297 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004298 }
4299 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004300
4301 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004302 if (DEBUG_DUMP_LOG) {
4303 synchronized (sDumpLogs) {
4304 Log.d(TAG, "");
4305 Log.d(TAG, "*********************");
4306 Log.d(TAG, "Launcher debug logs: ");
4307 for (int i = 0; i < sDumpLogs.size(); i++) {
4308 Log.d(TAG, " " + sDumpLogs.get(i));
4309 }
4310 Log.d(TAG, "*********************");
4311 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004312 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004313 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004314 }
4315
4316 public static void addDumpLog(String tag, String log, boolean debugLog) {
4317 if (debugLog) {
4318 Log.d(tag, log);
4319 }
Winson Chungede41292013-09-19 16:27:36 -07004320 if (DEBUG_DUMP_LOG) {
4321 sDateStamp.setTime(System.currentTimeMillis());
4322 synchronized (sDumpLogs) {
4323 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004324 }
Winson Chungede41292013-09-19 16:27:36 -07004325 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004326 }
4327
Winson Chungede41292013-09-19 16:27:36 -07004328 public void dumpLogsToLocalData() {
4329 if (DEBUG_DUMP_LOG) {
4330 new Thread("DumpLogsToLocalData") {
4331 @Override
4332 public void run() {
4333 boolean success = false;
4334 sDateStamp.setTime(sRunStart);
4335 String FILENAME = sDateStamp.getMonth() + "-"
4336 + sDateStamp.getDay() + "_"
4337 + sDateStamp.getHours() + "-"
4338 + sDateStamp.getMinutes() + "_"
4339 + sDateStamp.getSeconds() + ".txt";
4340
4341 FileOutputStream fos = null;
4342 File outFile = null;
4343 try {
4344 outFile = new File(getFilesDir(), FILENAME);
4345 outFile.createNewFile();
4346 fos = new FileOutputStream(outFile);
4347 } catch (Exception e) {
4348 e.printStackTrace();
4349 }
4350 if (fos != null) {
4351 PrintWriter writer = new PrintWriter(fos);
4352
4353 writer.println(" ");
4354 writer.println("Debug logs: ");
4355 synchronized (sDumpLogs) {
4356 for (int i = 0; i < sDumpLogs.size(); i++) {
4357 writer.println(" " + sDumpLogs.get(i));
4358 }
4359 }
4360 writer.close();
4361 }
4362 try {
4363 if (fos != null) {
4364 fos.close();
4365 success = true;
4366 }
4367 } catch (IOException e) {
4368 e.printStackTrace();
4369 }
4370 }
4371 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004372 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004373 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004374}
Michael Jurka2763be32011-02-24 11:19:57 -08004375
Michael Jurkaabded662011-03-04 12:06:57 -08004376interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004377 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004378 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004379 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004380 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004381 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004382}