blob: 7ae429dae10644fe11bd3f8eb336844c0f84590b [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 Cohen61f560d2013-09-30 15:58:20 -0700284 private View.OnTouchListener mHapticFeedbackTouchListener;
285
Adam Cohended9f8d2010-11-03 13:25:16 -0700286 // Related to the auto-advancing of widgets
287 private final int ADVANCE_MSG = 1;
288 private final int mAdvanceInterval = 20000;
289 private final int mAdvanceStagger = 250;
290 private long mAutoAdvanceSentTime;
291 private long mAutoAdvanceTimeLeft = -1;
292 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
293 new HashMap<View, AppWidgetProviderInfo>();
294
Winson Chung400438b2011-01-16 17:53:48 -0800295 // Determines how long to wait after a rotation before restoring the screen orientation to
296 // match the sensor state.
297 private final int mRestoreScreenOrientationDelay = 500;
298
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700300 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
302 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
Winson Chungd64a6662013-09-30 11:06:59 -0700304 private Intent mAppMarketIntent = null;
305 private static final boolean DISABLE_MARKET_BUTTON = true;
306
Craig Mautner360310b2012-10-26 15:13:08 -0700307 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700308
Adam Cohen1462de32012-07-24 22:34:36 -0700309 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
310
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700311 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700312 static Date sDateStamp = new Date();
313 static DateFormat sDateFormat =
314 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
315 static long sRunStart = System.currentTimeMillis();
316 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700317
Winson Chung46353de2012-02-16 14:05:10 -0800318 // We only want to get the SharedPreferences once since it does an FS stat each time we get
319 // it from the context.
320 private SharedPreferences mSharedPrefs;
321
Adam Cohene25af792013-06-06 23:08:25 -0700322 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
323
Winson Chungf0c6ae02012-03-21 16:10:31 -0700324 // Holds the page that we need to animate to, and the icon views that we need to animate up
325 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700326 private ImageView mFolderIconImageView;
327 private Bitmap mFolderIconBitmap;
328 private Canvas mFolderIconCanvas;
329 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700330
Michael Jurkaddd62e92011-02-16 17:49:14 -0800331 private BubbleTextView mWaitingForResume;
332
Michael Jurka22143132012-10-04 17:42:38 +0200333 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
334 = new HideFromAccessibilityHelper();
335
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 private Runnable mBuildLayersRunnable = new Runnable() {
337 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700338 if (mWorkspace != null) {
339 mWorkspace.buildPageHardwareLayers();
340 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700341 }
342 };
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static ArrayList<PendingAddArguments> sPendingAddList
345 = new ArrayList<PendingAddArguments>();
346
Michael Jurka0a457bf2012-11-19 14:05:05 -0800347 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
348
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 private static class PendingAddArguments {
350 int requestCode;
351 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700352 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700353 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int cellX;
355 int cellY;
356 }
357
Daniel Sandlerff02d492013-08-05 02:12:05 -0400358 private Stats mStats;
359
Michael Jurka0a457bf2012-11-19 14:05:05 -0800360 private static boolean isPropertyEnabled(String propertyName) {
361 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700362 }
363
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 @Override
365 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700366 if (DEBUG_STRICT_MODE) {
367 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
368 .detectDiskReads()
369 .detectDiskWrites()
370 .detectNetwork() // or .detectAll() for all detectable problems
371 .penaltyLog()
372 .build());
373 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
374 .detectLeakedSqlLiteObjects()
375 .detectLeakedClosableObjects()
376 .penaltyLog()
377 .penaltyDeath()
378 .build());
379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400382
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400383 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400384 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700385
386 // Determine the dynamic grid properties
387 Point smallestSize = new Point();
388 Point largestSize = new Point();
389 Point realSize = new Point();
390 Display display = getWindowManager().getDefaultDisplay();
391 display.getCurrentSizeRange(smallestSize, largestSize);
392 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700393 DisplayMetrics dm = new DisplayMetrics();
394 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700395 // Lazy-initialize the dynamic grid
396 DeviceProfile grid = app.initDynamicGrid(this,
397 Math.min(smallestSize.x, smallestSize.y),
398 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700399 realSize.x, realSize.y,
400 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700401
402 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400403 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700404 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800405 mModel = app.setLauncher(this);
406 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400407 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700409
Daniel Sandlerff02d492013-08-05 02:12:05 -0400410 mStats = new Stats(this);
411
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700412 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700413 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
414 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700415
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700416 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
417 // this also ensures that any synchronous binding below doesn't re-trigger another
418 // LauncherModel load.
419 mPaused = false;
420
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200422 android.os.Debug.startMethodTracing(
423 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 }
425
426 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 setContentView(R.layout.launcher);
428 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100429 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800431 registerContentObservers();
432
Joe Onorato7c312c12009-08-13 21:36:53 -0700433 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700434
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 mSavedState = savedInstanceState;
436 restoreState(mSavedState);
437
Winson Chunga12a2502010-12-20 14:41:35 -0800438 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700439 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200440 mAppsCustomizeContent.onPackagesUpdated(
441 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700442 }
Winson Chunga12a2502010-12-20 14:41:35 -0800443
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 if (PROFILE_STARTUP) {
445 android.os.Debug.stopMethodTracing();
446 }
447
448 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700449 if (sPausedFromUserAction) {
450 // If the user leaves launcher, then we should just load items asynchronously when
451 // they return.
452 mModel.startLoader(true, -1);
453 } else {
454 // We only load the page synchronously if the user rotates (or triggers a
455 // configuration change) while launcher is in the foreground
456 mModel.startLoader(true, mWorkspace.getCurrentPage());
457 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 }
459
460 // For handling default keys
461 mDefaultKeySsb = new SpannableStringBuilder();
462 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800463
464 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
465 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800466
Adam Cohenf9426d52012-06-04 17:26:21 -0700467 updateGlobalIcons();
468
469 // On large interfaces, we want the screen to auto-rotate based on the current orientation
470 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700471
472 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700473 }
474
Winson Chung4a2afa32012-07-19 14:53:05 -0700475 protected void onUserLeaveHint() {
476 super.onUserLeaveHint();
477 sPausedFromUserAction = true;
478 }
479
Winson Chung98ca0f72013-07-29 12:58:51 -0700480 /** To be overriden by subclasses to hint to Launcher that we have custom content */
481 protected boolean hasCustomContentToLeft() {
482 return false;
483 }
484
Dave Hawkeya8881582013-09-17 15:55:33 -0600485 /**
486 * To be overridden by subclasses to create the custom content and call
487 * {@link #addToCustomContentPage}. This will only be invoked if
488 * {@link #hasCustomContentToLeft()} is {@code true}.
489 */
490 protected void addCustomContentToLeft() {
491 }
492
493 /**
494 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
495 * ensure the custom content page is added or removed if necessary.
496 */
497 protected void invalidateHasCustomContentToLeft() {
498 if (mWorkspace.getScreenOrder().isEmpty()) {
499 // Not bound yet, wait for bindScreens to be called.
500 return;
501 }
502
503 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
504 // Create the custom content page and call the subclass to populate it.
505 mWorkspace.createCustomContentPage();
506 addCustomContentToLeft();
507 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
508 mWorkspace.removeCustomContentPage();
509 }
510 }
511
Adam Cohenf9426d52012-06-04 17:26:21 -0700512 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700513 boolean searchVisible = false;
514 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800515 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700516 int coi = getCurrentOrientationIndexForGlobalIcons();
517 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
518 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700519 if (!DISABLE_MARKET_BUTTON) {
520 updateAppMarketIcon();
521 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 searchVisible = updateGlobalSearchIcon();
523 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700524 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700525 if (sGlobalSearchIcon[coi] != null) {
526 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700527 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700528 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700529 if (sVoiceSearchIcon[coi] != null) {
530 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700531 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700532 }
Winson Chungd64a6662013-09-30 11:06:59 -0700533 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700534 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800535 }
Winson Chungadf0c182012-08-23 14:59:07 -0700536 if (mSearchDropTargetBar != null) {
537 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
538 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 }
Romain Guycbb89e42009-06-08 15:52:54 -0700540
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800541 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700542 if (sLocaleConfiguration == null) {
543 new AsyncTask<Void, Void, LocaleConfiguration>() {
544 @Override
545 protected LocaleConfiguration doInBackground(Void... unused) {
546 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
547 readConfiguration(Launcher.this, localeConfiguration);
548 return localeConfiguration;
549 }
550
551 @Override
552 protected void onPostExecute(LocaleConfiguration result) {
553 sLocaleConfiguration = result;
554 checkForLocaleChange(); // recursive, but now with a locale configuration
555 }
556 }.execute();
557 return;
558 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700559
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 final Configuration configuration = getResources().getConfiguration();
561
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700562 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 final String locale = configuration.locale.toString();
564
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 final int mcc = configuration.mcc;
567
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 final int mnc = configuration.mnc;
570
Romain Guy84f296c2009-11-04 15:00:44 -0800571 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572
Romain Guy84f296c2009-11-04 15:00:44 -0800573 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 sLocaleConfiguration.locale = locale;
575 sLocaleConfiguration.mcc = mcc;
576 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700577
Joe Onorato0589f0f2010-02-08 13:44:00 -0800578 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700579
580 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
581 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700582 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700583 public void run() {
584 writeConfiguration(Launcher.this, localeConfiguration);
585 }
586 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700587 }
588 }
589
590 private static class LocaleConfiguration {
591 public String locale;
592 public int mcc = -1;
593 public int mnc = -1;
594 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700595
Romain Guy98d01652009-06-30 16:21:04 -0700596 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
597 DataInputStream in = null;
598 try {
599 in = new DataInputStream(context.openFileInput(PREFERENCES));
600 configuration.locale = in.readUTF();
601 configuration.mcc = in.readInt();
602 configuration.mnc = in.readInt();
603 } catch (FileNotFoundException e) {
604 // Ignore
605 } catch (IOException e) {
606 // Ignore
607 } finally {
608 if (in != null) {
609 try {
610 in.close();
611 } catch (IOException e) {
612 // Ignore
613 }
614 }
615 }
616 }
617
618 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
619 DataOutputStream out = null;
620 try {
621 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
622 out.writeUTF(configuration.locale);
623 out.writeInt(configuration.mcc);
624 out.writeInt(configuration.mnc);
625 out.flush();
626 } catch (FileNotFoundException e) {
627 // Ignore
628 } catch (IOException e) {
629 //noinspection ResultOfMethodCallIgnored
630 context.getFileStreamPath(PREFERENCES).delete();
631 } finally {
632 if (out != null) {
633 try {
634 out.close();
635 } catch (IOException e) {
636 // Ignore
637 }
638 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800639 }
640 }
641
Anton Hanssona2f665f2013-09-26 12:18:32 +0100642 public Stats getStats() {
643 return mStats;
644 }
645
Bjorn Bringertc459e522013-06-07 19:36:01 +0100646 public LayoutInflater getInflater() {
647 return mInflater;
648 }
649
Adam Cohen716b51e2011-06-30 12:09:54 -0700650 public DragLayer getDragLayer() {
651 return mDragLayer;
652 }
653
Winson Chung36a62fe2012-05-06 18:04:42 -0700654 boolean isDraggingEnabled() {
655 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
656 // that is subsequently removed from the workspace in startBinding().
657 return !mModel.isLoadingWorkspace();
658 }
659
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 static int getScreen() {
661 synchronized (sLock) {
662 return sScreen;
663 }
664 }
665
666 static void setScreen(int screen) {
667 synchronized (sLock) {
668 sScreen = screen;
669 }
670 }
671
Winson Chung557d6ed2011-07-08 15:34:52 -0700672 /**
673 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
674 * a configuration step, this allows the proper animations to run after other transitions.
675 */
676 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700677 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800678 switch (args.requestCode) {
679 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700680 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700681 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800682 break;
683 case REQUEST_PICK_SHORTCUT:
684 processShortcut(args.intent);
685 break;
686 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700687 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700688 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 result = true;
690 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 case REQUEST_CREATE_APPWIDGET:
692 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700693 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 result = true;
695 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800696 }
Michael Jurka27614d22012-04-02 06:40:22 -0700697 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
698 // if you turned the screen off and then back while in All Apps, Launcher would not
699 // return to the workspace. Clearing mAddInfo.container here fixes this issue
700 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700701 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800702 }
703
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 protected void onActivityResult(
706 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700707 // Reset the startActivity waiting flag
708 mWaitingForResult = false;
709
Michael Jurka8b805b12012-04-18 14:23:14 -0700710 if (requestCode == REQUEST_BIND_APPWIDGET) {
711 int appWidgetId = data != null ?
712 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
713 if (resultCode == RESULT_CANCELED) {
714 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
715 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700716 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700717 }
718 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200719 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
720 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
721 mWorkspace.exitOverviewMode(false);
722 }
723 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700724 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200725
Winson Chung557d6ed2011-07-08 15:34:52 -0700726 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800727 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
728 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700729
Adam Cohened66b2b2012-01-23 17:28:51 -0800730 // We have special handling for widgets
731 if (isWidgetDrop) {
732 int appWidgetId = data != null ?
733 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700734 if (appWidgetId < 0) {
735 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
736 "widget configuration activity.");
737 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
738 } else {
739 completeTwoStageWidgetDrop(resultCode, appWidgetId);
740 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800741 return;
742 }
743
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 // The pattern used here is that a user PICKs a specific application,
745 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700746
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800747 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
748 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700749 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 final PendingAddArguments args = new PendingAddArguments();
751 args.requestCode = requestCode;
752 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700753 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700754 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700755 args.cellX = mPendingAddInfo.cellX;
756 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 if (isWorkspaceLocked()) {
758 sPendingAddList.add(args);
759 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700760 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800761 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700764 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800765 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
766 null);
767 }
768
769 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700770 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700771 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800772 Runnable onCompleteRunnable = null;
773 int animationType = 0;
774
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700775 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 if (resultCode == RESULT_OK) {
777 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
778 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700779 mPendingAddWidgetInfo);
780 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 onCompleteRunnable = new Runnable() {
782 @Override
783 public void run() {
784 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700785 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800786 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
787 null);
788 }
789 };
790 } else if (resultCode == RESULT_CANCELED) {
791 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
792 onCompleteRunnable = new Runnable() {
793 @Override
794 public void run() {
795 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
796 null);
797 }
798 };
799 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700800 if (mDragLayer.getAnimatedView() != null) {
801 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
802 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
803 animationType, boundWidget, true);
804 } else {
805 // The animated view may be null in the case of a rotation during widget configuration
806 onCompleteRunnable.run();
807 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800808 }
809
810 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700811 protected void onStop() {
812 super.onStop();
813 FirstFrameAnimatorHelper.setIsVisible(false);
814 }
815
816 @Override
817 protected void onStart() {
818 super.onStart();
819 FirstFrameAnimatorHelper.setIsVisible(true);
820 }
821
822 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200824 long startTime = 0;
825 if (DEBUG_RESUME_TIME) {
826 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400827 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200828 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800829 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700830
Winson Chung4a2afa32012-07-19 14:53:05 -0700831 // Restore the previous launcher state
832 if (mOnResumeState == State.WORKSPACE) {
833 showWorkspace(false);
834 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700835 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700836 }
837 mOnResumeState = State.NONE;
838
Craig Mautner360310b2012-10-26 15:13:08 -0700839 // Background was set to gradient in onPause(), restore to black if in all apps.
840 setWorkspaceBackground(mState == State.WORKSPACE);
841
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800842 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700843 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700844 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400845 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700846 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400847 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700848 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700850 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200851 // We might have postponed some bind calls until onResume (see waitUntilResume) --
852 // execute them here
853 long startTimeCallbacks = 0;
854 if (DEBUG_RESUME_TIME) {
855 startTimeCallbacks = System.currentTimeMillis();
856 }
857
858 if (mAppsCustomizeContent != null) {
859 mAppsCustomizeContent.setBulkBind(true);
860 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700861 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
862 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200863 }
864 if (mAppsCustomizeContent != null) {
865 mAppsCustomizeContent.setBulkBind(false);
866 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700867 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200868 if (DEBUG_RESUME_TIME) {
869 Log.d(TAG, "Time spent processing callbacks in onResume: " +
870 (System.currentTimeMillis() - startTimeCallbacks));
871 }
Michael Jurka447bf842013-05-15 14:52:15 +0200872 }
Michael Jurka54554252013-08-01 12:52:23 +0200873 if (mOnResumeCallbacks.size() > 0) {
874 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
875 mOnResumeCallbacks.get(i).run();
876 }
877 mOnResumeCallbacks.clear();
878 }
Winson Chunge4e50662012-01-23 14:45:13 -0800879
880 // Reset the pressed state of icons that were locked in the press state while activities
881 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800882 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800883 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800884 mWaitingForResume.setStayPressed(false);
885 }
Winson Chunge4e50662012-01-23 14:45:13 -0800886 if (mAppsCustomizeContent != null) {
887 // Resets the previous all apps icon press state
888 mAppsCustomizeContent.resetDrawableState();
889 }
Winson Chung780fe592013-09-26 14:48:44 -0700890 // Reset AllApps to its initial state
891 if (mAppsCustomizeTabHost != null) {
892 mAppsCustomizeTabHost.reset();
893 }
Adam Cohen06dff352012-06-01 17:17:08 -0700894 // It is possible that widgets can receive updates while launcher is not in the foreground.
895 // Consequently, the widgets will be inflated in the orientation of the foreground activity
896 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
897 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700898 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700899
Winson Chung780fe592013-09-26 14:48:44 -0700900 // Process any items that were added while Launcher was away.
901 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
902
Winson Chung5841efa2013-09-30 18:06:44 -0700903 // Update the voice search button proxy
904 updateVoiceButtonProxyVisible(false);
905
Adam Cohenf9426d52012-06-04 17:26:21 -0700906 // Again, as with the above scenario, it's possible that one or more of the global icons
907 // were updated in the wrong orientation.
908 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200909 if (DEBUG_RESUME_TIME) {
910 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
911 }
Adam Cohen06dff352012-06-01 17:17:08 -0700912 }
913
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800914 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700915 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700916 // Ensure that items added to Launcher are queued until Launcher returns
917 InstallShortcutReceiver.enableInstallQueue();
918
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700919 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700920 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800921 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700922 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700923 }
Romain Guycbb89e42009-06-08 15:52:54 -0700924
Adam Cohen66a01fd2013-06-11 12:48:00 -0700925 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700926 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600927 addCustomContentToLeft();
928 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700929 }
930
Adam Cohenbffe7452013-07-22 18:21:45 -0700931 QSBScroller mQsbScroller = new QSBScroller() {
932 int scrollY = 0;
933
934 @Override
935 public void setScrollY(int scroll) {
936 scrollY = scroll;
937
938 if (mWorkspace.isOnOrMovingToCustomContent()) {
939 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100940 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700941 }
942 }
943 };
944
945 public void resetQSBScroll() {
946 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100947 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700948 }
949
950 public interface CustomContentCallbacks {
951 // Custom content is completely shown
952 public void onShow();
953
954 // Custom content is completely hidden
955 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700956
957 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
958 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 }
960
Adam Cohen30bacb22013-08-29 14:25:25 -0700961 protected void startSettings() {
962 }
963
Adam Cohenbffe7452013-07-22 18:21:45 -0700964 public interface QSBScroller {
965 public void setScrollY(int scrollY);
966 }
967
Adam Cohen66a01fd2013-06-11 12:48:00 -0700968 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700969 public QSBScroller addToCustomContentPage(View customContent) {
970 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700971 }
972
Winson Chung98ca0f72013-07-29 12:58:51 -0700973 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700974 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700975 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700976 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700977 }
978
Adam Cohenedb40762013-07-18 16:45:45 -0700979 // The custom content needs to offset its content to account for the QSB
980 public int getTopOffsetForCustomContent() {
981 return mWorkspace.getPaddingTop();
982 }
983
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700984 @Override
985 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400986 // Flag the loader to stop early before switching
987 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700988 if (mAppsCustomizeContent != null) {
989 mAppsCustomizeContent.surrender();
990 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800991 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700992 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700993
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800994 // We can't hide the IME if it was forced open. So don't bother
995 /*
996 @Override
997 public void onWindowFocusChanged(boolean hasFocus) {
998 super.onWindowFocusChanged(hasFocus);
999
1000 if (hasFocus) {
1001 final InputMethodManager inputManager = (InputMethodManager)
1002 getSystemService(Context.INPUT_METHOD_SERVICE);
1003 WindowManager.LayoutParams lp = getWindow().getAttributes();
1004 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1005 android.os.Handler()) {
1006 protected void onReceiveResult(int resultCode, Bundle resultData) {
1007 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1008 }
1009 });
1010 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1011 }
1012 }
1013 */
1014
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015 private boolean acceptFilter() {
1016 final InputMethodManager inputManager = (InputMethodManager)
1017 getSystemService(Context.INPUT_METHOD_SERVICE);
1018 return !inputManager.isFullscreenMode();
1019 }
1020
1021 @Override
1022 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001023 final int uniChar = event.getUnicodeChar();
1024 final boolean handled = super.onKeyDown(keyCode, event);
1025 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1026 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001027 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1028 keyCode, event);
1029 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001030 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001031 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001032 // showSearchDialog()
1033 // If there are multiple keystrokes before the search dialog takes focus,
1034 // onSearchRequested() will be called for every keystroke,
1035 // but it is idempotent, so it's fine.
1036 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 }
1038 }
1039
Joe Onorato8a9625e2010-01-28 15:55:35 -08001040 // Eat the long press event so the keyboard doesn't come up.
1041 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1042 return true;
1043 }
1044
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045 return handled;
1046 }
1047
Karl Rosaen138a0412009-04-23 19:00:21 -07001048 private String getTypedText() {
1049 return mDefaultKeySsb.toString();
1050 }
1051
1052 private void clearTypedText() {
1053 mDefaultKeySsb.clear();
1054 mDefaultKeySsb.clearSpans();
1055 Selection.setSelection(mDefaultKeySsb, 0);
1056 }
1057
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001059 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1060 * State
1061 */
1062 private static State intToState(int stateOrdinal) {
1063 State state = State.WORKSPACE;
1064 final State[] stateValues = State.values();
1065 for (int i = 0; i < stateValues.length; i++) {
1066 if (stateValues[i].ordinal() == stateOrdinal) {
1067 state = stateValues[i];
1068 break;
1069 }
1070 }
1071 return state;
1072 }
1073
1074 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 * Restores the previous state, if it exists.
1076 *
1077 * @param savedState The previous state.
1078 */
1079 private void restoreState(Bundle savedState) {
1080 if (savedState == null) {
1081 return;
1082 }
1083
Michael Jurka883f55b2010-10-21 15:47:14 -07001084 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001085 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001086 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001087 }
1088
Winson Chungf0c6ae02012-03-21 16:10:31 -07001089 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001091 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001092 }
1093
Winson Chung3d503fb2011-07-13 17:25:49 -07001094 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001095 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001096
Winson Chung3d503fb2011-07-13 17:25:49 -07001097 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1098 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001099 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001100 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1101 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001102 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1103 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1104 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001105 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001106 mRestoring = true;
1107 }
1108
1109 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1110 if (renameFolder) {
1111 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001112 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 mRestoring = true;
1114 }
Winson Chunga12a2502010-12-20 14:41:35 -08001115
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 // Restore the AppsCustomize tab
1117 if (mAppsCustomizeTabHost != null) {
1118 String curTab = savedState.getString("apps_customize_currentTab");
1119 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001120 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001121 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001122 mAppsCustomizeContent.loadAssociatedPages(
1123 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001124 }
1125
Winson Chung5afbf7b2011-07-25 11:53:08 -07001126 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1127 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001128 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 }
1130
1131 /**
1132 * Finds all the views we need and configure them properly.
1133 */
1134 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001135 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001136
Craig Mautner360310b2012-10-26 15:13:08 -07001137 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001138 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1139 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001140
John Spurlock77e1f472013-09-11 10:09:51 -04001141 mLauncherView.setSystemUiVisibility(
1142 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001143 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001144
Winson Chung4c98d922011-05-31 16:50:48 -07001145 // Setup the drag layer
1146 mDragLayer.setup(this, dragController);
1147
Winson Chung3d503fb2011-07-13 17:25:49 -07001148 // Setup the hotseat
1149 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1150 if (mHotseat != null) {
1151 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001152 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001153 }
1154
Adam Cohenf358a4b2013-07-23 16:47:31 -07001155 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001156 View widgetButton = findViewById(R.id.widget_button);
1157 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001158 @Override
1159 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001160 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001161 }
1162 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001163 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1164
1165 View wallpaperButton = findViewById(R.id.wallpaper_button);
1166 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001167 @Override
1168 public void onClick(View arg0) {
1169 startWallpaper();
1170 }
1171 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001172 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1173
1174 View settingsButton = findViewById(R.id.settings_button);
1175 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001176 @Override
1177 public void onClick(View arg0) {
1178 startSettings();
1179 }
1180 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001181 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001182 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001183
Winson Chung4c98d922011-05-31 16:50:48 -07001184 // Setup the workspace
1185 mWorkspace.setHapticFeedbackEnabled(false);
1186 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001187 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001188 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001189
Winson Chungf0ea4d32011-06-06 14:27:16 -07001190 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001191 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001192
Winson Chungf0ea4d32011-06-06 14:27:16 -07001193 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001194 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001195 mAppsCustomizeContent = (AppsCustomizePagedView)
1196 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1197 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001198
Winson Chung3d503fb2011-07-13 17:25:49 -07001199 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001200 dragController.setDragScoller(mWorkspace);
1201 dragController.setScrollView(mDragLayer);
1202 dragController.setMoveTarget(mWorkspace);
1203 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001204 if (mSearchDropTargetBar != null) {
1205 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001206 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001207
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001208 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001209 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001210 mWeightWatcher = new WeightWatcher(this);
1211 mWeightWatcher.setAlpha(0.5f);
1212 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001213 new FrameLayout.LayoutParams(
1214 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001215 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001216 Gravity.BOTTOM)
1217 );
Adam Cohen39a06042013-07-19 14:30:12 -07001218
1219 boolean show = shouldShowWeightWatcher();
1220 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 }
1223
1224 /**
1225 * Creates a view representing a shortcut.
1226 *
1227 * @param info The data structure describing the shortcut.
1228 *
1229 * @return A View inflated from R.layout.application.
1230 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001231 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001233 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234 }
1235
1236 /**
1237 * Creates a view representing a shortcut inflated from the specified resource.
1238 *
1239 * @param layoutResId The id of the XML layout used to create the shortcut.
1240 * @param parent The group the shortcut belongs to.
1241 * @param info The data structure describing the shortcut.
1242 *
1243 * @return A View inflated from layoutResId.
1244 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001245 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001246 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1247 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 return favorite;
1250 }
1251
1252 /**
1253 * Add an application shortcut to the workspace.
1254 *
1255 * @param data The intent describing the application.
1256 * @param cellInfo The position on screen where to create the shortcut.
1257 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001258 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001259 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001260 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001261
Adam Cohenfbba09b2011-07-18 21:43:05 -07001262 // First we check if we already know the exact location where we want to add this item.
1263 if (cellX >= 0 && cellY >= 0) {
1264 cellXY[0] = cellX;
1265 cellXY[1] = cellY;
1266 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001267 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001268 return;
1269 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001270
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001271 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001272
Romain Guy73b979d2009-06-09 12:57:21 -07001273 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001274 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001275 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001276 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001278 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001279 } else {
1280 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 }
1282 }
Romain Guycbb89e42009-06-08 15:52:54 -07001283
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 /**
1285 * Add a shortcut to the workspace.
1286 *
1287 * @param data The intent describing the shortcut.
1288 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001290 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001291 int cellY) {
1292 int[] cellXY = mTmpAddItemCellCoordinates;
1293 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001294 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001295
Michael Jurkad3ef3062010-11-23 16:23:58 -08001296 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001297
Adam Cohen558baaf2011-08-15 15:22:57 -07001298 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001299 if (info == null) {
1300 return;
1301 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001302 final View view = createShortcut(info);
1303
Adam Cohenfbba09b2011-07-18 21:43:05 -07001304 // First we check if we already know the exact location where we want to add this item.
1305 if (cellX >= 0 && cellY >= 0) {
1306 cellXY[0] = cellX;
1307 cellXY[1] = cellY;
1308 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001309
1310 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001311 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001312 true, null,null)) {
1313 return;
1314 }
1315 DragObject dragObject = new DragObject();
1316 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001317 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1318 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001319 return;
1320 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001321 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001322 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001323 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001324 foundCellSpan = (result != null);
1325 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001326 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001327 }
1328
1329 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001330 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001331 return;
1332 }
1333
Adam Cohendcd297f2013-06-18 13:13:40 -07001334 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001335
1336 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001337 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001338 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 }
1340 }
1341
Adam Cohen2f093b62012-04-30 18:59:53 -07001342 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1343 int minHeight) {
1344 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001345 // We want to account for the extra amount of padding that we are adding to the widget
1346 // to ensure that it gets the full amount of space that it has requested
1347 int requiredWidth = minWidth + padding.left + padding.right;
1348 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001349 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001350 }
1351
Adam Cohen2f093b62012-04-30 18:59:53 -07001352 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1353 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001354 }
1355
Adam Cohen2f093b62012-04-30 18:59:53 -07001356 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1357 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001358 }
1359
Adam Cohen2f093b62012-04-30 18:59:53 -07001360 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1361 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001362 }
1363
Adam Cohen2f093b62012-04-30 18:59:53 -07001364 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1365 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001366 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001367 }
1368
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001370 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001372 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001373 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001375 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001376 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1377 if (appWidgetInfo == null) {
1378 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1379 }
Romain Guycbb89e42009-06-08 15:52:54 -07001380
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001381 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001382 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001383
Adam Cohen2f093b62012-04-30 18:59:53 -07001384 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1385 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001386
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001387 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001388 // We have saved the position to which the widget was dragged-- this really only matters
1389 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001390 int[] cellXY = mTmpAddItemCellCoordinates;
1391 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001392 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001393 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001394 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1395 cellXY[0] = mPendingAddInfo.cellX;
1396 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001397 spanXY[0] = mPendingAddInfo.spanX;
1398 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001399 foundCellSpan = true;
1400 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001401 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001402 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001403 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1404 spanXY[1], cellXY, finalSpan);
1405 spanXY[0] = finalSpan[0];
1406 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001407 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001408 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001409 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001410 }
1411
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001413 if (appWidgetId != -1) {
1414 // Deleting an app widget ID is a void call but writes to disk before returning
1415 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001416 new Thread("deleteAppWidgetId") {
1417 public void run() {
1418 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1419 }
1420 }.start();
1421 }
Winson Chung93eef082012-03-23 15:59:27 -07001422 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001423 return;
1424 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001425
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001426 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001427 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1428 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001429 launcherInfo.spanX = spanXY[0];
1430 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001431 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1432 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001433
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001435 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436
1437 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001438 if (hostView == null) {
1439 // Perform actual inflation because we're live
1440 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1441 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1442 } else {
1443 // The AppWidgetHostView has already been inflated and instantiated
1444 launcherInfo.hostView = hostView;
1445 }
Romain Guycbb89e42009-06-08 15:52:54 -07001446
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001448 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001449 launcherInfo.notifyWidgetSizeChanged(this);
1450
Adam Cohendcd297f2013-06-18 13:13:40 -07001451 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001452 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001453
1454 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001456 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 }
Romain Guycbb89e42009-06-08 15:52:54 -07001458
Adam Cohended9f8d2010-11-03 13:25:16 -07001459 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1460 @Override
1461 public void onReceive(Context context, Intent intent) {
1462 final String action = intent.getAction();
1463 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1464 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001465 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001466 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001467
Winson Chungc100e8e2011-08-09 16:02:43 -07001468 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001469 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001470 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001471 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001472 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001473 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1474 mUserPresent = true;
1475 updateRunning();
1476 }
1477 }
1478 };
1479
1480 @Override
1481 public void onAttachedToWindow() {
1482 super.onAttachedToWindow();
1483
1484 // Listen for broadcasts related to user-presence
1485 final IntentFilter filter = new IntentFilter();
1486 filter.addAction(Intent.ACTION_SCREEN_OFF);
1487 filter.addAction(Intent.ACTION_USER_PRESENT);
1488 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001489 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001490 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001491 mVisible = true;
1492 }
1493
1494 @Override
1495 public void onDetachedFromWindow() {
1496 super.onDetachedFromWindow();
1497 mVisible = false;
1498
Adam Cohend113e0c2010-11-11 10:48:05 -08001499 if (mAttached) {
1500 unregisterReceiver(mReceiver);
1501 mAttached = false;
1502 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001503 updateRunning();
1504 }
1505
1506 public void onWindowVisibilityChanged(int visibility) {
1507 mVisible = visibility == View.VISIBLE;
1508 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001509 // The following code used to be in onResume, but it turns out onResume is called when
1510 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1511 // is a more appropriate event to handle
1512 if (mVisible) {
1513 mAppsCustomizeTabHost.onWindowVisible();
1514 if (!mWorkspaceLoading) {
1515 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001516 // We want to let Launcher draw itself at least once before we force it to build
1517 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001518 // apps is nice and speedy.
1519 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001520 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001521 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001522 if (mStarted) return;
1523 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001524 // We delay the layer building a bit in order to give
1525 // other message processing a time to run. In particular
1526 // this avoids a delay in hiding the IME if it was
1527 // currently shown, because doing that may involve
1528 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001529 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001530 final ViewTreeObserver.OnDrawListener listener = this;
1531 mWorkspace.post(new Runnable() {
1532 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001533 if (mWorkspace != null &&
1534 mWorkspace.getViewTreeObserver() != null) {
1535 mWorkspace.getViewTreeObserver().
1536 removeOnDrawListener(listener);
1537 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001538 }
1539 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001540 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001541 }
1542 });
1543 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001544 // When Launcher comes back to foreground, a different Activity might be responsible for
1545 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001546 if (!DISABLE_MARKET_BUTTON) {
1547 updateAppMarketIcon();
1548 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001549 clearTypedText();
1550 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001551 }
1552
1553 private void sendAdvanceMessage(long delay) {
1554 mHandler.removeMessages(ADVANCE_MSG);
1555 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1556 mHandler.sendMessageDelayed(msg, delay);
1557 mAutoAdvanceSentTime = System.currentTimeMillis();
1558 }
1559
1560 private void updateRunning() {
1561 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1562 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1563 mAutoAdvanceRunning = autoAdvanceRunning;
1564 if (autoAdvanceRunning) {
1565 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1566 sendAdvanceMessage(delay);
1567 } else {
1568 if (!mWidgetsToAdvance.isEmpty()) {
1569 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1570 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1571 }
1572 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001573 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001574 }
1575 }
1576 }
1577
1578 private final Handler mHandler = new Handler() {
1579 @Override
1580 public void handleMessage(Message msg) {
1581 if (msg.what == ADVANCE_MSG) {
1582 int i = 0;
1583 for (View key: mWidgetsToAdvance.keySet()) {
1584 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1585 final int delay = mAdvanceStagger * i;
1586 if (v instanceof Advanceable) {
1587 postDelayed(new Runnable() {
1588 public void run() {
1589 ((Advanceable) v).advance();
1590 }
1591 }, delay);
1592 }
1593 i++;
1594 }
1595 sendAdvanceMessage(mAdvanceInterval);
1596 }
1597 }
1598 };
1599
1600 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001601 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001602 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1603 if (v instanceof Advanceable) {
1604 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001605 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001606 updateRunning();
1607 }
1608 }
1609
1610 void removeWidgetToAutoAdvance(View hostView) {
1611 if (mWidgetsToAdvance.containsKey(hostView)) {
1612 mWidgetsToAdvance.remove(hostView);
1613 updateRunning();
1614 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001615 }
1616
Joe Onorato9c1289c2009-08-17 11:03:03 -04001617 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001618 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001619 launcherInfo.hostView = null;
1620 }
1621
Winson Chung93eef082012-03-23 15:59:27 -07001622 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1623 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1624 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001625 }
1626
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001627 public LauncherAppWidgetHost getAppWidgetHost() {
1628 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001629 }
Romain Guycbb89e42009-06-08 15:52:54 -07001630
Winson Chunga9abd0e2010-10-27 17:18:37 -07001631 public LauncherModel getModel() {
1632 return mModel;
1633 }
1634
Bjorn Bringertc459e522013-06-07 19:36:01 +01001635 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001636 getWindow().closeAllPanels();
1637
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001638 // Whatever we were doing is hereby canceled.
1639 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001640 }
1641
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001642 @Override
1643 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001644 long startTime = 0;
1645 if (DEBUG_RESUME_TIME) {
1646 startTime = System.currentTimeMillis();
1647 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 super.onNewIntent(intent);
1649
1650 // Close the menu
1651 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001652 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001653 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001654
Jamie Genniscb222e82012-10-23 15:44:26 -07001655 final boolean alreadyOnHome =
1656 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001657 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001658
Jamie Genniscb222e82012-10-23 15:44:26 -07001659 Runnable processIntent = new Runnable() {
1660 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001661 if (mWorkspace == null) {
1662 // Can be cases where mWorkspace is null, this prevents a NPE
1663 return;
1664 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001665 Folder openFolder = mWorkspace.getOpenFolder();
1666 // In all these cases, only animate if we're already on home
1667 mWorkspace.exitWidgetResizeMode();
1668 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1669 openFolder == null) {
1670 mWorkspace.moveToDefaultScreen(true);
1671 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001672
Jamie Genniscb222e82012-10-23 15:44:26 -07001673 closeFolder();
1674 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001675
Jamie Genniscb222e82012-10-23 15:44:26 -07001676 // If we are already on home, then just animate back to the workspace,
1677 // otherwise, just wait until onResume to set the state back to Workspace
1678 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001679 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001680 } else {
1681 mOnResumeState = State.WORKSPACE;
1682 }
1683
1684 final View v = getWindow().peekDecorView();
1685 if (v != null && v.getWindowToken() != null) {
1686 InputMethodManager imm = (InputMethodManager)getSystemService(
1687 INPUT_METHOD_SERVICE);
1688 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1689 }
1690
Winson Chung7819a562013-09-19 15:55:45 -07001691 // Reset the apps customize page
1692 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001693 mAppsCustomizeTabHost.reset();
1694 }
1695 }
1696 };
1697
1698 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1699 // Delay processing of the intent to allow the status bar animation to finish
1700 // first in order to avoid janky animations.
1701 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001702 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001703 // Process the intent immediately.
1704 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001705 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001706
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 }
Michael Jurka447bf842013-05-15 14:52:15 +02001708 if (DEBUG_RESUME_TIME) {
1709 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
1712
Adam Cohen040a5d22013-09-16 17:09:33 -07001713 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1714 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001715 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001716 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001717 }
1718 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001719 protected void showWorkspaceAndExitOverviewMode() {
1720 showWorkspaceAndExitOverviewMode(true);
1721 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001722
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001723 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001724 public void onRestoreInstanceState(Bundle state) {
1725 super.onRestoreInstanceState(state);
1726 for (int page: mSynchronouslyBoundPages) {
1727 mWorkspace.restoreInstanceStateForChild(page);
1728 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 }
1730
1731 @Override
1732 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001733 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001734 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735
Michael Jurka883f55b2010-10-21 15:47:14 -07001736 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001737 // We close any open folder since it will not be re-opened, and we need to make sure
1738 // this state is reflected.
1739 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740
Adam Cohendcd297f2013-06-18 13:13:40 -07001741 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001742 mWaitingForResult) {
1743 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001744 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001745 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1746 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001747 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1748 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1749 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 }
1751
1752 if (mFolderInfo != null && mWaitingForResult) {
1753 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1754 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1755 }
Michael Jurka946ad472010-07-09 18:05:18 -07001756
Winson Chung785d2eb2011-04-14 16:08:02 -07001757 // Save the current AppsCustomize tab
1758 if (mAppsCustomizeTabHost != null) {
1759 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1760 if (currentTabTag != null) {
1761 outState.putString("apps_customize_currentTab", currentTabTag);
1762 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001763 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1764 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001765 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766 }
1767
1768 @Override
1769 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001770 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001771
Winson Chunge7a03942011-08-05 15:05:12 -07001772 // Remove all pending runnables
1773 mHandler.removeMessages(ADVANCE_MSG);
1774 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001775 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001776
Winson Chungcd2b0142011-06-08 16:02:26 -07001777 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001778 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001779 mModel.stopLoader();
1780 app.setLauncher(null);
1781
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001783 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001785 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001787 mAppWidgetHost = null;
1788
1789 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790
1791 TextKeyListener.getInstance().release();
1792
Winson Chung81b52252012-08-27 15:34:29 -07001793 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1794 // to prevent leaking Launcher activities on orientation change.
1795 if (mModel != null) {
1796 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1797 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001798
1799 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001800 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001801
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001802 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001803 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1804 mWorkspace.removeAllViews();
1805 mWorkspace = null;
1806 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001807
Michael Jurka2ecf9952012-06-18 12:52:28 -07001808 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 }
1810
Adam Cohena9cf38f2011-05-02 15:36:58 -07001811 public DragController getDragController() {
1812 return mDragController;
1813 }
1814
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 @Override
1816 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001817 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 super.startActivityForResult(intent, requestCode);
1819 }
1820
Winson Chung70d72102011-08-12 11:24:35 -07001821 /**
1822 * Indicates that we want global search for this activity by setting the globalSearch
1823 * argument for {@link #startSearch} to true.
1824 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001826 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001828
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001829 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001830
Karl Rosaen138a0412009-04-23 19:00:21 -07001831 if (initialQuery == null) {
1832 // Use any text typed in the launcher as the initial query
1833 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001834 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 if (appSearchData == null) {
1836 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001837 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838 }
Winson Chungadf0c182012-08-23 14:59:07 -07001839 Rect sourceBounds = new Rect();
1840 if (mSearchDropTargetBar != null) {
1841 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1842 }
Romain Guycbb89e42009-06-08 15:52:54 -07001843
Bjorn Bringertc459e522013-06-07 19:36:01 +01001844 startSearch(initialQuery, selectInitialQuery,
1845 appSearchData, sourceBounds);
1846 }
1847
1848 public void startSearch(String initialQuery,
1849 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001850 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001851 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001852 }
1853
1854 /**
1855 * Starts the global search activity. This code is a copied from SearchManager
1856 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001857 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001858 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001859 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001860 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1861 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1862 if (globalSearchActivity == null) {
1863 Log.w(TAG, "No global search activity found.");
1864 return;
1865 }
1866 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1867 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1868 intent.setComponent(globalSearchActivity);
1869 // Make sure that we have a Bundle to put source in
1870 if (appSearchData == null) {
1871 appSearchData = new Bundle();
1872 } else {
1873 appSearchData = new Bundle(appSearchData);
1874 }
1875 // Set source to package name of app that starts global search, if not set already.
1876 if (!appSearchData.containsKey("source")) {
1877 appSearchData.putString("source", getPackageName());
1878 }
1879 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1880 if (!TextUtils.isEmpty(initialQuery)) {
1881 intent.putExtra(SearchManager.QUERY, initialQuery);
1882 }
1883 if (selectInitialQuery) {
1884 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1885 }
1886 intent.setSourceBounds(sourceBounds);
1887 try {
1888 startActivity(intent);
1889 } catch (ActivityNotFoundException ex) {
1890 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1891 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 }
1893
Winson Chung70d72102011-08-12 11:24:35 -07001894 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001895 public boolean onPrepareOptionsMenu(Menu menu) {
1896 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001897 if (!mWorkspace.isInOverviewMode()) {
1898 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001899 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001900 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001903 @Override
1904 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001905 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001906 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001907 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001908 }
1909
Joe Onorato9c1289c2009-08-17 11:03:03 -04001910 public boolean isWorkspaceLocked() {
1911 return mWorkspaceLoading || mWaitingForResult;
1912 }
1913
Michael Jurka0280c3b2010-09-17 15:00:07 -07001914 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001915 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001916 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001917 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1918 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001919 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001920 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001921 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001922
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001923 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1924 AppWidgetProviderInfo appWidgetInfo) {
1925 if (appWidgetInfo.configure != null) {
1926 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001927
Bjorn Bringert7984c942009-12-09 15:38:25 +00001928 // Launch over to configure widget, if needed
1929 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001930 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001931 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001932 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001934 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001935 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001936 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001937 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001938 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 }
1940 }
Romain Guycbb89e42009-06-08 15:52:54 -07001941
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001942 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001943 // Close any folders that may be open.
1944 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001945 mWorkspace.moveToCustomContentScreen(animate);
1946 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001947 /**
1948 * Process a shortcut drop.
1949 *
1950 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 * @param cell The cell it should be added to, optional
1953 * @param position The location on the screen where it was dropped, optional
1954 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001957 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001958 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001959 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001960 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001961
1962 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.cellX = cell[0];
1964 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001965 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001966
1967 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1968 createShortcutIntent.setComponent(componentName);
1969 processShortcut(createShortcutIntent);
1970 }
1971
Adam Cohenfbba09b2011-07-18 21:43:05 -07001972 /**
1973 * Process a widget drop.
1974 *
1975 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001976 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001977 * @param cell The cell it should be added to, optional
1978 * @param position The location on the screen where it was dropped, optional
1979 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001980 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001981 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001982 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001983 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001984 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001985 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001986 mPendingAddInfo.minSpanX = info.minSpanX;
1987 mPendingAddInfo.minSpanY = info.minSpanY;
1988
Adam Cohenfbba09b2011-07-18 21:43:05 -07001989 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001990 mPendingAddInfo.cellX = cell[0];
1991 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001992 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001993 if (span != null) {
1994 mPendingAddInfo.spanX = span[0];
1995 mPendingAddInfo.spanY = span[1];
1996 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001997
Adam Cohened66b2b2012-01-23 17:28:51 -08001998 AppWidgetHostView hostView = info.boundWidget;
1999 int appWidgetId;
2000 if (hostView != null) {
2001 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002002 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002003 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002004 // In this case, we either need to start an activity to get permission to bind
2005 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002006 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002007 Bundle options = info.bindOptions;
2008
2009 boolean success = false;
2010 if (options != null) {
2011 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2012 info.componentName, options);
2013 } else {
2014 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2015 info.componentName);
2016 }
2017 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002018 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002019 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002020 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002021 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2022 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2023 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002024 // TODO: we need to make sure that this accounts for the options bundle.
2025 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002026 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2027 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002028 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002029 }
2030
Joe Onoratodeb98af2010-02-19 14:59:39 -08002031 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002032 // Handle case where user selected "Applications"
2033 String applicationName = getResources().getString(R.string.group_applications);
2034 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002035
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002036 if (applicationName != null && applicationName.equals(shortcutName)) {
2037 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2038 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002039
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002040 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2041 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002042 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002043 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002044 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002045 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002046 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 }
2048
Winson Chung24ab2f12010-09-16 14:10:47 -07002049 void processWallpaper(Intent intent) {
2050 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2051 }
2052
Adam Cohendcd297f2013-06-18 13:13:40 -07002053 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002054 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002055 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 folderInfo.title = getText(R.string.folder_name);
2057
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002059 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002060 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002061 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062
2063 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002064 FolderIcon newFolder =
2065 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002066 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002067 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002068 // Force measure the new folder icon
2069 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2070 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002071 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002072 }
Romain Guycbb89e42009-06-08 15:52:54 -07002073
Joe Onorato9c1289c2009-08-17 11:03:03 -04002074 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002075 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002076 }
2077
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002078 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002079 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002080 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002081 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002082 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 }
2084
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002085 protected ComponentName getWallpaperPickerComponent() {
2086 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2087 }
2088
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002089 /**
2090 * Registers various content observers. The current implementation registers
2091 * only a favorites observer to keep track of the favorites applications.
2092 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002093 private void registerContentObservers() {
2094 ContentResolver resolver = getContentResolver();
2095 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2096 true, mWidgetObserver);
2097 }
2098
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 @Override
2100 public boolean dispatchKeyEvent(KeyEvent event) {
2101 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2102 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002103 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002104 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002105 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002106 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002107 dumpState();
2108 return true;
2109 }
2110 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002111 }
2112 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2113 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002114 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002115 return true;
2116 }
2117 }
2118
2119 return super.dispatchKeyEvent(event);
2120 }
2121
Joe Onorato88ec0992009-11-19 13:16:06 -08002122 @Override
2123 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002124 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002125 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002126 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002127 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002128 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002129 Folder openFolder = mWorkspace.getOpenFolder();
2130 if (openFolder.isEditingName()) {
2131 openFolder.dismissEditingName();
2132 } else {
2133 closeFolder();
2134 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002135 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002136 mWorkspace.exitWidgetResizeMode();
2137
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002138 // Back button is a no-op here, but give at least some feedback for the button press
2139 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002140 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002141 }
2142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002144 * Re-listen when widgets are reset.
2145 */
2146 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002147 if (mAppWidgetHost != null) {
2148 mAppWidgetHost.startListening();
2149 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002150 }
2151
2152 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 * Launches the intent referred by the clicked shortcut.
2154 *
2155 * @param v The view representing the clicked shortcut.
2156 */
2157 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002158 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2159 // view has detached (it's possible for this to happen if the view is removed mid touch).
2160 if (v.getWindowToken() == null) {
2161 return;
2162 }
2163
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002164 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002165 return;
2166 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002167
Adam Cohen1697b792013-09-17 19:08:21 -07002168 if (v instanceof Workspace) {
2169 if (mWorkspace.isInOverviewMode()) {
2170 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002171 }
2172 return;
2173 }
2174
2175 if (v instanceof CellLayout) {
2176 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002177 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002178 }
2179 }
2180
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002182 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002184 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2185 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002186
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002187 // Check for special shortcuts
2188 if (intent.getComponent() != null) {
2189 final String shortcutClass = intent.getComponent().getClassName();
2190
2191 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002192 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002193 return;
2194 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2195 MemoryDumpActivity.startDump(this);
2196 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002197 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2198 toggleShowWeightWatcher();
2199 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002200 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002201 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002202
2203 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002204 int[] pos = new int[2];
2205 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002206 intent.setSourceBounds(new Rect(pos[0], pos[1],
2207 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002208
2209 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002210
Daniel Sandlerff02d492013-08-05 02:12:05 -04002211 mStats.recordLaunch(intent, shortcut);
2212
Michael Jurkaddd62e92011-02-16 17:49:14 -08002213 if (success && v instanceof BubbleTextView) {
2214 mWaitingForResume = (BubbleTextView) v;
2215 mWaitingForResume.setStayPressed(true);
2216 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002217 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002218 if (v instanceof FolderIcon) {
2219 FolderIcon fi = (FolderIcon) v;
2220 handleFolderClick(fi);
2221 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002222 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002223 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002224 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002225 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002226 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002227 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002228 }
2229 }
2230
Michael Jurka0e260592010-06-30 17:07:39 -07002231 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002232 return false;
2233 }
2234
Michael Jurkaaf442092010-06-10 17:01:57 -07002235 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002236 * Event handler for the search button
2237 *
2238 * @param v The view that was clicked.
2239 */
2240 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002241 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2242
Amith Yamasania135ba82011-08-09 17:42:01 -07002243 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002244 }
2245
2246 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002247 * Event handler for the voice button
2248 *
2249 * @param v The view that was clicked.
2250 */
2251 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002252 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002253
Bjorn Bringertc459e522013-06-07 19:36:01 +01002254 startVoice();
2255 }
2256
2257 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002258 try {
2259 final SearchManager searchManager =
2260 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2261 ComponentName activityName = searchManager.getGlobalSearchActivity();
2262 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002263 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002264 if (activityName != null) {
2265 intent.setPackage(activityName.getPackageName());
2266 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002267 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002268 } catch (ActivityNotFoundException e) {
2269 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002270 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002271 startActivitySafely(null, intent, "onClickVoiceButton");
2272 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002273 }
2274
2275 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002276 * Event handler for the "grid" button that appears on the home screen, which
2277 * enters all apps mode.
2278 *
2279 * @param v The view that was clicked.
2280 */
2281 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002282 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002283 }
2284
2285 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002286 // Provide the same haptic feedback that the system offers for virtual keys.
2287 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002288 }
2289
Adam Cohen61f560d2013-09-30 15:58:20 -07002290 public void performHapticFeedbackOnTouchDown(View v) {
2291 // Provide the same haptic feedback that the system offers for virtual keys.
2292 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2293 }
2294
2295 public View.OnTouchListener getHapticFeedbackTouchListener() {
2296 if (mHapticFeedbackTouchListener == null) {
2297 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2298 @Override
2299 public boolean onTouch(View v, MotionEvent event) {
2300 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2301 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2302 }
2303 return false;
2304 }
2305 };
2306 }
2307 return mHapticFeedbackTouchListener;
2308 }
2309
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002310 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002311 if (!DISABLE_MARKET_BUTTON) {
2312 if (mAppMarketIntent != null) {
2313 startActivitySafely(v, mAppMarketIntent, "app market");
2314 } else {
2315 Log.e(TAG, "Invalid app market intent.");
2316 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002317 }
2318 }
2319
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002320 /**
2321 * Called when the user stops interacting with the launcher.
2322 * This implies that the user is now on the homescreen and is not doing housekeeping.
2323 */
2324 protected void onInteractionEnd() {}
2325
2326 /**
2327 * Called when the user starts interacting with the launcher.
2328 * The possible interactions are:
2329 * - open all apps
2330 * - reorder an app shortcut, or a widget
2331 * - open the overview mode.
2332 * This is a good time to stop doing things that only make sense
2333 * when the user is on the homescreen and not doing housekeeping.
2334 */
2335 protected void onInteractionBegin() {}
2336
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002337 void startApplicationDetailsActivity(ComponentName componentName) {
2338 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002339 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2340 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002341 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002342 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002343 }
2344
Michael Jurka1e2f4652013-07-08 18:03:46 -07002345 // returns true if the activity was started
2346 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002347 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002348 // System applications cannot be installed. For now, show a toast explaining that.
2349 // We may give them the option of disabling apps this way.
2350 int messageId = R.string.uninstall_system_app_text;
2351 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002352 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002353 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002354 String packageName = componentName.getPackageName();
2355 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002356 Intent intent = new Intent(
2357 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002358 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2359 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002360 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002361 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002362 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002363 }
2364
Michael Jurka86a720e2012-05-09 11:23:23 -07002365 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002367
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002368 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002369 // Only launch using the new animation if the shortcut has not opted out (this is a
2370 // private contract between launcher and may be ignored in the future).
2371 boolean useLaunchAnimation = (v != null) &&
2372 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2373 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002374 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2375 v.getMeasuredWidth(), v.getMeasuredHeight());
2376
2377 startActivity(intent, opts.toBundle());
2378 } else {
2379 startActivity(intent);
2380 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002381 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 } catch (SecurityException e) {
2383 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002384 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002386 "or use the exported attribute for this activity. "
2387 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002388 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002389 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002391
Michael Jurka86a720e2012-05-09 11:23:23 -07002392 boolean startActivitySafely(View v, Intent intent, Object tag) {
2393 boolean success = false;
2394 try {
2395 success = startActivity(v, intent, tag);
2396 } catch (ActivityNotFoundException e) {
2397 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2398 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2399 }
2400 return success;
2401 }
2402
Adam Cohena9cf38f2011-05-02 15:36:58 -07002403 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002404 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002405 Folder openFolder = mWorkspace.getFolderForTag(info);
2406
2407 // If the folder info reports that the associated folder is open, then verify that
2408 // it is actually opened. There have been a few instances where this gets out of sync.
2409 if (info.opened && openFolder == null) {
2410 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002411 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002412 info.opened = false;
2413 }
2414
Adam Cohenfb91f302012-06-11 15:45:18 -07002415 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002416 // Close any open folder
2417 closeFolder();
2418 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002419 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002420 } else {
2421 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002422 int folderScreen;
2423 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002424 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 // .. and close it
2426 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002427 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002428 // Close any folder open on the current screen
2429 closeFolder();
2430 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002431 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 }
2433 }
2434 }
2435 }
2436
Adam Cohen268c4752012-06-06 17:47:33 -07002437 /**
2438 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2439 * in the DragLayer in the exact absolute location of the original FolderIcon.
2440 */
2441 private void copyFolderIconToImage(FolderIcon fi) {
2442 final int width = fi.getMeasuredWidth();
2443 final int height = fi.getMeasuredHeight();
2444
2445 // Lazy load ImageView, Bitmap and Canvas
2446 if (mFolderIconImageView == null) {
2447 mFolderIconImageView = new ImageView(this);
2448 }
2449 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2450 mFolderIconBitmap.getHeight() != height) {
2451 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2452 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2453 }
2454
2455 DragLayer.LayoutParams lp;
2456 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2457 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2458 } else {
2459 lp = new DragLayer.LayoutParams(width, height);
2460 }
2461
Adam Cohen307fe232012-08-16 17:55:58 -07002462 // The layout from which the folder is being opened may be scaled, adjust the starting
2463 // view size by this scale factor.
2464 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002465 lp.customPosition = true;
2466 lp.x = mRectForFolderAnimation.left;
2467 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002468 lp.width = (int) (scale * width);
2469 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002470
2471 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2472 fi.draw(mFolderIconCanvas);
2473 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002474 if (fi.getFolder() != null) {
2475 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2476 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002477 }
Adam Cohen268c4752012-06-06 17:47:33 -07002478 // Just in case this image view is still in the drag layer from a previous animation,
2479 // we remove it and re-add it.
2480 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2481 mDragLayer.removeView(mFolderIconImageView);
2482 }
2483 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002484 if (fi.getFolder() != null) {
2485 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002486 }
Adam Cohen268c4752012-06-06 17:47:33 -07002487 }
2488
Adam Cohen2801caf2011-05-13 20:57:39 -07002489 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002490 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002491 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2492 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2493 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2494
Adam Cohenc51934b2011-07-26 21:07:43 -07002495 FolderInfo info = (FolderInfo) fi.getTag();
2496 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2497 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002498 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2499 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002500 }
2501
Adam Cohen268c4752012-06-06 17:47:33 -07002502 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2503 copyFolderIconToImage(fi);
2504 fi.setVisibility(View.INVISIBLE);
2505
Michael Jurka2ecf9952012-06-18 12:52:28 -07002506 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002507 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002508 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2509 oa.start();
2510 }
2511
Adam Cohen268c4752012-06-06 17:47:33 -07002512 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002513 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002514 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2515 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2516 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2517
Adam Cohen268c4752012-06-06 17:47:33 -07002518 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002519
Adam Cohen268c4752012-06-06 17:47:33 -07002520 // We remove and re-draw the FolderIcon in-case it has changed
2521 mDragLayer.removeView(mFolderIconImageView);
2522 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002523 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002524 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002525 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002526 oa.addListener(new AnimatorListenerAdapter() {
2527 @Override
2528 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002529 if (cl != null) {
2530 cl.clearFolderLeaveBehind();
2531 // Remove the ImageView copy of the FolderIcon and make the original visible.
2532 mDragLayer.removeView(mFolderIconImageView);
2533 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002534 }
2535 }
2536 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002537 oa.start();
2538 }
2539
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002540 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002541 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002542 * is animated relative to the specified View. If the View is null, no animation
2543 * is played.
2544 *
2545 * @param folderInfo The FolderInfo describing the folder to open.
2546 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002547 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002548 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002549 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002550
Adam Cohena9cf38f2011-05-02 15:36:58 -07002551 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552
Adam Cohen4554ee12011-08-03 16:13:21 -07002553 // Just verify that the folder hasn't already been added to the DragLayer.
2554 // There was a one-off crash where the folder had a parent already.
2555 if (folder.getParent() == null) {
2556 mDragLayer.addView(folder);
2557 mDragController.addDropTarget((DropTarget) folder);
2558 } else {
2559 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2560 folder.getParent() + ").");
2561 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002562 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002563 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002564
2565 // Notify the accessibility manager that this folder "window" has appeared and occluded
2566 // the workspace items
2567 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2568 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002569 }
2570
2571 public void closeFolder() {
2572 Folder folder = mWorkspace.getOpenFolder();
2573 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002574 if (folder.isEditingName()) {
2575 folder.dismissEditingName();
2576 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002577 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002578
2579 // Dismiss the folder cling
2580 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002581 }
2582 }
2583
2584 void closeFolder(Folder folder) {
2585 folder.getInfo().opened = false;
2586
2587 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2588 if (parent != null) {
2589 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2590 shrinkAndFadeInFolderIcon(fi);
2591 }
2592 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002593
2594 // Notify the accessibility manager that this folder "window" has disappeard and no
2595 // longer occludeds the workspace items
2596 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002597 }
2598
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002599 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002600 if (!isDraggingEnabled()) return false;
2601 if (isWorkspaceLocked()) return false;
2602 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002603
Adam Cohen1697b792013-09-17 19:08:21 -07002604 if (v instanceof Workspace) {
2605 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002606 if (mWorkspace.enterOverviewMode()) {
2607 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2608 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2609 return true;
2610 } else {
2611 return false;
2612 }
Adam Cohen1697b792013-09-17 19:08:21 -07002613 }
Adam Cohen1697b792013-09-17 19:08:21 -07002614 }
2615
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002616 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002617 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002618 }
2619
Michael Jurka0280c3b2010-09-17 15:00:07 -07002620 resetAddInfo();
2621 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002622 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002623 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002624 return true;
2625 }
2626
Winson Chung3d503fb2011-07-13 17:25:49 -07002627 // The hotseat touch handling does not go through Workspace, and we always allow long press
2628 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002629 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002630 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2631 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002632 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002633 // User long pressed on empty space
2634 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2635 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2636 // Disabling reordering until we sort out some issues.
2637 if (mWorkspace.isInOverviewMode()) {
2638 mWorkspace.startReordering(v);
2639 } else {
2640 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002641 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002642 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002643 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002644 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002645 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002646 }
2647 }
2648 }
2649 return true;
2650 }
2651
Winson Chung3d503fb2011-07-13 17:25:49 -07002652 boolean isHotseatLayout(View layout) {
2653 return mHotseat != null && layout != null &&
2654 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2655 }
2656 Hotseat getHotseat() {
2657 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002658 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002659 View getOverviewPanel() {
2660 return mOverviewPanel;
2661 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002662 SearchDropTargetBar getSearchBar() {
2663 return mSearchDropTargetBar;
2664 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002665
Winson Chung3d503fb2011-07-13 17:25:49 -07002666 /**
2667 * Returns the CellLayout of the specified container at the specified screen.
2668 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002669 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002670 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2671 if (mHotseat != null) {
2672 return mHotseat.getLayout();
2673 } else {
2674 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002675 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002676 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002677 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002678 }
2679 }
2680
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002681 Workspace getWorkspace() {
2682 return mWorkspace;
2683 }
2684
Daniel Sandler843e8602010-06-07 14:59:01 -04002685 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002686 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002687 }
2688
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002689 /**
2690 * Helper method for the cameraZoomIn/cameraZoomOut animations
2691 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002692 * @param scaleFactor The scale factor used for the zoom
2693 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002694 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002695 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002696 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002697 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002698
Craig Mautner360310b2012-10-26 15:13:08 -07002699 private void setWorkspaceBackground(boolean workspace) {
2700 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002701 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002702 }
2703
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002704 void updateWallpaperVisibility(boolean visible) {
2705 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2706 int curflags = getWindow().getAttributes().flags
2707 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2708 if (wpflags != curflags) {
2709 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2710 }
Craig Mautner360310b2012-10-26 15:13:08 -07002711 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002712 }
2713
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002714 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2715 if (v instanceof LauncherTransitionable) {
2716 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2717 }
2718 }
2719
Michael Jurkabed61d22012-02-14 22:51:29 -08002720 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2721 if (v instanceof LauncherTransitionable) {
2722 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2723 }
Winson Chung70442722012-02-10 15:43:22 -08002724
2725 // Update the workspace transition step as well
2726 dispatchOnLauncherTransitionStep(v, 0f);
2727 }
2728
2729 private void dispatchOnLauncherTransitionStep(View v, float t) {
2730 if (v instanceof LauncherTransitionable) {
2731 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2732 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002733 }
2734
2735 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2736 if (v instanceof LauncherTransitionable) {
2737 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2738 }
Winson Chung70442722012-02-10 15:43:22 -08002739
2740 // Update the workspace transition step as well
2741 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002742 }
2743
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002744 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002745 * Things to test when changing the following seven functions.
2746 * - Home from workspace
2747 * - from center screen
2748 * - from other screens
2749 * - Home from all apps
2750 * - from center screen
2751 * - from other screens
2752 * - Back from all apps
2753 * - from center screen
2754 * - from other screens
2755 * - Launch app from workspace and quit
2756 * - with back
2757 * - with home
2758 * - Launch app from all apps and quit
2759 * - with back
2760 * - with home
2761 * - Go to a screen that's not the default, then all
2762 * apps, and launch and app, and go back
2763 * - with back
2764 * -with home
2765 * - On workspace, long press power and go back
2766 * - with back
2767 * - with home
2768 * - On all apps, long press power and go back
2769 * - with back
2770 * - with home
2771 * - On workspace, power off
2772 * - On all apps, power off
2773 * - Launch an app and turn off the screen while in that app
2774 * - Go back with home key
2775 * - Go back with back key TODO: make this not go to workspace
2776 * - From all apps
2777 * - From workspace
2778 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2779 * - From all apps
2780 * - From the center workspace
2781 * - From another workspace
2782 */
2783
2784 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002785 * Zoom the camera out from the workspace to reveal 'toView'.
2786 * Assumes that the view to show is anchored at either the very top or very bottom
2787 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002788 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002789 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002790 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2791 showAppsCustomizeHelper(animated, springLoaded, contentType);
2792 }
2793 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2794 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002795 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002796 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002797 mStateAnimation.cancel();
2798 mStateAnimation = null;
2799 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002800 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002801
Winson Chungf0ea4d32011-06-06 14:27:16 -07002802 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2803 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2804 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002805 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002806 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002807 final int startDelay =
2808 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002809
Michael Jurkab3e22d92011-10-31 15:58:33 -07002810 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002811
Michael Jurkad74c9842011-07-10 12:44:21 -07002812 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002813 Animator workspaceAnim =
2814 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002815 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2816 // Set the content type for the all apps space
2817 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2818 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002819
2820 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002821 toView.setScaleX(scale);
2822 toView.setScaleY(scale);
2823 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2824 scaleAnim.
2825 scaleX(1f).scaleY(1f).
2826 setDuration(duration).
2827 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002828
Winson Chungf0ea4d32011-06-06 14:27:16 -07002829 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002830 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002831 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002832 .ofFloat(toView, "alpha", 0f, 1f)
2833 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002834 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002835 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2836 @Override
2837 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002838 if (animation == null) {
2839 throw new RuntimeException("animation is null");
2840 }
Winson Chung70442722012-02-10 15:43:22 -08002841 float t = (Float) animation.getAnimatedValue();
2842 dispatchOnLauncherTransitionStep(fromView, t);
2843 dispatchOnLauncherTransitionStep(toView, t);
2844 }
2845 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002846
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002847 // toView should appear right at the end of the workspace shrink
2848 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002849 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002850 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002851 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002852
2853 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002854 boolean animationCancelled = false;
2855
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002856 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002857 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002858 // Prepare the position
2859 toView.setTranslationX(0.0f);
2860 toView.setTranslationY(0.0f);
2861 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002862 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002863 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002864 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002865 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002866 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2867 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002868
Winson Chungc7d2b602012-05-16 17:02:20 -07002869 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002870 if (mSearchDropTargetBar != null) {
2871 mSearchDropTargetBar.hideSearchBar(false);
2872 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002873 }
2874
Adam Cohencff6af82011-09-13 14:51:53 -07002875 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002876 public void onAnimationCancel(Animator animation) {
2877 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002878 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002879 });
2880
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002881 if (workspaceAnim != null) {
2882 mStateAnimation.play(workspaceAnim);
2883 }
Michael Jurka1899a362011-11-03 13:50:45 -07002884
2885 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002886
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002887 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2888 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002889
2890 // If any of the objects being animated haven't been measured/laid out
2891 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002892 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002893 (mWorkspace.getMeasuredWidth() == 0) ||
2894 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002895 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002896 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002897
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002898 final AnimatorSet stateAnimation = mStateAnimation;
2899 final Runnable startAnimRunnable = new Runnable() {
2900 public void run() {
2901 // Check that mStateAnimation hasn't changed while
2902 // we waited for a layout/draw pass
2903 if (mStateAnimation != stateAnimation)
2904 return;
2905 setPivotsForZoom(toView, scale);
2906 dispatchOnLauncherTransitionStart(fromView, animated, false);
2907 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002908 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002909 }
2910 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002911 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002912 final ViewTreeObserver observer = toView.getViewTreeObserver();
2913 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2914 public void onGlobalLayout() {
2915 startAnimRunnable.run();
2916 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2917 }
2918 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002919 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002920 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002921 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002922 } else {
2923 toView.setTranslationX(0.0f);
2924 toView.setTranslationY(0.0f);
2925 toView.setScaleX(1.0f);
2926 toView.setScaleY(1.0f);
2927 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002928 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002929
Daniel Sandlere4f98912013-06-25 15:13:26 -04002930 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002931 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002932 if (mSearchDropTargetBar != null) {
2933 mSearchDropTargetBar.hideSearchBar(false);
2934 }
Michael Jurkaabded662011-03-04 12:06:57 -08002935 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002936 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002937 dispatchOnLauncherTransitionStart(fromView, animated, false);
2938 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002939 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002940 dispatchOnLauncherTransitionStart(toView, animated, false);
2941 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002942 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002943 }
2944
2945 /**
2946 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002947 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002948 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002949 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002950 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2951 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002952
Michael Jurkab3e22d92011-10-31 15:58:33 -07002953 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002954 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002955 mStateAnimation.cancel();
2956 mStateAnimation = null;
2957 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002958 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002959
Winson Chungf0ea4d32011-06-06 14:27:16 -07002960 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002961 final int fadeOutDuration =
2962 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002963 final float scaleFactor = (float)
2964 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2965 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002966 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002967 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002968 if (toState == State.WORKSPACE) {
2969 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2970 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002971 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002972 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2973 workspaceAnim = mWorkspace.getChangeStateAnimation(
2974 Workspace.State.SPRING_LOADED, animated);
2975 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002976
Michael Jurkab3e22d92011-10-31 15:58:33 -07002977 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002978 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002979 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002980 final LauncherViewPropertyAnimator scaleAnim =
2981 new LauncherViewPropertyAnimator(fromView);
2982 scaleAnim.
2983 scaleX(scaleFactor).scaleY(scaleFactor).
2984 setDuration(duration).
2985 setInterpolator(new Workspace.ZoomInInterpolator());
2986
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002987 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002988 .ofFloat(fromView, "alpha", 1f, 0f)
2989 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002990 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002991 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2992 @Override
2993 public void onAnimationUpdate(ValueAnimator animation) {
2994 float t = 1f - (Float) animation.getAnimatedValue();
2995 dispatchOnLauncherTransitionStep(fromView, t);
2996 dispatchOnLauncherTransitionStep(toView, t);
2997 }
2998 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002999
Michael Jurka2ecf9952012-06-18 12:52:28 -07003000 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003001
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003002 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3003 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003004 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003005
3006 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003007 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003008 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003009 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003010 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3011 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003012 if (onCompleteRunnable != null) {
3013 onCompleteRunnable.run();
3014 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003015 mAppsCustomizeContent.updateCurrentPageScroll();
3016 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003017 }
3018 });
3019
Winson Chungf0ea4d32011-06-06 14:27:16 -07003020 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003021 if (workspaceAnim != null) {
3022 mStateAnimation.play(workspaceAnim);
3023 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003024 dispatchOnLauncherTransitionStart(fromView, animated, true);
3025 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003026 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003027 } else {
3028 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003029 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003030 dispatchOnLauncherTransitionStart(fromView, animated, true);
3031 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003032 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003033 dispatchOnLauncherTransitionStart(toView, animated, true);
3034 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003035 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003036 }
3037
Michael Jurkae326f182011-11-21 14:05:46 -08003038 @Override
3039 public void onTrimMemory(int level) {
3040 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003041 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003042 mAppsCustomizeTabHost.onTrimMemory();
3043 }
3044 }
3045
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003046 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003047 showWorkspace(animated, null);
3048 }
3049
3050 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003052 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003053 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003054 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003055
Winson Chungc7d2b602012-05-16 17:02:20 -07003056 // Show the search bar (only animate if we were showing the drop target bar in spring
3057 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003058 if (mSearchDropTargetBar != null) {
3059 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3060 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003061
Michael Jurkab3e22d92011-10-31 15:58:33 -07003062 // Set focus to the AppsCustomize button
3063 if (mAllAppsButton != null) {
3064 mAllAppsButton.requestFocus();
3065 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003066 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003067
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003068 // Change the state *after* we've called all the transition code
3069 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003070
Winson Chung5fb63472011-02-02 17:03:37 -08003071 // Resume the auto-advance of widgets
3072 mUserPresent = true;
3073 updateRunning();
3074
alanv1d4fde62012-10-17 13:15:47 -07003075 // Send an accessibility event to announce the context change
3076 getWindow().getDecorView()
3077 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003078
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003079 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003080 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003081 }
3082
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003083 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003084 }
3085
Winson Chungc58497e2013-09-03 17:48:37 -07003086 void showAllApps(boolean animated,
3087 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003088 if (mState != State.WORKSPACE) return;
3089
Winson Chungc58497e2013-09-03 17:48:37 -07003090 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003091 mAppsCustomizeTabHost.requestFocus();
3092
Michael Jurkab3e22d92011-10-31 15:58:33 -07003093 // Change the state *after* we've called all the transition code
3094 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003095 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003096
3097 // Pause the auto-advance of widgets until we are out of AllApps
3098 mUserPresent = false;
3099 updateRunning();
3100 closeFolder();
3101
3102 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003103 getWindow().getDecorView()
3104 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003105 }
3106
Adam Cohen7777d962011-08-18 18:58:38 -07003107 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003108 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003109 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003110 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003111 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003112 }
Adam Cohen7777d962011-08-18 18:58:38 -07003113
Adam Cohened66b2b2012-01-23 17:28:51 -08003114 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3115 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003116 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3117
Winson Chunge7a03942011-08-05 15:05:12 -07003118 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003119 @Override
3120 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003121 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003122 // Before we show workspace, hide all apps again because
3123 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3124 // clean up our state transition functions
3125 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003126 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003127 } else {
3128 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003129 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003130 }
3131 }, (extendedDelay ?
3132 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3133 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3134 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003135
Michael Jurkad3ef3062010-11-23 16:23:58 -08003136 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003137 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003138 final boolean animated = true;
3139 final boolean springLoaded = true;
3140 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003141 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003142 }
3143 // Otherwise, we are not in spring loaded mode, so don't do anything.
3144 }
3145
Michael Jurkab3e22d92011-10-31 15:58:33 -07003146 void lockAllApps() {
3147 // TODO
3148 }
3149
3150 void unlockAllApps() {
3151 // TODO
3152 }
3153
Winson Chungf0ea4d32011-06-06 14:27:16 -07003154 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003155 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003156 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003157 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003158 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003159 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003160 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003161 int duration = 0;
3162 if (mSearchDropTargetBar != null) {
3163 duration = mSearchDropTargetBar.getTransitionInDuration();
3164 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003165 mHotseat.animate().alpha(1f).setDuration(duration);
3166 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003167 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003168 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003169 }
3170 }
3171 }
3172
3173 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003174 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003175 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003176 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003177 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003178 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003179 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003180 int duration = 0;
3181 if (mSearchDropTargetBar != null) {
3182 duration = mSearchDropTargetBar.getTransitionOutDuration();
3183 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003184 mHotseat.animate().alpha(0f).setDuration(duration);
3185 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003186 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003187 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003188 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003189 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003190 }
3191
Patrick Dubroy5f445422011-02-18 14:35:21 -08003192 /**
3193 * Add an item from all apps or customize onto the given workspace screen.
3194 * If layout is null, add to the current screen.
3195 */
3196 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003197 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003198 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003199 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003200 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003201
Winson Chungdff8ebb2011-09-08 17:25:31 -07003202 /** Maps the current orientation to an index for referencing orientation correct global icons */
3203 private int getCurrentOrientationIndexForGlobalIcons() {
3204 // default - 0, landscape - 1
3205 switch (getResources().getConfiguration().orientation) {
3206 case Configuration.ORIENTATION_LANDSCAPE:
3207 return 1;
3208 default:
3209 return 0;
3210 }
3211 }
3212
Michael Jurkaae65ee32012-04-30 11:45:54 -07003213 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003214 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003215 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003216 // Look for the toolbar icon specified in the activity meta-data
3217 Bundle metaData = packageManager.getActivityInfo(
3218 activityName, PackageManager.GET_META_DATA).metaData;
3219 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003220 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003221 if (iconResId != 0) {
3222 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003223 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003224 }
3225 }
3226 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003227 // This can happen if the activity defines an invalid drawable
3228 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3229 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003230 } catch (Resources.NotFoundException nfe) {
3231 // This can happen if the activity defines an invalid drawable
3232 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3233 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003234 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003235 return null;
3236 }
3237
3238 // if successful in getting icon, return it; otherwise, set button to use default drawable
3239 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003240 int buttonId, ComponentName activityName, int fallbackDrawableId,
3241 String toolbarResourceName) {
3242 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003243 Resources r = getResources();
3244 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3245 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003246
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003247 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003248 // If we were unable to find the icon via the meta-data, use a generic one
3249 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003250 toolbarIcon = r.getDrawable(fallbackDrawableId);
3251 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003252 if (button != null) {
3253 button.setCompoundDrawables(toolbarIcon, null, null, null);
3254 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003255 return null;
3256 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003257 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003258 if (button != null) {
3259 button.setCompoundDrawables(toolbarIcon, null, null, null);
3260 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003261 return toolbarIcon.getConstantState();
3262 }
3263 }
3264
3265 // if successful in getting icon, return it; otherwise, set button to use default drawable
3266 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003267 int buttonId, ComponentName activityName, int fallbackDrawableId,
3268 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003269 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003270 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003271
Michael Jurka19e0fc52011-07-22 18:00:21 -07003272 if (button != null) {
3273 // If we were unable to find the icon via the meta-data, use a
3274 // generic one
3275 if (toolbarIcon == null) {
3276 button.setImageResource(fallbackDrawableId);
3277 } else {
3278 button.setImageDrawable(toolbarIcon);
3279 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003280 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003281
3282 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3283
Michael Jurka0423dcf2010-10-05 14:56:18 -07003284 }
3285
Winson Chung1b884092012-06-08 17:13:02 -07003286 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003287 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003288 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003289 }
3290
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003291 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003292 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003293 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003294 }
3295
Winson Chungbb185bd2011-11-21 12:31:42 -08003296 private void invalidatePressedFocusedStates(View container, View button) {
3297 if (container instanceof HolographicLinearLayout) {
3298 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3299 layout.invalidatePressedFocusedStates();
3300 } else if (button instanceof HolographicImageView) {
3301 HolographicImageView view = (HolographicImageView) button;
3302 view.invalidatePressedFocusedStates();
3303 }
3304 }
3305
Cristina Stancu476493b2013-08-07 17:20:14 +01003306 public View getQsbBar() {
3307 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003308 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3309 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003310 }
3311 return mQsbBar;
3312 }
3313
3314 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003315 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003316 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003317 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003318 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003319
Winson Chung1cad91e2011-05-25 17:41:01 -07003320 final SearchManager searchManager =
3321 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3322 ComponentName activityName = searchManager.getGlobalSearchActivity();
3323 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003324 int coi = getCurrentOrientationIndexForGlobalIcons();
3325 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003326 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3327 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3328 if (sGlobalSearchIcon[coi] == null) {
3329 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3330 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3331 TOOLBAR_ICON_METADATA_NAME);
3332 }
3333
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3335 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003336 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003337 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003338 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003339 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003340 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3341 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003342 if (searchButton != null) searchButton.setVisibility(View.GONE);
3343 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003344 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003345 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003346 }
3347 }
3348
Cristina Stancu476493b2013-08-07 17:20:14 +01003349 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003350 final View searchButtonContainer = findViewById(R.id.search_button_container);
3351 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003352 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003353 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003354 }
3355
Cristina Stancu476493b2013-08-07 17:20:14 +01003356 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003357 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003358 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003359
Winson Chungc51db6a2011-10-05 11:44:49 -07003360 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003361 final SearchManager searchManager =
3362 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3363 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3364
3365 ComponentName activityName = null;
3366 if (globalSearchActivity != null) {
3367 // Check if the global search activity handles voice search
3368 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3369 intent.setPackage(globalSearchActivity.getPackageName());
3370 activityName = intent.resolveActivity(getPackageManager());
3371 }
3372
3373 if (activityName == null) {
3374 // Fallback: check if an activity other than the global search activity
3375 // resolves this
3376 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3377 activityName = intent.resolveActivity(getPackageManager());
3378 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003379 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003380 int coi = getCurrentOrientationIndexForGlobalIcons();
3381 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003382 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3383 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3384 if (sVoiceSearchIcon[coi] == null) {
3385 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3386 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3387 TOOLBAR_ICON_METADATA_NAME);
3388 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003389 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003390 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003391 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003392 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003393 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003394 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003395 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003396 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003397 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003398 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003399 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003400 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003401
Cristina Stancu476493b2013-08-07 17:20:14 +01003402 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003403 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3404 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003405 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003406 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003407 }
3408
Winson Chung5841efa2013-09-30 18:06:44 -07003409 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003410 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3411 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003412 boolean visible = !forceDisableVoiceButtonProxy &&
3413 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003414 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003415 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003416 }
3417 }
Winson Chung5841efa2013-09-30 18:06:44 -07003418
3419 /**
3420 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3421 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3422 */
3423 public void disableVoiceButtonProxy(boolean disabled) {
3424 updateVoiceButtonProxyVisible(disabled);
3425 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003426 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003427 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003428 */
3429 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003430 if (!DISABLE_MARKET_BUTTON) {
3431 final View marketButton = findViewById(R.id.market_button);
3432 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3433 // Find the app market activity by resolving an intent.
3434 // (If multiple app markets are installed, it will return the ResolverActivity.)
3435 ComponentName activityName = intent.resolveActivity(getPackageManager());
3436 if (activityName != null) {
3437 int coi = getCurrentOrientationIndexForGlobalIcons();
3438 mAppMarketIntent = intent;
3439 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3440 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3441 TOOLBAR_ICON_METADATA_NAME);
3442 marketButton.setVisibility(View.VISIBLE);
3443 } else {
3444 // We should hide and disable the view so that we don't try and restore the visibility
3445 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3446 marketButton.setVisibility(View.GONE);
3447 marketButton.setEnabled(false);
3448 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003449 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003450 }
3451
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003452 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003453 if (!DISABLE_MARKET_BUTTON) {
3454 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3455 Resources r = getResources();
3456 Drawable marketIconDrawable = d.newDrawable(r);
3457 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3458 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3459 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003460
Winson Chungd64a6662013-09-30 11:06:59 -07003461 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3462 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003463 }
3464
Michael Jurkad7c28052012-04-27 15:43:36 -07003465 @Override
3466 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003467 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003468 final List<CharSequence> text = event.getText();
3469 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003470 // Populate event with a fake title based on the current state.
3471 if (mState == State.APPS_CUSTOMIZE) {
3472 text.add(getString(R.string.all_apps_button_label));
3473 } else {
3474 text.add(getString(R.string.all_apps_home_button_label));
3475 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003476 return result;
3477 }
3478
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003479 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003480 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003481 */
3482 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3483 @Override
3484 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003485 closeSystemDialogs();
3486 }
3487 }
3488
3489 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003490 * Receives notifications whenever the appwidgets are reset.
3491 */
3492 private class AppWidgetResetObserver extends ContentObserver {
3493 public AppWidgetResetObserver() {
3494 super(new Handler());
3495 }
3496
3497 @Override
3498 public void onChange(boolean selfChange) {
3499 onAppWidgetReset();
3500 }
3501 }
3502
3503 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003504 * If the activity is currently paused, signal that we need to run the passed Runnable
3505 * in onResume.
3506 *
3507 * This needs to be called from incoming places where resources might have been loaded
3508 * while we are paused. That is becaues the Configuration might be wrong
3509 * when we're not running, and if it comes back to what it was when we
3510 * were paused, we are not restarted.
3511 *
3512 * Implementation of the method from LauncherModel.Callbacks.
3513 *
3514 * @return true if we are currently paused. The caller might be able to
3515 * skip some work in that case since we will come back again.
3516 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003517 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003518 if (mPaused) {
3519 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003520 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003521 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003522 }
3523 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003524 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003525 return true;
3526 } else {
3527 return false;
3528 }
3529 }
3530
Michael Jurkac402cd92013-05-20 15:49:32 +02003531 private boolean waitUntilResume(Runnable run) {
3532 return waitUntilResume(run, false);
3533 }
3534
Michael Jurka1e2f4652013-07-08 18:03:46 -07003535 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003536 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003537 }
3538
Michael Jurka7607c2f2013-04-03 14:33:19 -07003539 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003540 * If the activity is currently paused, signal that we need to re-run the loader
3541 * in onResume.
3542 *
3543 * This needs to be called from incoming places where resources might have been loaded
3544 * while we are paused. That is becaues the Configuration might be wrong
3545 * when we're not running, and if it comes back to what it was when we
3546 * were paused, we are not restarted.
3547 *
3548 * Implementation of the method from LauncherModel.Callbacks.
3549 *
3550 * @return true if we are currently paused. The caller might be able to
3551 * skip some work in that case since we will come back again.
3552 */
3553 public boolean setLoadOnResume() {
3554 if (mPaused) {
3555 Log.i(TAG, "setLoadOnResume");
3556 mOnResumeNeedsLoad = true;
3557 return true;
3558 } else {
3559 return false;
3560 }
3561 }
3562
3563 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003564 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003565 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003566 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003567 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003568 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003569 } else {
3570 return SCREEN_COUNT / 2;
3571 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003572 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003573
Joe Onorato9c1289c2009-08-17 11:03:03 -04003574 /**
3575 * Refreshes the shortcuts shown on the workspace.
3576 *
3577 * Implementation of the method from LauncherModel.Callbacks.
3578 */
3579 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003580 // If we're starting binding all over again, clear any bind calls we'd postponed in
3581 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3582 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003583 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003584
Winson Chungd64d1762013-08-20 14:37:16 -07003585 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003586 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003587 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003588
Michael Jurka05bf644e2011-11-30 20:28:53 -08003589 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003590 if (mHotseat != null) {
3591 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003592 }
3593 }
3594
Adam Cohendcd297f2013-06-18 13:13:40 -07003595 @Override
3596 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003597 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003598
Adam Cohen5084cba2013-09-03 12:01:16 -07003599 // If there are no screens, we need to have an empty screen
3600 if (orderedScreenIds.size() == 0) {
3601 mWorkspace.addExtraEmptyScreen();
3602 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003603
3604 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003605 // setCurrentPage() so ensure that all pages are added before calling this).
3606 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003607 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3608 mWorkspace.createCustomContentPage();
3609 }
Winson Chung64359a52013-07-08 17:17:08 -07003610 }
3611
3612 @Override
3613 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003614 int count = orderedScreenIds.size();
3615 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003616 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003617 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003618 }
3619
Adam Cohen39a06042013-07-19 14:30:12 -07003620 private boolean shouldShowWeightWatcher() {
3621 String spKey = LauncherAppState.getSharedPreferencesKey();
3622 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003623 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003624
3625 return show;
3626 }
3627
Adam Cohen4caf2982013-08-20 18:54:31 -07003628 private boolean emailSent() {
3629 String spKey = LauncherAppState.getSharedPreferencesKey();
3630 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3631 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3632 return show;
3633 }
3634
3635 private void setEmailSent(boolean sent) {
3636 String spKey = LauncherAppState.getSharedPreferencesKey();
3637 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3638
3639 SharedPreferences.Editor editor = sp.edit();
3640 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3641 editor.commit();
3642 }
3643
Adam Cohen39a06042013-07-19 14:30:12 -07003644 private void toggleShowWeightWatcher() {
3645 String spKey = LauncherAppState.getSharedPreferencesKey();
3646 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3647 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3648
3649 show = !show;
3650
3651 SharedPreferences.Editor editor = sp.edit();
3652 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3653 editor.commit();
3654
3655 if (mWeightWatcher != null) {
3656 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3657 }
3658 }
3659
Winson Chungd64d1762013-08-20 14:37:16 -07003660 public void bindAppsAdded(final ArrayList<Long> newScreens,
3661 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003662 final ArrayList<ItemInfo> addAnimated,
3663 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003664 Runnable r = new Runnable() {
3665 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003666 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003667 }
3668 };
3669 if (waitUntilResume(r)) {
3670 return;
3671 }
3672
Winson Chungd64d1762013-08-20 14:37:16 -07003673 // Add the new screens
3674 bindAddScreens(newScreens);
3675
3676 // We add the items without animation on non-visible pages, and with
3677 // animations on the new page (which we will try and snap to).
3678 if (!addNotAnimated.isEmpty()) {
3679 bindItems(addNotAnimated, 0,
3680 addNotAnimated.size(), false);
3681 }
3682 if (!addAnimated.isEmpty()) {
3683 bindItems(addAnimated, 0,
3684 addAnimated.size(), true);
3685 }
Winson Chungc58497e2013-09-03 17:48:37 -07003686
3687 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3688 addedApps != null && mAppsCustomizeContent != null) {
3689 mAppsCustomizeContent.addApps(addedApps);
3690 }
Winson Chungd64d1762013-08-20 14:37:16 -07003691 }
3692
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003693 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003694 * Bind the items start-end from the list.
3695 *
3696 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003697 */
Winson Chung64359a52013-07-08 17:17:08 -07003698 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3699 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003700 Runnable r = new Runnable() {
3701 public void run() {
3702 bindItems(shortcuts, start, end, forceAnimateIcons);
3703 }
3704 };
3705 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003706 return;
3707 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003708
Winson Chungf0c6ae02012-03-21 16:10:31 -07003709 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003710 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3711 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003712 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003713 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003714 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003715 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003716 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003717
3718 // Short circuit if we are loading dock items for a configuration which has no dock
3719 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3720 mHotseat == null) {
3721 continue;
3722 }
3723
Joe Onorato9c1289c2009-08-17 11:03:03 -04003724 switch (item.itemType) {
3725 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3726 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003727 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003728 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003729
Winson Chung64359a52013-07-08 17:17:08 -07003730 /*
3731 * TODO: FIX collision case
3732 */
Winson Chungce376632013-07-11 16:12:41 -07003733 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3734 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3735 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3736 throw new RuntimeException("OCCUPIED");
3737 }
Winson Chung64359a52013-07-08 17:17:08 -07003738 }
3739
Adam Cohendcd297f2013-06-18 13:13:40 -07003740 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3741 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003742 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003743 // Animate all the applications up now
3744 shortcut.setAlpha(0f);
3745 shortcut.setScaleX(0f);
3746 shortcut.setScaleY(0f);
3747 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003748 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003749 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003750 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003751 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003752 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003753 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003754 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003755 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3756 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003757 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003758 default:
3759 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003760 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003761 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003762
Winson Chung997a9232013-07-24 15:33:46 -07003763 if (animateIcons) {
3764 // Animate to the correct page
3765 if (newShortcutsScreenId > -1) {
3766 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003767 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003768 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003769 // We post the animation slightly delayed to prevent slowdowns
3770 // when we are loading right after we return to launcher.
3771 mWorkspace.postDelayed(new Runnable() {
3772 public void run() {
3773 mWorkspace.snapToPage(newScreenIndex);
3774 mWorkspace.postDelayed(new Runnable() {
3775 public void run() {
3776 anim.playTogether(bounceAnims);
3777 anim.start();
3778 }
3779 }, NEW_APPS_ANIMATION_DELAY);
3780 }
3781 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003782 }
3783 }
Winson Chung64359a52013-07-08 17:17:08 -07003784 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003785 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003786 }
3787
Joe Onorato9c1289c2009-08-17 11:03:03 -04003788 /**
3789 * Implementation of the method from LauncherModel.Callbacks.
3790 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003791 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003792 Runnable r = new Runnable() {
3793 public void run() {
3794 bindFolders(folders);
3795 }
3796 };
3797 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003798 return;
3799 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003800 sFolders.clear();
3801 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003802 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003803
3804 /**
3805 * Add the views for a widget to the workspace.
3806 *
3807 * Implementation of the method from LauncherModel.Callbacks.
3808 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003809 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003810 Runnable r = new Runnable() {
3811 public void run() {
3812 bindAppWidget(item);
3813 }
3814 };
3815 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003816 return;
3817 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003818
Daniel Sandler843e8602010-06-07 14:59:01 -04003819 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3820 if (DEBUG_WIDGETS) {
3821 Log.d(TAG, "bindAppWidget: " + item);
3822 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003823 final Workspace workspace = mWorkspace;
3824
3825 final int appWidgetId = item.appWidgetId;
3826 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003827 if (DEBUG_WIDGETS) {
3828 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3829 }
3830
Joe Onorato9c1289c2009-08-17 11:03:03 -04003831 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3832
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003834 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003835
Adam Cohendcd297f2013-06-18 13:13:40 -07003836 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003838 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3839
Joe Onorato9c1289c2009-08-17 11:03:03 -04003840 workspace.requestLayout();
3841
Daniel Sandler843e8602010-06-07 14:59:01 -04003842 if (DEBUG_WIDGETS) {
3843 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3844 + (SystemClock.uptimeMillis()-start) + "ms");
3845 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003846 }
3847
Adam Cohen1462de32012-07-24 22:34:36 -07003848 public void onPageBoundSynchronously(int page) {
3849 mSynchronouslyBoundPages.add(page);
3850 }
3851
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 /**
3853 * Callback saying that there aren't any more items to bind.
3854 *
3855 * Implementation of the method from LauncherModel.Callbacks.
3856 */
Adam Cohene25af792013-06-06 23:08:25 -07003857 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003858 Runnable r = new Runnable() {
3859 public void run() {
3860 finishBindingItems(upgradePath);
3861 }
3862 };
3863 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003864 return;
3865 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003866 if (mSavedState != null) {
3867 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003868 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003869 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003870 mSavedState = null;
3871 }
3872
Adam Cohen1462de32012-07-24 22:34:36 -07003873 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003874
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003875 // If we received the result of any pending adds while the loader was running (e.g. the
3876 // widget configuration forced an orientation change), process them now.
3877 for (int i = 0; i < sPendingAddList.size(); i++) {
3878 completeAdd(sPendingAddList.get(i));
3879 }
3880 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003881
Winson Chungc51db6a2011-10-05 11:44:49 -07003882 // Update the market app icon as necessary (the other icons will be managed in response to
3883 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003884 if (!DISABLE_MARKET_BUTTON) {
3885 updateAppMarketIcon();
3886 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003887
Winson Chungf0c6ae02012-03-21 16:10:31 -07003888 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003889 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003890 mWorkspace.getUniqueComponents(true, null);
3891 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003892 }
Adam Cohen99894d92013-06-14 11:22:59 -07003893
Adam Cohen66a01fd2013-06-11 12:48:00 -07003894 mWorkspace.post(new Runnable() {
3895 @Override
3896 public void run() {
3897 onFinishBindingItems();
3898 }
3899 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003900 }
3901
Winson Chunga0b7e862013-09-05 16:03:15 -07003902 public boolean isAllAppsButtonRank(int rank) {
3903 if (mHotseat != null) {
3904 return mHotseat.isAllAppsButtonRank(rank);
3905 }
3906 return false;
3907 }
3908
Winson Chunga2413752012-04-03 14:22:34 -07003909 private boolean canRunNewAppsAnimation() {
3910 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3911 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3912 }
3913
Winson Chungc9168342013-06-26 14:54:55 -07003914 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3915 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3916 PropertyValuesHolder.ofFloat("alpha", 1f),
3917 PropertyValuesHolder.ofFloat("scaleX", 1f),
3918 PropertyValuesHolder.ofFloat("scaleY", 1f));
3919 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3920 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3921 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3922 return bounceAnim;
3923 }
3924
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003925 @Override
3926 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003927 boolean searchVisible = updateGlobalSearchIcon();
3928 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003929 if (mSearchDropTargetBar != null) {
3930 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3931 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003932 }
3933
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003934 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 * Add the icons for all apps.
3936 *
3937 * Implementation of the method from LauncherModel.Callbacks.
3938 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003939 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003940 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3941 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3942 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3943 getHotseat().addAllAppsFolder(mIconCache, apps,
3944 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3945 }
3946 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003947 }
Winson Chungc58497e2013-09-03 17:48:37 -07003948 } else {
3949 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3950 mAppsCustomizeContent != null) {
3951 mAppsCustomizeContent.setApps(apps);
3952 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003953 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003954 }
3955
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003956 @Override
3957 public boolean shouldShowApp(ResolveInfo app) {
3958 return true;
3959 }
3960
Joe Onorato9c1289c2009-08-17 11:03:03 -04003961 /**
3962 * A package was updated.
3963 *
3964 * Implementation of the method from LauncherModel.Callbacks.
3965 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003966 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003967 Runnable r = new Runnable() {
3968 public void run() {
3969 bindAppsUpdated(apps);
3970 }
3971 };
3972 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003973 return;
3974 }
3975
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003976 if (mWorkspace != null) {
3977 mWorkspace.updateShortcuts(apps);
3978 }
Winson Chungc58497e2013-09-03 17:48:37 -07003979
3980 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3981 mAppsCustomizeContent != null) {
3982 mAppsCustomizeContent.updateApps(apps);
3983 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003984 }
3985
3986 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003987 * A package was uninstalled. We take both the super set of packageNames
3988 * in addition to specific applications to remove, the reason being that
3989 * this can be called when a package is updated as well. In that scenario,
3990 * we only remove specific components from the workspace, where as
3991 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003992 *
3993 * Implementation of the method from LauncherModel.Callbacks.
3994 */
Winson Chung83892cc2013-05-01 16:53:33 -07003995 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003996 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003997 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003998 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003999 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07004000 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07004001 }
Winson Chungd64d1762013-08-20 14:37:16 -07004002 };
4003 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004004 return;
4005 }
4006
Winson Chung64359a52013-07-08 17:17:08 -07004007 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07004008 mWorkspace.removeItemsByPackageName(packageNames);
4009 } else {
4010 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004011 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004012
Winson Chunga1820962011-10-03 16:31:06 -07004013 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07004014 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07004015
4016 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4017 mAppsCustomizeContent != null) {
4018 mAppsCustomizeContent.removeApps(appInfos);
4019 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004020 }
Joe Onoratobe386092009-11-17 17:32:16 -08004021
4022 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004023 * A number of packages were updated.
4024 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004025 private ArrayList<Object> mWidgetsAndShortcuts;
4026 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004027 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004028 bindPackagesUpdated(mWidgetsAndShortcuts);
4029 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004030 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004031 };
4032
4033 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4034 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4035 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004036 return;
4037 }
4038
Winson Chung64359a52013-07-08 17:17:08 -07004039 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004040 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4041 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004042 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004043 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004044 }
4045
Winson Chung400438b2011-01-16 17:53:48 -08004046 private int mapConfigurationOriActivityInfoOri(int configOri) {
4047 final Display d = getWindowManager().getDefaultDisplay();
4048 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4049 switch (d.getRotation()) {
4050 case Surface.ROTATION_0:
4051 case Surface.ROTATION_180:
4052 // We are currently in the same basic orientation as the natural orientation
4053 naturalOri = configOri;
4054 break;
4055 case Surface.ROTATION_90:
4056 case Surface.ROTATION_270:
4057 // We are currently in the other basic orientation to the natural orientation
4058 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4059 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4060 break;
4061 }
4062
4063 int[] oriMap = {
4064 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4065 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4066 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4067 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4068 };
4069 // Since the map starts at portrait, we need to offset if this device's natural orientation
4070 // is landscape.
4071 int indexOffset = 0;
4072 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4073 indexOffset = 1;
4074 }
4075 return oriMap[(d.getRotation() + indexOffset) % 4];
4076 }
Adam Cohen446e9402011-09-15 18:21:21 -07004077
Winson Chung4b919f82012-05-01 10:44:08 -07004078 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004079 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004080 getResources().getBoolean(R.bool.allow_rotation);
4081 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004082 }
Winson Chung4b919f82012-05-01 10:44:08 -07004083 public void lockScreenOrientation() {
4084 if (isRotationEnabled()) {
4085 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4086 .getConfiguration().orientation));
4087 }
4088 }
4089 public void unlockScreenOrientation(boolean immediate) {
4090 if (isRotationEnabled()) {
4091 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004092 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004093 } else {
4094 mHandler.postDelayed(new Runnable() {
4095 public void run() {
4096 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4097 }
4098 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004099 }
Winson Chung4b919f82012-05-01 10:44:08 -07004100 }
Winson Chung400438b2011-01-16 17:53:48 -08004101 }
4102
Winson Chung82f55532011-08-09 14:14:23 -07004103 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004104 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004105 if (DISABLE_CLINGS) {
4106 return false;
4107 }
4108
Brett Chabot2a9e2282011-08-23 15:03:13 -07004109 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004110 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004111
Michael Jurkae233a8b2013-03-19 13:49:20 +01004112 // Restricted secondary users (child mode) will potentially have very few apps
4113 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004114// boolean supportsLimitedUsers =
4115// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4116// Account[] accounts = AccountManager.get(this).getAccounts();
4117// if (supportsLimitedUsers && accounts.length == 0) {
4118// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4119// Bundle restrictions = um.getUserRestrictions();
4120// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4121// return false;
4122// }
4123// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004124 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004125 }
Michael Jurka22143132012-10-04 17:42:38 +02004126
Winson Chungfa545132013-09-26 17:45:32 -07004127 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004128 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004129 Cling cling = (Cling) findViewById(clingId);
4130 View scrim = null;
4131 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004132 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004133 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004134 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004135 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004136 cling.show(animate, SHOW_CLING_DURATION);
4137
4138 if (dimNavBarVisibilty) {
4139 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4140 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004141 }
4142 }
4143 return cling;
4144 }
Michael Jurka22143132012-10-04 17:42:38 +02004145
Winson Chungaf40f202013-09-18 18:26:31 -07004146 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4147 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004148 // To catch cases where siblings of top-level views are made invisible, just check whether
4149 // the cling is directly set to GONE before dismissing it.
4150 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004151 final Runnable cleanUpClingCb = new Runnable() {
4152 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004153 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004154 // We should update the shared preferences on a background thread
4155 new Thread("dismissClingThread") {
4156 public void run() {
4157 SharedPreferences.Editor editor = mSharedPrefs.edit();
4158 editor.putBoolean(flag, true);
4159 editor.commit();
4160 }
4161 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004162 if (postAnimationCb != null) {
4163 postAnimationCb.run();
4164 }
4165 }
4166 };
4167 if (duration <= 0) {
4168 cleanUpClingCb.run();
4169 } else {
4170 cling.hide(duration, cleanUpClingCb);
4171 }
Michael Jurka22143132012-10-04 17:42:38 +02004172 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004173
4174 if (restoreNavBarVisibilty) {
4175 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4176 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4177 }
Winson Chung82f55532011-08-09 14:14:23 -07004178 }
4179 }
Michael Jurka22143132012-10-04 17:42:38 +02004180
Winson Chung9d9d74f2011-09-19 11:49:12 -07004181 private void removeCling(int id) {
4182 final View cling = findViewById(id);
4183 if (cling != null) {
4184 final ViewGroup parent = (ViewGroup) cling.getParent();
4185 parent.post(new Runnable() {
4186 @Override
4187 public void run() {
4188 parent.removeView(cling);
4189 }
4190 });
Michael Jurka22143132012-10-04 17:42:38 +02004191 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004192 }
4193 }
Michael Jurka974c3862012-05-22 22:00:31 -07004194
4195 private boolean skipCustomClingIfNoAccounts() {
4196 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4197 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4198 if (customCling) {
4199 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004200 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004201 Account[] accounts = am.getAccountsByType("com.google");
4202 return accounts.length == 0;
4203 }
4204 return false;
4205 }
4206
Winson Chungaf40f202013-09-18 18:26:31 -07004207 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004208 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004209 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004210 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004211 // If we're not using the default workspace layout, replace workspace cling
4212 // with a custom workspace cling (usually specified in an overlay)
4213 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004214 if (!DISABLE_CUSTOM_CLINGS) {
4215 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4216 getResources().getBoolean(R.bool.config_useCustomClings)) {
4217 // Use a custom cling
4218 View cling = findViewById(R.id.workspace_cling);
4219 ViewGroup clingParent = (ViewGroup) cling.getParent();
4220 int clingIndex = clingParent.indexOfChild(cling);
4221 clingParent.removeViewAt(clingIndex);
4222 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4223 clingParent.addView(customCling, clingIndex);
4224 customCling.setId(R.id.workspace_cling);
4225 }
4226 }
4227 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4228 if (cling != null) {
4229 String sbHintStr = getFirstRunClingSearchBarHint();
4230 String ccHintStr = getFirstRunCustomContentHint();
4231 if (!sbHintStr.isEmpty()) {
4232 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4233 sbHint.setText(sbHintStr);
4234 sbHint.setVisibility(View.VISIBLE);
4235 }
4236 if (!ccHintStr.isEmpty()) {
4237 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4238 ccHint.setText(ccHintStr);
4239 ccHint.setVisibility(View.VISIBLE);
4240 }
Michael Jurka45355c42012-10-08 13:21:35 +02004241 }
Winson Chungfa545132013-09-26 17:45:32 -07004242 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004243 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004244 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004245 }
4246 }
Winson Chungaf40f202013-09-18 18:26:31 -07004247
Winson Chunge6eabff2013-09-24 11:01:23 -07004248 protected String getFirstRunClingSearchBarHint() {
4249 return "";
4250 }
4251 protected String getFirstRunCustomContentHint() {
4252 return "";
4253 }
4254
Winson Chungaf40f202013-09-18 18:26:31 -07004255 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004256 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004257 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004258 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004259 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004260 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004261 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004262 }
4263 }
4264 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004265 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004266 if (isClingsEnabled() &&
4267 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004268 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4269 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004270 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004271 } else {
4272 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004273 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004274 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004275 }
Michael Jurka104c4562013-07-08 18:03:46 -07004276 protected SharedPreferences getSharedPrefs() {
4277 return mSharedPrefs;
4278 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004279 public boolean isFolderClingVisible() {
4280 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004281 if (cling != null) {
4282 return cling.getVisibility() == View.VISIBLE;
4283 }
4284 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004285 }
Winson Chungaf40f202013-09-18 18:26:31 -07004286 public void dismissFirstRunCling(View v) {
4287 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4288 Runnable cb = new Runnable() {
4289 public void run() {
4290 // Show the workspace cling next
4291 showFirstRunWorkspaceCling();
4292 }
4293 };
4294 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4295 DISMISS_CLING_DURATION, false);
4296 }
Winson Chung82f55532011-08-09 14:14:23 -07004297 public void dismissWorkspaceCling(View v) {
4298 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004299 Runnable cb = null;
4300 if (v == null) {
4301 cb = new Runnable() {
4302 public void run() {
4303 mWorkspace.enterOverviewMode();
4304 }
4305 };
4306 }
4307 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4308 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004309 }
4310 public void dismissFolderCling(View v) {
4311 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004312 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4313 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004314 }
4315
Winson Chung80baf5a2010-08-09 16:03:15 -07004316 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004317 * Prints out out state for debugging.
4318 */
4319 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004320 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004321 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004322 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4323 Log.d(TAG, "mRestoring=" + mRestoring);
4324 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4325 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004326 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004327 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004328
Winson Chung785d2eb2011-04-14 16:08:02 -07004329 if (mAppsCustomizeContent != null) {
4330 mAppsCustomizeContent.dumpState();
4331 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004332 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004333 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004334
4335 @Override
4336 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4337 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004338 synchronized (sDumpLogs) {
4339 writer.println(" ");
4340 writer.println("Debug logs: ");
4341 for (int i = 0; i < sDumpLogs.size(); i++) {
4342 writer.println(" " + sDumpLogs.get(i));
4343 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004344 }
4345 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004346
4347 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004348 if (DEBUG_DUMP_LOG) {
4349 synchronized (sDumpLogs) {
4350 Log.d(TAG, "");
4351 Log.d(TAG, "*********************");
4352 Log.d(TAG, "Launcher debug logs: ");
4353 for (int i = 0; i < sDumpLogs.size(); i++) {
4354 Log.d(TAG, " " + sDumpLogs.get(i));
4355 }
4356 Log.d(TAG, "*********************");
4357 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004358 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004359 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004360 }
4361
4362 public static void addDumpLog(String tag, String log, boolean debugLog) {
4363 if (debugLog) {
4364 Log.d(tag, log);
4365 }
Winson Chungede41292013-09-19 16:27:36 -07004366 if (DEBUG_DUMP_LOG) {
4367 sDateStamp.setTime(System.currentTimeMillis());
4368 synchronized (sDumpLogs) {
4369 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004370 }
Winson Chungede41292013-09-19 16:27:36 -07004371 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004372 }
4373
Winson Chungede41292013-09-19 16:27:36 -07004374 public void dumpLogsToLocalData() {
4375 if (DEBUG_DUMP_LOG) {
4376 new Thread("DumpLogsToLocalData") {
4377 @Override
4378 public void run() {
4379 boolean success = false;
4380 sDateStamp.setTime(sRunStart);
4381 String FILENAME = sDateStamp.getMonth() + "-"
4382 + sDateStamp.getDay() + "_"
4383 + sDateStamp.getHours() + "-"
4384 + sDateStamp.getMinutes() + "_"
4385 + sDateStamp.getSeconds() + ".txt";
4386
4387 FileOutputStream fos = null;
4388 File outFile = null;
4389 try {
4390 outFile = new File(getFilesDir(), FILENAME);
4391 outFile.createNewFile();
4392 fos = new FileOutputStream(outFile);
4393 } catch (Exception e) {
4394 e.printStackTrace();
4395 }
4396 if (fos != null) {
4397 PrintWriter writer = new PrintWriter(fos);
4398
4399 writer.println(" ");
4400 writer.println("Debug logs: ");
4401 synchronized (sDumpLogs) {
4402 for (int i = 0; i < sDumpLogs.size(); i++) {
4403 writer.println(" " + sDumpLogs.get(i));
4404 }
4405 }
4406 writer.close();
4407 }
4408 try {
4409 if (fos != null) {
4410 fos.close();
4411 success = true;
4412 }
4413 } catch (IOException e) {
4414 e.printStackTrace();
4415 }
4416 }
4417 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004418 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004420}
Michael Jurka2763be32011-02-24 11:19:57 -08004421
Michael Jurkaabded662011-03-04 12:06:57 -08004422interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004423 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004424 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004425 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004426 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004427 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004428}