blob: 5047e9e05875081e1905a1040405187b0b1b8db2 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700212 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
213 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700214 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700215
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800216 private final BroadcastReceiver mCloseSystemDialogsReceiver
217 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800218 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 private LayoutInflater mInflater;
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700223 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800224 private DragLayer mDragLayer;
225 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700226 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700227
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700228 private AppWidgetManager mAppWidgetManager;
229 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700230
Michael Jurkac9d95c52011-08-29 14:03:34 -0700231 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700232 private AppWidgetProviderInfo mPendingAddWidgetInfo;
233
Michael Jurka0280c3b2010-09-17 15:00:07 -0700234 private int[] mTmpAddItemCellCoordinates = new int[2];
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private FolderInfo mFolderInfo;
237
Winson Chung3d503fb2011-07-13 17:25:49 -0700238 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700239 private View mOverviewPanel;
240
Michael Jurka838a4ca2011-02-07 13:33:06 -0800241 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700242
Winson Chungc51db6a2011-10-05 11:44:49 -0700243 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700244 private AppsCustomizeTabHost mAppsCustomizeTabHost;
245 private AppsCustomizePagedView mAppsCustomizeContent;
246 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100247 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700250 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
251 // scroll issues (because the workspace may not have been measured yet) and extra work.
252 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
253 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
255 private SpannableStringBuilder mDefaultKeySsb = null;
256
Joe Onorato9c1289c2009-08-17 11:03:03 -0400257 private boolean mWorkspaceLoading = true;
258
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800259 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 private boolean mRestoring;
261 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700262 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
Michael Jurka1e2f4652013-07-08 18:03:46 -0700264 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700265 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
266
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // Keep track of whether the user has left launcher
268 private static boolean sPausedFromUserAction = false;
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private Bundle mSavedInstanceState;
271
Joe Onorato9c1289c2009-08-17 11:03:03 -0400272 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800273 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800274 private boolean mUserPresent = true;
275 private boolean mVisible = false;
276 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700277 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700278 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static LocaleConfiguration sLocaleConfiguration = null;
281
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700282 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Winson Chungd64a6662013-09-30 11:06:59 -0700302 private Intent mAppMarketIntent = null;
303 private static final boolean DISABLE_MARKET_BUTTON = true;
304
Craig Mautner360310b2012-10-26 15:13:08 -0700305 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700306
Adam Cohen1462de32012-07-24 22:34:36 -0700307 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
308
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700309 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700310 static Date sDateStamp = new Date();
311 static DateFormat sDateFormat =
312 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
313 static long sRunStart = System.currentTimeMillis();
314 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700315
Winson Chung46353de2012-02-16 14:05:10 -0800316 // We only want to get the SharedPreferences once since it does an FS stat each time we get
317 // it from the context.
318 private SharedPreferences mSharedPrefs;
319
Adam Cohene25af792013-06-06 23:08:25 -0700320 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
321
Winson Chungf0c6ae02012-03-21 16:10:31 -0700322 // Holds the page that we need to animate to, and the icon views that we need to animate up
323 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700324 private ImageView mFolderIconImageView;
325 private Bitmap mFolderIconBitmap;
326 private Canvas mFolderIconCanvas;
327 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700328
Michael Jurkaddd62e92011-02-16 17:49:14 -0800329 private BubbleTextView mWaitingForResume;
330
Michael Jurka22143132012-10-04 17:42:38 +0200331 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
332 = new HideFromAccessibilityHelper();
333
Michael Jurkac1f5d262011-09-30 19:32:27 -0700334 private Runnable mBuildLayersRunnable = new Runnable() {
335 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700336 if (mWorkspace != null) {
337 mWorkspace.buildPageHardwareLayers();
338 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700339 }
340 };
341
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800342 private static ArrayList<PendingAddArguments> sPendingAddList
343 = new ArrayList<PendingAddArguments>();
344
Michael Jurka0a457bf2012-11-19 14:05:05 -0800345 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
346
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800347 private static class PendingAddArguments {
348 int requestCode;
349 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700350 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700351 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352 int cellX;
353 int cellY;
354 }
355
Daniel Sandlerff02d492013-08-05 02:12:05 -0400356 private Stats mStats;
357
Michael Jurka0a457bf2012-11-19 14:05:05 -0800358 private static boolean isPropertyEnabled(String propertyName) {
359 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700360 }
361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 @Override
363 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700364 if (DEBUG_STRICT_MODE) {
365 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
366 .detectDiskReads()
367 .detectDiskWrites()
368 .detectNetwork() // or .detectAll() for all detectable problems
369 .penaltyLog()
370 .build());
371 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
372 .detectLeakedSqlLiteObjects()
373 .detectLeakedClosableObjects()
374 .penaltyLog()
375 .penaltyDeath()
376 .build());
377 }
378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400381 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400382 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700383
384 // Determine the dynamic grid properties
385 Point smallestSize = new Point();
386 Point largestSize = new Point();
387 Point realSize = new Point();
388 Display display = getWindowManager().getDefaultDisplay();
389 display.getCurrentSizeRange(smallestSize, largestSize);
390 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700391 DisplayMetrics dm = new DisplayMetrics();
392 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700393 // Lazy-initialize the dynamic grid
394 DeviceProfile grid = app.initDynamicGrid(this,
395 Math.min(smallestSize.x, smallestSize.y),
396 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700397 realSize.x, realSize.y,
398 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700399
400 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400401 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700402 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800403 mModel = app.setLauncher(this);
404 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400405 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700407
Daniel Sandlerff02d492013-08-05 02:12:05 -0400408 mStats = new Stats(this);
409
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700411 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
412 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700413
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700414 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
415 // this also ensures that any synchronous binding below doesn't re-trigger another
416 // LauncherModel load.
417 mPaused = false;
418
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200420 android.os.Debug.startMethodTracing(
421 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 }
423
424 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 setContentView(R.layout.launcher);
426 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100427 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800429 registerContentObservers();
430
Joe Onorato7c312c12009-08-13 21:36:53 -0700431 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 mSavedState = savedInstanceState;
434 restoreState(mSavedState);
435
Winson Chunga12a2502010-12-20 14:41:35 -0800436 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700437 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200438 mAppsCustomizeContent.onPackagesUpdated(
439 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700440 }
Winson Chunga12a2502010-12-20 14:41:35 -0800441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 if (PROFILE_STARTUP) {
443 android.os.Debug.stopMethodTracing();
444 }
445
446 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700447 if (sPausedFromUserAction) {
448 // If the user leaves launcher, then we should just load items asynchronously when
449 // they return.
450 mModel.startLoader(true, -1);
451 } else {
452 // We only load the page synchronously if the user rotates (or triggers a
453 // configuration change) while launcher is in the foreground
454 mModel.startLoader(true, mWorkspace.getCurrentPage());
455 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 }
457
458 // For handling default keys
459 mDefaultKeySsb = new SpannableStringBuilder();
460 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800461
462 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
463 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800464
Adam Cohenf9426d52012-06-04 17:26:21 -0700465 updateGlobalIcons();
466
467 // On large interfaces, we want the screen to auto-rotate based on the current orientation
468 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700469
470 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700471 }
472
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 protected void onUserLeaveHint() {
474 super.onUserLeaveHint();
475 sPausedFromUserAction = true;
476 }
477
Winson Chung98ca0f72013-07-29 12:58:51 -0700478 /** To be overriden by subclasses to hint to Launcher that we have custom content */
479 protected boolean hasCustomContentToLeft() {
480 return false;
481 }
482
Dave Hawkeya8881582013-09-17 15:55:33 -0600483 /**
484 * To be overridden by subclasses to create the custom content and call
485 * {@link #addToCustomContentPage}. This will only be invoked if
486 * {@link #hasCustomContentToLeft()} is {@code true}.
487 */
488 protected void addCustomContentToLeft() {
489 }
490
491 /**
492 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
493 * ensure the custom content page is added or removed if necessary.
494 */
495 protected void invalidateHasCustomContentToLeft() {
496 if (mWorkspace.getScreenOrder().isEmpty()) {
497 // Not bound yet, wait for bindScreens to be called.
498 return;
499 }
500
501 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
502 // Create the custom content page and call the subclass to populate it.
503 mWorkspace.createCustomContentPage();
504 addCustomContentToLeft();
505 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
506 mWorkspace.removeCustomContentPage();
507 }
508 }
509
Adam Cohenf9426d52012-06-04 17:26:21 -0700510 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700511 boolean searchVisible = false;
512 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800513 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700514 int coi = getCurrentOrientationIndexForGlobalIcons();
515 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
516 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700517 if (!DISABLE_MARKET_BUTTON) {
518 updateAppMarketIcon();
519 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700520 searchVisible = updateGlobalSearchIcon();
521 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700522 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700523 if (sGlobalSearchIcon[coi] != null) {
524 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700525 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700526 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700527 if (sVoiceSearchIcon[coi] != null) {
528 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700529 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700530 }
Winson Chungd64a6662013-09-30 11:06:59 -0700531 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700532 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800533 }
Winson Chungadf0c182012-08-23 14:59:07 -0700534 if (mSearchDropTargetBar != null) {
535 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
536 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800537 }
Romain Guycbb89e42009-06-08 15:52:54 -0700538
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700540 if (sLocaleConfiguration == null) {
541 new AsyncTask<Void, Void, LocaleConfiguration>() {
542 @Override
543 protected LocaleConfiguration doInBackground(Void... unused) {
544 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
545 readConfiguration(Launcher.this, localeConfiguration);
546 return localeConfiguration;
547 }
548
549 @Override
550 protected void onPostExecute(LocaleConfiguration result) {
551 sLocaleConfiguration = result;
552 checkForLocaleChange(); // recursive, but now with a locale configuration
553 }
554 }.execute();
555 return;
556 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700557
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final Configuration configuration = getResources().getConfiguration();
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final String locale = configuration.locale.toString();
562
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700563 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final int mcc = configuration.mcc;
565
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700566 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567 final int mnc = configuration.mnc;
568
Romain Guy84f296c2009-11-04 15:00:44 -0800569 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570
Romain Guy84f296c2009-11-04 15:00:44 -0800571 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700572 sLocaleConfiguration.locale = locale;
573 sLocaleConfiguration.mcc = mcc;
574 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700575
Joe Onorato0589f0f2010-02-08 13:44:00 -0800576 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700577
578 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
579 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700580 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700581 public void run() {
582 writeConfiguration(Launcher.this, localeConfiguration);
583 }
584 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700585 }
586 }
587
588 private static class LocaleConfiguration {
589 public String locale;
590 public int mcc = -1;
591 public int mnc = -1;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
Romain Guy98d01652009-06-30 16:21:04 -0700594 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
595 DataInputStream in = null;
596 try {
597 in = new DataInputStream(context.openFileInput(PREFERENCES));
598 configuration.locale = in.readUTF();
599 configuration.mcc = in.readInt();
600 configuration.mnc = in.readInt();
601 } catch (FileNotFoundException e) {
602 // Ignore
603 } catch (IOException e) {
604 // Ignore
605 } finally {
606 if (in != null) {
607 try {
608 in.close();
609 } catch (IOException e) {
610 // Ignore
611 }
612 }
613 }
614 }
615
616 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
617 DataOutputStream out = null;
618 try {
619 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
620 out.writeUTF(configuration.locale);
621 out.writeInt(configuration.mcc);
622 out.writeInt(configuration.mnc);
623 out.flush();
624 } catch (FileNotFoundException e) {
625 // Ignore
626 } catch (IOException e) {
627 //noinspection ResultOfMethodCallIgnored
628 context.getFileStreamPath(PREFERENCES).delete();
629 } finally {
630 if (out != null) {
631 try {
632 out.close();
633 } catch (IOException e) {
634 // Ignore
635 }
636 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800637 }
638 }
639
Anton Hanssona2f665f2013-09-26 12:18:32 +0100640 public Stats getStats() {
641 return mStats;
642 }
643
Bjorn Bringertc459e522013-06-07 19:36:01 +0100644 public LayoutInflater getInflater() {
645 return mInflater;
646 }
647
Adam Cohen716b51e2011-06-30 12:09:54 -0700648 public DragLayer getDragLayer() {
649 return mDragLayer;
650 }
651
Winson Chung36a62fe2012-05-06 18:04:42 -0700652 boolean isDraggingEnabled() {
653 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
654 // that is subsequently removed from the workspace in startBinding().
655 return !mModel.isLoadingWorkspace();
656 }
657
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 static int getScreen() {
659 synchronized (sLock) {
660 return sScreen;
661 }
662 }
663
664 static void setScreen(int screen) {
665 synchronized (sLock) {
666 sScreen = screen;
667 }
668 }
669
Winson Chung557d6ed2011-07-08 15:34:52 -0700670 /**
671 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
672 * a configuration step, this allows the proper animations to run after other transitions.
673 */
674 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700675 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800676 switch (args.requestCode) {
677 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700678 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700679 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800680 break;
681 case REQUEST_PICK_SHORTCUT:
682 processShortcut(args.intent);
683 break;
684 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700685 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700686 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700687 result = true;
688 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800689 case REQUEST_CREATE_APPWIDGET:
690 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700691 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700692 result = true;
693 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800694 }
Michael Jurka27614d22012-04-02 06:40:22 -0700695 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
696 // if you turned the screen off and then back while in All Apps, Launcher would not
697 // return to the workspace. Clearing mAddInfo.container here fixes this issue
698 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700699 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800700 }
701
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700703 protected void onActivityResult(
704 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700705 // Reset the startActivity waiting flag
706 mWaitingForResult = false;
707
Michael Jurka8b805b12012-04-18 14:23:14 -0700708 if (requestCode == REQUEST_BIND_APPWIDGET) {
709 int appWidgetId = data != null ?
710 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
711 if (resultCode == RESULT_CANCELED) {
712 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
713 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700714 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700715 }
716 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200717 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
718 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
719 mWorkspace.exitOverviewMode(false);
720 }
721 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700722 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200723
Winson Chung557d6ed2011-07-08 15:34:52 -0700724 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800725 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
726 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700727
Adam Cohened66b2b2012-01-23 17:28:51 -0800728 // We have special handling for widgets
729 if (isWidgetDrop) {
730 int appWidgetId = data != null ?
731 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700732 if (appWidgetId < 0) {
733 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
734 "widget configuration activity.");
735 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
736 } else {
737 completeTwoStageWidgetDrop(resultCode, appWidgetId);
738 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800739 return;
740 }
741
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 // The pattern used here is that a user PICKs a specific application,
743 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700744
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
746 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700747 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 final PendingAddArguments args = new PendingAddArguments();
749 args.requestCode = requestCode;
750 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700751 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700752 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700753 args.cellX = mPendingAddInfo.cellX;
754 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800755 if (isWorkspaceLocked()) {
756 sPendingAddList.add(args);
757 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700758 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800759 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800760 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800761 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700762 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
764 null);
765 }
766
767 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700768 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700769 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800770 Runnable onCompleteRunnable = null;
771 int animationType = 0;
772
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700773 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800774 if (resultCode == RESULT_OK) {
775 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
776 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700777 mPendingAddWidgetInfo);
778 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 onCompleteRunnable = new Runnable() {
780 @Override
781 public void run() {
782 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700783 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800784 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
785 null);
786 }
787 };
788 } else if (resultCode == RESULT_CANCELED) {
789 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
790 onCompleteRunnable = new Runnable() {
791 @Override
792 public void run() {
793 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
794 null);
795 }
796 };
797 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700798 if (mDragLayer.getAnimatedView() != null) {
799 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
800 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
801 animationType, boundWidget, true);
802 } else {
803 // The animated view may be null in the case of a rotation during widget configuration
804 onCompleteRunnable.run();
805 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800806 }
807
808 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700809 protected void onStop() {
810 super.onStop();
811 FirstFrameAnimatorHelper.setIsVisible(false);
812 }
813
814 @Override
815 protected void onStart() {
816 super.onStart();
817 FirstFrameAnimatorHelper.setIsVisible(true);
818 }
819
820 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200822 long startTime = 0;
823 if (DEBUG_RESUME_TIME) {
824 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400825 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200826 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700828
Winson Chung4a2afa32012-07-19 14:53:05 -0700829 // Restore the previous launcher state
830 if (mOnResumeState == State.WORKSPACE) {
831 showWorkspace(false);
832 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700833 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700834 }
835 mOnResumeState = State.NONE;
836
Craig Mautner360310b2012-10-26 15:13:08 -0700837 // Background was set to gradient in onPause(), restore to black if in all apps.
838 setWorkspaceBackground(mState == State.WORKSPACE);
839
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800840 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700841 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700842 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400843 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700844 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400845 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700846 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700848 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200849 // We might have postponed some bind calls until onResume (see waitUntilResume) --
850 // execute them here
851 long startTimeCallbacks = 0;
852 if (DEBUG_RESUME_TIME) {
853 startTimeCallbacks = System.currentTimeMillis();
854 }
855
856 if (mAppsCustomizeContent != null) {
857 mAppsCustomizeContent.setBulkBind(true);
858 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700859 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
860 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200861 }
862 if (mAppsCustomizeContent != null) {
863 mAppsCustomizeContent.setBulkBind(false);
864 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700865 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200866 if (DEBUG_RESUME_TIME) {
867 Log.d(TAG, "Time spent processing callbacks in onResume: " +
868 (System.currentTimeMillis() - startTimeCallbacks));
869 }
Michael Jurka447bf842013-05-15 14:52:15 +0200870 }
Michael Jurka54554252013-08-01 12:52:23 +0200871 if (mOnResumeCallbacks.size() > 0) {
872 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
873 mOnResumeCallbacks.get(i).run();
874 }
875 mOnResumeCallbacks.clear();
876 }
Winson Chunge4e50662012-01-23 14:45:13 -0800877
878 // Reset the pressed state of icons that were locked in the press state while activities
879 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800880 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800881 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800882 mWaitingForResume.setStayPressed(false);
883 }
Winson Chunge4e50662012-01-23 14:45:13 -0800884 if (mAppsCustomizeContent != null) {
885 // Resets the previous all apps icon press state
886 mAppsCustomizeContent.resetDrawableState();
887 }
Winson Chung780fe592013-09-26 14:48:44 -0700888 // Reset AllApps to its initial state
889 if (mAppsCustomizeTabHost != null) {
890 mAppsCustomizeTabHost.reset();
891 }
Adam Cohen06dff352012-06-01 17:17:08 -0700892 // It is possible that widgets can receive updates while launcher is not in the foreground.
893 // Consequently, the widgets will be inflated in the orientation of the foreground activity
894 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
895 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700896 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700897
Winson Chung780fe592013-09-26 14:48:44 -0700898 // Process any items that were added while Launcher was away.
899 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
900
Adam Cohenf9426d52012-06-04 17:26:21 -0700901 // Again, as with the above scenario, it's possible that one or more of the global icons
902 // were updated in the wrong orientation.
903 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200904 if (DEBUG_RESUME_TIME) {
905 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
906 }
Adam Cohen06dff352012-06-01 17:17:08 -0700907 }
908
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800909 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700910 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700911 // Ensure that items added to Launcher are queued until Launcher returns
912 InstallShortcutReceiver.enableInstallQueue();
913
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700914 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700915 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800916 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700917 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700918 }
Romain Guycbb89e42009-06-08 15:52:54 -0700919
Adam Cohen66a01fd2013-06-11 12:48:00 -0700920 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700921 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600922 addCustomContentToLeft();
923 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700924 }
925
Adam Cohenbffe7452013-07-22 18:21:45 -0700926 QSBScroller mQsbScroller = new QSBScroller() {
927 int scrollY = 0;
928
929 @Override
930 public void setScrollY(int scroll) {
931 scrollY = scroll;
932
933 if (mWorkspace.isOnOrMovingToCustomContent()) {
934 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100935 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700936 }
937 }
938 };
939
940 public void resetQSBScroll() {
941 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100942 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700943 }
944
945 public interface CustomContentCallbacks {
946 // Custom content is completely shown
947 public void onShow();
948
949 // Custom content is completely hidden
950 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700951
952 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
953 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700954 }
955
Adam Cohen30bacb22013-08-29 14:25:25 -0700956 protected void startSettings() {
957 }
958
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 public interface QSBScroller {
960 public void setScrollY(int scrollY);
961 }
962
Adam Cohen66a01fd2013-06-11 12:48:00 -0700963 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700964 public QSBScroller addToCustomContentPage(View customContent) {
965 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700966 }
967
Winson Chung98ca0f72013-07-29 12:58:51 -0700968 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700969 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700970 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700971 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700972 }
973
Adam Cohenedb40762013-07-18 16:45:45 -0700974 // The custom content needs to offset its content to account for the QSB
975 public int getTopOffsetForCustomContent() {
976 return mWorkspace.getPaddingTop();
977 }
978
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700979 @Override
980 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400981 // Flag the loader to stop early before switching
982 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700983 if (mAppsCustomizeContent != null) {
984 mAppsCustomizeContent.surrender();
985 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800986 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700987 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700988
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800989 // We can't hide the IME if it was forced open. So don't bother
990 /*
991 @Override
992 public void onWindowFocusChanged(boolean hasFocus) {
993 super.onWindowFocusChanged(hasFocus);
994
995 if (hasFocus) {
996 final InputMethodManager inputManager = (InputMethodManager)
997 getSystemService(Context.INPUT_METHOD_SERVICE);
998 WindowManager.LayoutParams lp = getWindow().getAttributes();
999 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1000 android.os.Handler()) {
1001 protected void onReceiveResult(int resultCode, Bundle resultData) {
1002 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1003 }
1004 });
1005 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1006 }
1007 }
1008 */
1009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 private boolean acceptFilter() {
1011 final InputMethodManager inputManager = (InputMethodManager)
1012 getSystemService(Context.INPUT_METHOD_SERVICE);
1013 return !inputManager.isFullscreenMode();
1014 }
1015
1016 @Override
1017 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001018 final int uniChar = event.getUnicodeChar();
1019 final boolean handled = super.onKeyDown(keyCode, event);
1020 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1021 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1023 keyCode, event);
1024 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001025 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001026 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001027 // showSearchDialog()
1028 // If there are multiple keystrokes before the search dialog takes focus,
1029 // onSearchRequested() will be called for every keystroke,
1030 // but it is idempotent, so it's fine.
1031 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 }
1033 }
1034
Joe Onorato8a9625e2010-01-28 15:55:35 -08001035 // Eat the long press event so the keyboard doesn't come up.
1036 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1037 return true;
1038 }
1039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 return handled;
1041 }
1042
Karl Rosaen138a0412009-04-23 19:00:21 -07001043 private String getTypedText() {
1044 return mDefaultKeySsb.toString();
1045 }
1046
1047 private void clearTypedText() {
1048 mDefaultKeySsb.clear();
1049 mDefaultKeySsb.clearSpans();
1050 Selection.setSelection(mDefaultKeySsb, 0);
1051 }
1052
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001054 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1055 * State
1056 */
1057 private static State intToState(int stateOrdinal) {
1058 State state = State.WORKSPACE;
1059 final State[] stateValues = State.values();
1060 for (int i = 0; i < stateValues.length; i++) {
1061 if (stateValues[i].ordinal() == stateOrdinal) {
1062 state = stateValues[i];
1063 break;
1064 }
1065 }
1066 return state;
1067 }
1068
1069 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070 * Restores the previous state, if it exists.
1071 *
1072 * @param savedState The previous state.
1073 */
1074 private void restoreState(Bundle savedState) {
1075 if (savedState == null) {
1076 return;
1077 }
1078
Michael Jurka883f55b2010-10-21 15:47:14 -07001079 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001080 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001081 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001082 }
1083
Winson Chungf0c6ae02012-03-21 16:10:31 -07001084 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001086 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 }
1088
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001090 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001091
Winson Chung3d503fb2011-07-13 17:25:49 -07001092 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1093 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001094 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001095 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1096 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001097 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1098 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1099 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001100 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 mRestoring = true;
1102 }
1103
1104 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1105 if (renameFolder) {
1106 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001107 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108 mRestoring = true;
1109 }
Winson Chunga12a2502010-12-20 14:41:35 -08001110
Winson Chung785d2eb2011-04-14 16:08:02 -07001111 // Restore the AppsCustomize tab
1112 if (mAppsCustomizeTabHost != null) {
1113 String curTab = savedState.getString("apps_customize_currentTab");
1114 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001115 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001117 mAppsCustomizeContent.loadAssociatedPages(
1118 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001119 }
1120
Winson Chung5afbf7b2011-07-25 11:53:08 -07001121 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1122 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001123 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124 }
1125
1126 /**
1127 * Finds all the views we need and configure them properly.
1128 */
1129 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001130 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001131
Craig Mautner360310b2012-10-26 15:13:08 -07001132 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001133 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1134 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001135
John Spurlock77e1f472013-09-11 10:09:51 -04001136 mLauncherView.setSystemUiVisibility(
1137 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001138 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139
Winson Chung4c98d922011-05-31 16:50:48 -07001140 // Setup the drag layer
1141 mDragLayer.setup(this, dragController);
1142
Winson Chung3d503fb2011-07-13 17:25:49 -07001143 // Setup the hotseat
1144 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1145 if (mHotseat != null) {
1146 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001147 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001148 }
1149
Adam Cohenf358a4b2013-07-23 16:47:31 -07001150 mOverviewPanel = findViewById(R.id.overview_panel);
1151 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1152 @Override
1153 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001154 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001155 }
1156 });
1157 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1158 @Override
1159 public void onClick(View arg0) {
1160 startWallpaper();
1161 }
1162 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001163 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1164 @Override
1165 public void onClick(View arg0) {
1166 startSettings();
1167 }
1168 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001169 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001170
Winson Chung4c98d922011-05-31 16:50:48 -07001171 // Setup the workspace
1172 mWorkspace.setHapticFeedbackEnabled(false);
1173 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001174 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001175 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001176
Winson Chungf0ea4d32011-06-06 14:27:16 -07001177 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001178 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001179
Winson Chungf0ea4d32011-06-06 14:27:16 -07001180 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001181 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001182 mAppsCustomizeContent = (AppsCustomizePagedView)
1183 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1184 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001185
Winson Chung3d503fb2011-07-13 17:25:49 -07001186 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001187 dragController.setDragScoller(mWorkspace);
1188 dragController.setScrollView(mDragLayer);
1189 dragController.setMoveTarget(mWorkspace);
1190 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001191 if (mSearchDropTargetBar != null) {
1192 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001193 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001194
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001195 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001197 mWeightWatcher = new WeightWatcher(this);
1198 mWeightWatcher.setAlpha(0.5f);
1199 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001200 new FrameLayout.LayoutParams(
1201 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001202 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001203 Gravity.BOTTOM)
1204 );
Adam Cohen39a06042013-07-19 14:30:12 -07001205
1206 boolean show = shouldShowWeightWatcher();
1207 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001208 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 /**
1212 * Creates a view representing a shortcut.
1213 *
1214 * @param info The data structure describing the shortcut.
1215 *
1216 * @return A View inflated from R.layout.application.
1217 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001218 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001220 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221 }
1222
1223 /**
1224 * Creates a view representing a shortcut inflated from the specified resource.
1225 *
1226 * @param layoutResId The id of the XML layout used to create the shortcut.
1227 * @param parent The group the shortcut belongs to.
1228 * @param info The data structure describing the shortcut.
1229 *
1230 * @return A View inflated from layoutResId.
1231 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001232 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001233 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1234 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 return favorite;
1237 }
1238
1239 /**
1240 * Add an application shortcut to the workspace.
1241 *
1242 * @param data The intent describing the application.
1243 * @param cellInfo The position on screen where to create the shortcut.
1244 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001245 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001246 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001247 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001248
Adam Cohenfbba09b2011-07-18 21:43:05 -07001249 // First we check if we already know the exact location where we want to add this item.
1250 if (cellX >= 0 && cellY >= 0) {
1251 cellXY[0] = cellX;
1252 cellXY[1] = cellY;
1253 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001254 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001255 return;
1256 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001258 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001259
Romain Guy73b979d2009-06-09 12:57:21 -07001260 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001261 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001263 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001264 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001265 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001266 } else {
1267 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 }
1269 }
Romain Guycbb89e42009-06-08 15:52:54 -07001270
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001271 /**
1272 * Add a shortcut to the workspace.
1273 *
1274 * @param data The intent describing the shortcut.
1275 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001278 int cellY) {
1279 int[] cellXY = mTmpAddItemCellCoordinates;
1280 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001281 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001282
Michael Jurkad3ef3062010-11-23 16:23:58 -08001283 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001284
Adam Cohen558baaf2011-08-15 15:22:57 -07001285 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001286 if (info == null) {
1287 return;
1288 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001289 final View view = createShortcut(info);
1290
Adam Cohenfbba09b2011-07-18 21:43:05 -07001291 // First we check if we already know the exact location where we want to add this item.
1292 if (cellX >= 0 && cellY >= 0) {
1293 cellXY[0] = cellX;
1294 cellXY[1] = cellY;
1295 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001296
1297 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001298 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001299 true, null,null)) {
1300 return;
1301 }
1302 DragObject dragObject = new DragObject();
1303 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001304 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1305 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001306 return;
1307 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001308 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001309 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001310 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001311 foundCellSpan = (result != null);
1312 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001313 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001314 }
1315
1316 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001317 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001318 return;
1319 }
1320
Adam Cohendcd297f2013-06-18 13:13:40 -07001321 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322
1323 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001324 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001325 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 }
1327 }
1328
Adam Cohen2f093b62012-04-30 18:59:53 -07001329 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1330 int minHeight) {
1331 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001332 // We want to account for the extra amount of padding that we are adding to the widget
1333 // to ensure that it gets the full amount of space that it has requested
1334 int requiredWidth = minWidth + padding.left + padding.right;
1335 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001336 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1340 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001341 }
1342
Adam Cohen2f093b62012-04-30 18:59:53 -07001343 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1344 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001345 }
1346
Adam Cohen2f093b62012-04-30 18:59:53 -07001347 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1348 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001349 }
1350
Adam Cohen2f093b62012-04-30 18:59:53 -07001351 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1352 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001353 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001354 }
1355
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001359 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001360 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001362 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001363 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1364 if (appWidgetInfo == null) {
1365 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1366 }
Romain Guycbb89e42009-06-08 15:52:54 -07001367
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001368 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001369 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001370
Adam Cohen2f093b62012-04-30 18:59:53 -07001371 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1372 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001373
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001375 // We have saved the position to which the widget was dragged-- this really only matters
1376 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 int[] cellXY = mTmpAddItemCellCoordinates;
1378 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001379 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001380 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001381 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1382 cellXY[0] = mPendingAddInfo.cellX;
1383 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001384 spanXY[0] = mPendingAddInfo.spanX;
1385 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001386 foundCellSpan = true;
1387 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001389 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001390 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1391 spanXY[1], cellXY, finalSpan);
1392 spanXY[0] = finalSpan[0];
1393 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001394 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001395 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001396 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001397 }
1398
Michael Jurka0280c3b2010-09-17 15:00:07 -07001399 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001400 if (appWidgetId != -1) {
1401 // Deleting an app widget ID is a void call but writes to disk before returning
1402 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001403 new Thread("deleteAppWidgetId") {
1404 public void run() {
1405 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1406 }
1407 }.start();
1408 }
Winson Chung93eef082012-03-23 15:59:27 -07001409 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001410 return;
1411 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001413 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001414 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1415 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 launcherInfo.spanX = spanXY[0];
1417 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001418 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1419 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001420
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001421 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001422 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423
1424 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001425 if (hostView == null) {
1426 // Perform actual inflation because we're live
1427 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1428 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1429 } else {
1430 // The AppWidgetHostView has already been inflated and instantiated
1431 launcherInfo.hostView = hostView;
1432 }
Romain Guycbb89e42009-06-08 15:52:54 -07001433
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001435 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001436 launcherInfo.notifyWidgetSizeChanged(this);
1437
Adam Cohendcd297f2013-06-18 13:13:40 -07001438 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001439 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001440
1441 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001442 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001443 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444 }
Romain Guycbb89e42009-06-08 15:52:54 -07001445
Adam Cohended9f8d2010-11-03 13:25:16 -07001446 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1447 @Override
1448 public void onReceive(Context context, Intent intent) {
1449 final String action = intent.getAction();
1450 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1451 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001452 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001453 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001454
Winson Chungc100e8e2011-08-09 16:02:43 -07001455 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001456 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001457 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001458 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001459 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001460 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1461 mUserPresent = true;
1462 updateRunning();
1463 }
1464 }
1465 };
1466
1467 @Override
1468 public void onAttachedToWindow() {
1469 super.onAttachedToWindow();
1470
1471 // Listen for broadcasts related to user-presence
1472 final IntentFilter filter = new IntentFilter();
1473 filter.addAction(Intent.ACTION_SCREEN_OFF);
1474 filter.addAction(Intent.ACTION_USER_PRESENT);
1475 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001476 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001477 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001478 mVisible = true;
1479 }
1480
1481 @Override
1482 public void onDetachedFromWindow() {
1483 super.onDetachedFromWindow();
1484 mVisible = false;
1485
Adam Cohend113e0c2010-11-11 10:48:05 -08001486 if (mAttached) {
1487 unregisterReceiver(mReceiver);
1488 mAttached = false;
1489 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001490 updateRunning();
1491 }
1492
1493 public void onWindowVisibilityChanged(int visibility) {
1494 mVisible = visibility == View.VISIBLE;
1495 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001496 // The following code used to be in onResume, but it turns out onResume is called when
1497 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1498 // is a more appropriate event to handle
1499 if (mVisible) {
1500 mAppsCustomizeTabHost.onWindowVisible();
1501 if (!mWorkspaceLoading) {
1502 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001503 // We want to let Launcher draw itself at least once before we force it to build
1504 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 // apps is nice and speedy.
1506 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001507 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001508 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001509 if (mStarted) return;
1510 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001511 // We delay the layer building a bit in order to give
1512 // other message processing a time to run. In particular
1513 // this avoids a delay in hiding the IME if it was
1514 // currently shown, because doing that may involve
1515 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001516 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001517 final ViewTreeObserver.OnDrawListener listener = this;
1518 mWorkspace.post(new Runnable() {
1519 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001520 if (mWorkspace != null &&
1521 mWorkspace.getViewTreeObserver() != null) {
1522 mWorkspace.getViewTreeObserver().
1523 removeOnDrawListener(listener);
1524 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001525 }
1526 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001527 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001528 }
1529 });
1530 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001531 // When Launcher comes back to foreground, a different Activity might be responsible for
1532 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001533 if (!DISABLE_MARKET_BUTTON) {
1534 updateAppMarketIcon();
1535 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001536 clearTypedText();
1537 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001538 }
1539
1540 private void sendAdvanceMessage(long delay) {
1541 mHandler.removeMessages(ADVANCE_MSG);
1542 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1543 mHandler.sendMessageDelayed(msg, delay);
1544 mAutoAdvanceSentTime = System.currentTimeMillis();
1545 }
1546
1547 private void updateRunning() {
1548 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1549 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1550 mAutoAdvanceRunning = autoAdvanceRunning;
1551 if (autoAdvanceRunning) {
1552 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1553 sendAdvanceMessage(delay);
1554 } else {
1555 if (!mWidgetsToAdvance.isEmpty()) {
1556 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1557 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1558 }
1559 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001560 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001561 }
1562 }
1563 }
1564
1565 private final Handler mHandler = new Handler() {
1566 @Override
1567 public void handleMessage(Message msg) {
1568 if (msg.what == ADVANCE_MSG) {
1569 int i = 0;
1570 for (View key: mWidgetsToAdvance.keySet()) {
1571 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1572 final int delay = mAdvanceStagger * i;
1573 if (v instanceof Advanceable) {
1574 postDelayed(new Runnable() {
1575 public void run() {
1576 ((Advanceable) v).advance();
1577 }
1578 }, delay);
1579 }
1580 i++;
1581 }
1582 sendAdvanceMessage(mAdvanceInterval);
1583 }
1584 }
1585 };
1586
1587 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001588 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001589 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1590 if (v instanceof Advanceable) {
1591 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001592 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001593 updateRunning();
1594 }
1595 }
1596
1597 void removeWidgetToAutoAdvance(View hostView) {
1598 if (mWidgetsToAdvance.containsKey(hostView)) {
1599 mWidgetsToAdvance.remove(hostView);
1600 updateRunning();
1601 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001602 }
1603
Joe Onorato9c1289c2009-08-17 11:03:03 -04001604 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001605 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001606 launcherInfo.hostView = null;
1607 }
1608
Winson Chung93eef082012-03-23 15:59:27 -07001609 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1610 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1611 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001612 }
1613
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001614 public LauncherAppWidgetHost getAppWidgetHost() {
1615 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001616 }
Romain Guycbb89e42009-06-08 15:52:54 -07001617
Winson Chunga9abd0e2010-10-27 17:18:37 -07001618 public LauncherModel getModel() {
1619 return mModel;
1620 }
1621
Bjorn Bringertc459e522013-06-07 19:36:01 +01001622 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001623 getWindow().closeAllPanels();
1624
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001625 // Whatever we were doing is hereby canceled.
1626 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001627 }
1628
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001629 @Override
1630 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001631 long startTime = 0;
1632 if (DEBUG_RESUME_TIME) {
1633 startTime = System.currentTimeMillis();
1634 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 super.onNewIntent(intent);
1636
1637 // Close the menu
1638 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001639 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001640 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001641
Jamie Genniscb222e82012-10-23 15:44:26 -07001642 final boolean alreadyOnHome =
1643 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001644 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001645
Jamie Genniscb222e82012-10-23 15:44:26 -07001646 Runnable processIntent = new Runnable() {
1647 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001648 if (mWorkspace == null) {
1649 // Can be cases where mWorkspace is null, this prevents a NPE
1650 return;
1651 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001652 Folder openFolder = mWorkspace.getOpenFolder();
1653 // In all these cases, only animate if we're already on home
1654 mWorkspace.exitWidgetResizeMode();
1655 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1656 openFolder == null) {
1657 mWorkspace.moveToDefaultScreen(true);
1658 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001659
Jamie Genniscb222e82012-10-23 15:44:26 -07001660 closeFolder();
1661 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001662
Jamie Genniscb222e82012-10-23 15:44:26 -07001663 // If we are already on home, then just animate back to the workspace,
1664 // otherwise, just wait until onResume to set the state back to Workspace
1665 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001666 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001667 } else {
1668 mOnResumeState = State.WORKSPACE;
1669 }
1670
1671 final View v = getWindow().peekDecorView();
1672 if (v != null && v.getWindowToken() != null) {
1673 InputMethodManager imm = (InputMethodManager)getSystemService(
1674 INPUT_METHOD_SERVICE);
1675 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1676 }
1677
Winson Chung7819a562013-09-19 15:55:45 -07001678 // Reset the apps customize page
1679 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001680 mAppsCustomizeTabHost.reset();
1681 }
1682 }
1683 };
1684
1685 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1686 // Delay processing of the intent to allow the status bar animation to finish
1687 // first in order to avoid janky animations.
1688 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001689 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001690 // Process the intent immediately.
1691 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001692 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001693
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 }
Michael Jurka447bf842013-05-15 14:52:15 +02001695 if (DEBUG_RESUME_TIME) {
1696 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1697 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 }
1699
Adam Cohen040a5d22013-09-16 17:09:33 -07001700 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1701 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001702 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001703 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001704 }
1705 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001706 protected void showWorkspaceAndExitOverviewMode() {
1707 showWorkspaceAndExitOverviewMode(true);
1708 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001711 public void onRestoreInstanceState(Bundle state) {
1712 super.onRestoreInstanceState(state);
1713 for (int page: mSynchronouslyBoundPages) {
1714 mWorkspace.restoreInstanceStateForChild(page);
1715 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 }
1717
1718 @Override
1719 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001720 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001721 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722
Michael Jurka883f55b2010-10-21 15:47:14 -07001723 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001724 // We close any open folder since it will not be re-opened, and we need to make sure
1725 // this state is reflected.
1726 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727
Adam Cohendcd297f2013-06-18 13:13:40 -07001728 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001729 mWaitingForResult) {
1730 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001731 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001732 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1733 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001734 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1735 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1736 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 }
1738
1739 if (mFolderInfo != null && mWaitingForResult) {
1740 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1741 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1742 }
Michael Jurka946ad472010-07-09 18:05:18 -07001743
Winson Chung785d2eb2011-04-14 16:08:02 -07001744 // Save the current AppsCustomize tab
1745 if (mAppsCustomizeTabHost != null) {
1746 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1747 if (currentTabTag != null) {
1748 outState.putString("apps_customize_currentTab", currentTabTag);
1749 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001750 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1751 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001752 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
1754
1755 @Override
1756 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001758
Winson Chunge7a03942011-08-05 15:05:12 -07001759 // Remove all pending runnables
1760 mHandler.removeMessages(ADVANCE_MSG);
1761 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001762 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001763
Winson Chungcd2b0142011-06-08 16:02:26 -07001764 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001765 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001766 mModel.stopLoader();
1767 app.setLauncher(null);
1768
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001770 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001772 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001773 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001774 mAppWidgetHost = null;
1775
1776 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001777
1778 TextKeyListener.getInstance().release();
1779
Winson Chung81b52252012-08-27 15:34:29 -07001780 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1781 // to prevent leaking Launcher activities on orientation change.
1782 if (mModel != null) {
1783 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1784 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001785
1786 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001787 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001788
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001789 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001790 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1791 mWorkspace.removeAllViews();
1792 mWorkspace = null;
1793 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001794
Michael Jurka2ecf9952012-06-18 12:52:28 -07001795 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 }
1797
Adam Cohena9cf38f2011-05-02 15:36:58 -07001798 public DragController getDragController() {
1799 return mDragController;
1800 }
1801
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 @Override
1803 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001804 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 super.startActivityForResult(intent, requestCode);
1806 }
1807
Winson Chung70d72102011-08-12 11:24:35 -07001808 /**
1809 * Indicates that we want global search for this activity by setting the globalSearch
1810 * argument for {@link #startSearch} to true.
1811 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001813 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001815
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001816 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001817
Karl Rosaen138a0412009-04-23 19:00:21 -07001818 if (initialQuery == null) {
1819 // Use any text typed in the launcher as the initial query
1820 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001821 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 if (appSearchData == null) {
1823 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001824 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 }
Winson Chungadf0c182012-08-23 14:59:07 -07001826 Rect sourceBounds = new Rect();
1827 if (mSearchDropTargetBar != null) {
1828 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1829 }
Romain Guycbb89e42009-06-08 15:52:54 -07001830
Bjorn Bringertc459e522013-06-07 19:36:01 +01001831 startSearch(initialQuery, selectInitialQuery,
1832 appSearchData, sourceBounds);
1833 }
1834
1835 public void startSearch(String initialQuery,
1836 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001837 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001838 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001839 }
1840
1841 /**
1842 * Starts the global search activity. This code is a copied from SearchManager
1843 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001844 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001845 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001846 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001847 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1848 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1849 if (globalSearchActivity == null) {
1850 Log.w(TAG, "No global search activity found.");
1851 return;
1852 }
1853 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1854 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1855 intent.setComponent(globalSearchActivity);
1856 // Make sure that we have a Bundle to put source in
1857 if (appSearchData == null) {
1858 appSearchData = new Bundle();
1859 } else {
1860 appSearchData = new Bundle(appSearchData);
1861 }
1862 // Set source to package name of app that starts global search, if not set already.
1863 if (!appSearchData.containsKey("source")) {
1864 appSearchData.putString("source", getPackageName());
1865 }
1866 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1867 if (!TextUtils.isEmpty(initialQuery)) {
1868 intent.putExtra(SearchManager.QUERY, initialQuery);
1869 }
1870 if (selectInitialQuery) {
1871 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1872 }
1873 intent.setSourceBounds(sourceBounds);
1874 try {
1875 startActivity(intent);
1876 } catch (ActivityNotFoundException ex) {
1877 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1878 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 }
1880
Winson Chung70d72102011-08-12 11:24:35 -07001881 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001882 public boolean onPrepareOptionsMenu(Menu menu) {
1883 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001884 if (!mWorkspace.isInOverviewMode()) {
1885 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001886 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001887 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001890 @Override
1891 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001892 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001893 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001894 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001895 }
1896
Joe Onorato9c1289c2009-08-17 11:03:03 -04001897 public boolean isWorkspaceLocked() {
1898 return mWorkspaceLoading || mWaitingForResult;
1899 }
1900
Michael Jurka0280c3b2010-09-17 15:00:07 -07001901 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001903 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001904 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1905 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001906 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001907 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001908 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001909
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001910 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1911 AppWidgetProviderInfo appWidgetInfo) {
1912 if (appWidgetInfo.configure != null) {
1913 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001914
Bjorn Bringert7984c942009-12-09 15:38:25 +00001915 // Launch over to configure widget, if needed
1916 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001917 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001918 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001919 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001921 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001922 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001923 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001924 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001925 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 }
1927 }
Romain Guycbb89e42009-06-08 15:52:54 -07001928
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001929 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001930 // Close any folders that may be open.
1931 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001932 mWorkspace.moveToCustomContentScreen(animate);
1933 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001934 /**
1935 * Process a shortcut drop.
1936 *
1937 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001938 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001939 * @param cell The cell it should be added to, optional
1940 * @param position The location on the screen where it was dropped, optional
1941 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001942 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001943 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001944 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001945 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001946 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001947 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001948
1949 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001950 mPendingAddInfo.cellX = cell[0];
1951 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001953
1954 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1955 createShortcutIntent.setComponent(componentName);
1956 processShortcut(createShortcutIntent);
1957 }
1958
Adam Cohenfbba09b2011-07-18 21:43:05 -07001959 /**
1960 * Process a widget drop.
1961 *
1962 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001963 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001964 * @param cell The cell it should be added to, optional
1965 * @param position The location on the screen where it was dropped, optional
1966 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001967 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001968 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001969 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001970 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001971 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001972 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001973 mPendingAddInfo.minSpanX = info.minSpanX;
1974 mPendingAddInfo.minSpanY = info.minSpanY;
1975
Adam Cohenfbba09b2011-07-18 21:43:05 -07001976 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001977 mPendingAddInfo.cellX = cell[0];
1978 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001979 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001980 if (span != null) {
1981 mPendingAddInfo.spanX = span[0];
1982 mPendingAddInfo.spanY = span[1];
1983 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001984
Adam Cohened66b2b2012-01-23 17:28:51 -08001985 AppWidgetHostView hostView = info.boundWidget;
1986 int appWidgetId;
1987 if (hostView != null) {
1988 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001989 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001990 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001991 // In this case, we either need to start an activity to get permission to bind
1992 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001993 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001994 Bundle options = info.bindOptions;
1995
1996 boolean success = false;
1997 if (options != null) {
1998 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1999 info.componentName, options);
2000 } else {
2001 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2002 info.componentName);
2003 }
2004 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002005 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002006 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002007 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002008 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2009 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2010 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002011 // TODO: we need to make sure that this accounts for the options bundle.
2012 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002013 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2014 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002015 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002016 }
2017
Joe Onoratodeb98af2010-02-19 14:59:39 -08002018 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002019 // Handle case where user selected "Applications"
2020 String applicationName = getResources().getString(R.string.group_applications);
2021 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002022
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002023 if (applicationName != null && applicationName.equals(shortcutName)) {
2024 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2025 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002026
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002027 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2028 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002029 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002030 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002031 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002032 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002033 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 }
2035
Winson Chung24ab2f12010-09-16 14:10:47 -07002036 void processWallpaper(Intent intent) {
2037 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2038 }
2039
Adam Cohendcd297f2013-06-18 13:13:40 -07002040 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002042 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 folderInfo.title = getText(R.string.folder_name);
2044
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002046 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002047 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002048 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049
2050 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002051 FolderIcon newFolder =
2052 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002053 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002054 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002055 // Force measure the new folder icon
2056 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2057 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002058 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 }
Romain Guycbb89e42009-06-08 15:52:54 -07002060
Joe Onorato9c1289c2009-08-17 11:03:03 -04002061 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002062 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002063 }
2064
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002065 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002066 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002068 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002069 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 }
2071
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002072 protected ComponentName getWallpaperPickerComponent() {
2073 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2074 }
2075
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002076 /**
2077 * Registers various content observers. The current implementation registers
2078 * only a favorites observer to keep track of the favorites applications.
2079 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002080 private void registerContentObservers() {
2081 ContentResolver resolver = getContentResolver();
2082 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2083 true, mWidgetObserver);
2084 }
2085
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002086 @Override
2087 public boolean dispatchKeyEvent(KeyEvent event) {
2088 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2089 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002090 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002091 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002092 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002093 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002094 dumpState();
2095 return true;
2096 }
2097 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002098 }
2099 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2100 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002101 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002102 return true;
2103 }
2104 }
2105
2106 return super.dispatchKeyEvent(event);
2107 }
2108
Joe Onorato88ec0992009-11-19 13:16:06 -08002109 @Override
2110 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002111 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002112 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002113 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002114 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002115 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002116 Folder openFolder = mWorkspace.getOpenFolder();
2117 if (openFolder.isEditingName()) {
2118 openFolder.dismissEditingName();
2119 } else {
2120 closeFolder();
2121 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002122 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002123 mWorkspace.exitWidgetResizeMode();
2124
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002125 // Back button is a no-op here, but give at least some feedback for the button press
2126 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002127 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002128 }
2129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002131 * Re-listen when widgets are reset.
2132 */
2133 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002134 if (mAppWidgetHost != null) {
2135 mAppWidgetHost.startListening();
2136 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002137 }
2138
2139 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002140 * Launches the intent referred by the clicked shortcut.
2141 *
2142 * @param v The view representing the clicked shortcut.
2143 */
2144 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002145 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2146 // view has detached (it's possible for this to happen if the view is removed mid touch).
2147 if (v.getWindowToken() == null) {
2148 return;
2149 }
2150
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002151 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002152 return;
2153 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002154
Adam Cohen1697b792013-09-17 19:08:21 -07002155 if (v instanceof Workspace) {
2156 if (mWorkspace.isInOverviewMode()) {
2157 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002158 }
2159 return;
2160 }
2161
2162 if (v instanceof CellLayout) {
2163 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002164 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002165 }
2166 }
2167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002168 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002169 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002170 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002171 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2172 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002173
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002174 // Check for special shortcuts
2175 if (intent.getComponent() != null) {
2176 final String shortcutClass = intent.getComponent().getClassName();
2177
2178 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002179 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002180 return;
2181 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2182 MemoryDumpActivity.startDump(this);
2183 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002184 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2185 toggleShowWeightWatcher();
2186 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002187 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002188 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002189
2190 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002191 int[] pos = new int[2];
2192 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002193 intent.setSourceBounds(new Rect(pos[0], pos[1],
2194 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002195
2196 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002197
Daniel Sandlerff02d492013-08-05 02:12:05 -04002198 mStats.recordLaunch(intent, shortcut);
2199
Michael Jurkaddd62e92011-02-16 17:49:14 -08002200 if (success && v instanceof BubbleTextView) {
2201 mWaitingForResume = (BubbleTextView) v;
2202 mWaitingForResume.setStayPressed(true);
2203 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002205 if (v instanceof FolderIcon) {
2206 FolderIcon fi = (FolderIcon) v;
2207 handleFolderClick(fi);
2208 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002209 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002210 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002211 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002212 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002213 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002214 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 }
2216 }
2217
Michael Jurka0e260592010-06-30 17:07:39 -07002218 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002219 return false;
2220 }
2221
Michael Jurkaaf442092010-06-10 17:01:57 -07002222 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002223 * Event handler for the search button
2224 *
2225 * @param v The view that was clicked.
2226 */
2227 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002228 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2229
Amith Yamasania135ba82011-08-09 17:42:01 -07002230 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002231 }
2232
2233 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002234 * Event handler for the voice button
2235 *
2236 * @param v The view that was clicked.
2237 */
2238 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002239 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002240
Bjorn Bringertc459e522013-06-07 19:36:01 +01002241 startVoice();
2242 }
2243
2244 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002245 try {
2246 final SearchManager searchManager =
2247 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2248 ComponentName activityName = searchManager.getGlobalSearchActivity();
2249 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002250 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002251 if (activityName != null) {
2252 intent.setPackage(activityName.getPackageName());
2253 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002254 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002255 } catch (ActivityNotFoundException e) {
2256 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002257 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002258 startActivitySafely(null, intent, "onClickVoiceButton");
2259 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002260 }
2261
2262 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002263 * Event handler for the "grid" button that appears on the home screen, which
2264 * enters all apps mode.
2265 *
2266 * @param v The view that was clicked.
2267 */
2268 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002269 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002270 }
2271
2272 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002273 // Provide the same haptic feedback that the system offers for virtual keys.
2274 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002275 }
2276
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002277 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002278 if (!DISABLE_MARKET_BUTTON) {
2279 if (mAppMarketIntent != null) {
2280 startActivitySafely(v, mAppMarketIntent, "app market");
2281 } else {
2282 Log.e(TAG, "Invalid app market intent.");
2283 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002284 }
2285 }
2286
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002287 /**
2288 * Called when the user stops interacting with the launcher.
2289 * This implies that the user is now on the homescreen and is not doing housekeeping.
2290 */
2291 protected void onInteractionEnd() {}
2292
2293 /**
2294 * Called when the user starts interacting with the launcher.
2295 * The possible interactions are:
2296 * - open all apps
2297 * - reorder an app shortcut, or a widget
2298 * - open the overview mode.
2299 * This is a good time to stop doing things that only make sense
2300 * when the user is on the homescreen and not doing housekeeping.
2301 */
2302 protected void onInteractionBegin() {}
2303
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002304 void startApplicationDetailsActivity(ComponentName componentName) {
2305 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002306 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2307 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002308 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002309 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002310 }
2311
Michael Jurka1e2f4652013-07-08 18:03:46 -07002312 // returns true if the activity was started
2313 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002314 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002315 // System applications cannot be installed. For now, show a toast explaining that.
2316 // We may give them the option of disabling apps this way.
2317 int messageId = R.string.uninstall_system_app_text;
2318 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002319 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002320 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002321 String packageName = componentName.getPackageName();
2322 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002323 Intent intent = new Intent(
2324 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002325 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2326 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002327 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002328 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002329 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002330 }
2331
Michael Jurka86a720e2012-05-09 11:23:23 -07002332 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002333 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002334
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002335 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002336 // Only launch using the new animation if the shortcut has not opted out (this is a
2337 // private contract between launcher and may be ignored in the future).
2338 boolean useLaunchAnimation = (v != null) &&
2339 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2340 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002341 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2342 v.getMeasuredWidth(), v.getMeasuredHeight());
2343
2344 startActivity(intent, opts.toBundle());
2345 } else {
2346 startActivity(intent);
2347 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002348 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002349 } catch (SecurityException e) {
2350 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002351 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002352 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002353 "or use the exported attribute for this activity. "
2354 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002355 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002356 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002357 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002358
Michael Jurka86a720e2012-05-09 11:23:23 -07002359 boolean startActivitySafely(View v, Intent intent, Object tag) {
2360 boolean success = false;
2361 try {
2362 success = startActivity(v, intent, tag);
2363 } catch (ActivityNotFoundException e) {
2364 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2365 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2366 }
2367 return success;
2368 }
2369
Adam Cohena9cf38f2011-05-02 15:36:58 -07002370 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002371 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002372 Folder openFolder = mWorkspace.getFolderForTag(info);
2373
2374 // If the folder info reports that the associated folder is open, then verify that
2375 // it is actually opened. There have been a few instances where this gets out of sync.
2376 if (info.opened && openFolder == null) {
2377 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002378 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002379 info.opened = false;
2380 }
2381
Adam Cohenfb91f302012-06-11 15:45:18 -07002382 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 // Close any open folder
2384 closeFolder();
2385 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002386 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 } else {
2388 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002389 int folderScreen;
2390 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002391 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002392 // .. and close it
2393 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002394 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002395 // Close any folder open on the current screen
2396 closeFolder();
2397 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002398 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002399 }
2400 }
2401 }
2402 }
2403
Adam Cohen268c4752012-06-06 17:47:33 -07002404 /**
2405 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2406 * in the DragLayer in the exact absolute location of the original FolderIcon.
2407 */
2408 private void copyFolderIconToImage(FolderIcon fi) {
2409 final int width = fi.getMeasuredWidth();
2410 final int height = fi.getMeasuredHeight();
2411
2412 // Lazy load ImageView, Bitmap and Canvas
2413 if (mFolderIconImageView == null) {
2414 mFolderIconImageView = new ImageView(this);
2415 }
2416 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2417 mFolderIconBitmap.getHeight() != height) {
2418 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2419 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2420 }
2421
2422 DragLayer.LayoutParams lp;
2423 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2424 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2425 } else {
2426 lp = new DragLayer.LayoutParams(width, height);
2427 }
2428
Adam Cohen307fe232012-08-16 17:55:58 -07002429 // The layout from which the folder is being opened may be scaled, adjust the starting
2430 // view size by this scale factor.
2431 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002432 lp.customPosition = true;
2433 lp.x = mRectForFolderAnimation.left;
2434 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002435 lp.width = (int) (scale * width);
2436 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002437
2438 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2439 fi.draw(mFolderIconCanvas);
2440 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002441 if (fi.getFolder() != null) {
2442 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2443 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002444 }
Adam Cohen268c4752012-06-06 17:47:33 -07002445 // Just in case this image view is still in the drag layer from a previous animation,
2446 // we remove it and re-add it.
2447 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2448 mDragLayer.removeView(mFolderIconImageView);
2449 }
2450 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002451 if (fi.getFolder() != null) {
2452 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002453 }
Adam Cohen268c4752012-06-06 17:47:33 -07002454 }
2455
Adam Cohen2801caf2011-05-13 20:57:39 -07002456 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002457 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002458 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2459 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2460 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2461
Adam Cohenc51934b2011-07-26 21:07:43 -07002462 FolderInfo info = (FolderInfo) fi.getTag();
2463 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2464 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002465 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2466 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002467 }
2468
Adam Cohen268c4752012-06-06 17:47:33 -07002469 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2470 copyFolderIconToImage(fi);
2471 fi.setVisibility(View.INVISIBLE);
2472
Michael Jurka2ecf9952012-06-18 12:52:28 -07002473 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002474 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002475 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2476 oa.start();
2477 }
2478
Adam Cohen268c4752012-06-06 17:47:33 -07002479 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002480 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002481 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2482 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2483 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2484
Adam Cohen268c4752012-06-06 17:47:33 -07002485 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002486
Adam Cohen268c4752012-06-06 17:47:33 -07002487 // We remove and re-draw the FolderIcon in-case it has changed
2488 mDragLayer.removeView(mFolderIconImageView);
2489 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002490 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002491 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002492 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002493 oa.addListener(new AnimatorListenerAdapter() {
2494 @Override
2495 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002496 if (cl != null) {
2497 cl.clearFolderLeaveBehind();
2498 // Remove the ImageView copy of the FolderIcon and make the original visible.
2499 mDragLayer.removeView(mFolderIconImageView);
2500 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002501 }
2502 }
2503 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002504 oa.start();
2505 }
2506
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002507 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002508 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002509 * is animated relative to the specified View. If the View is null, no animation
2510 * is played.
2511 *
2512 * @param folderInfo The FolderInfo describing the folder to open.
2513 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002514 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002515 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002517
Adam Cohena9cf38f2011-05-02 15:36:58 -07002518 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002519
Adam Cohen4554ee12011-08-03 16:13:21 -07002520 // Just verify that the folder hasn't already been added to the DragLayer.
2521 // There was a one-off crash where the folder had a parent already.
2522 if (folder.getParent() == null) {
2523 mDragLayer.addView(folder);
2524 mDragController.addDropTarget((DropTarget) folder);
2525 } else {
2526 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2527 folder.getParent() + ").");
2528 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002529 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002530 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002531
2532 // Notify the accessibility manager that this folder "window" has appeared and occluded
2533 // the workspace items
2534 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2535 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002536 }
2537
2538 public void closeFolder() {
2539 Folder folder = mWorkspace.getOpenFolder();
2540 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002541 if (folder.isEditingName()) {
2542 folder.dismissEditingName();
2543 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002544 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002545
2546 // Dismiss the folder cling
2547 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002548 }
2549 }
2550
2551 void closeFolder(Folder folder) {
2552 folder.getInfo().opened = false;
2553
2554 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2555 if (parent != null) {
2556 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2557 shrinkAndFadeInFolderIcon(fi);
2558 }
2559 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002560
2561 // Notify the accessibility manager that this folder "window" has disappeard and no
2562 // longer occludeds the workspace items
2563 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 }
2565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002567 if (!isDraggingEnabled()) return false;
2568 if (isWorkspaceLocked()) return false;
2569 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002570
Adam Cohen1697b792013-09-17 19:08:21 -07002571 if (v instanceof Workspace) {
2572 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002573 if (mWorkspace.enterOverviewMode()) {
2574 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2575 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2576 return true;
2577 } else {
2578 return false;
2579 }
Adam Cohen1697b792013-09-17 19:08:21 -07002580 }
Adam Cohen1697b792013-09-17 19:08:21 -07002581 }
2582
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002583 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002584 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002585 }
2586
Michael Jurka0280c3b2010-09-17 15:00:07 -07002587 resetAddInfo();
2588 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002589 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002590 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 return true;
2592 }
2593
Winson Chung3d503fb2011-07-13 17:25:49 -07002594 // The hotseat touch handling does not go through Workspace, and we always allow long press
2595 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002596 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002597 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2598 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002599 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002600 // User long pressed on empty space
2601 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2602 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2603 // Disabling reordering until we sort out some issues.
2604 if (mWorkspace.isInOverviewMode()) {
2605 mWorkspace.startReordering(v);
2606 } else {
2607 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002608 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002609 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002610 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002611 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002612 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002613 }
2614 }
2615 }
2616 return true;
2617 }
2618
Winson Chung3d503fb2011-07-13 17:25:49 -07002619 boolean isHotseatLayout(View layout) {
2620 return mHotseat != null && layout != null &&
2621 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2622 }
2623 Hotseat getHotseat() {
2624 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002625 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002626 View getOverviewPanel() {
2627 return mOverviewPanel;
2628 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002629 SearchDropTargetBar getSearchBar() {
2630 return mSearchDropTargetBar;
2631 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002632
Winson Chung3d503fb2011-07-13 17:25:49 -07002633 /**
2634 * Returns the CellLayout of the specified container at the specified screen.
2635 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002636 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002637 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2638 if (mHotseat != null) {
2639 return mHotseat.getLayout();
2640 } else {
2641 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002642 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002643 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002644 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002645 }
2646 }
2647
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002648 Workspace getWorkspace() {
2649 return mWorkspace;
2650 }
2651
Daniel Sandler843e8602010-06-07 14:59:01 -04002652 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002653 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002654 }
2655
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002656 /**
2657 * Helper method for the cameraZoomIn/cameraZoomOut animations
2658 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002659 * @param scaleFactor The scale factor used for the zoom
2660 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002661 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002662 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002663 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002664 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002665
Craig Mautner360310b2012-10-26 15:13:08 -07002666 private void setWorkspaceBackground(boolean workspace) {
2667 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002668 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002669 }
2670
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002671 void updateWallpaperVisibility(boolean visible) {
2672 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2673 int curflags = getWindow().getAttributes().flags
2674 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2675 if (wpflags != curflags) {
2676 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2677 }
Craig Mautner360310b2012-10-26 15:13:08 -07002678 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002679 }
2680
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002681 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2682 if (v instanceof LauncherTransitionable) {
2683 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2684 }
2685 }
2686
Michael Jurkabed61d22012-02-14 22:51:29 -08002687 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2688 if (v instanceof LauncherTransitionable) {
2689 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2690 }
Winson Chung70442722012-02-10 15:43:22 -08002691
2692 // Update the workspace transition step as well
2693 dispatchOnLauncherTransitionStep(v, 0f);
2694 }
2695
2696 private void dispatchOnLauncherTransitionStep(View v, float t) {
2697 if (v instanceof LauncherTransitionable) {
2698 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2699 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002700 }
2701
2702 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2703 if (v instanceof LauncherTransitionable) {
2704 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2705 }
Winson Chung70442722012-02-10 15:43:22 -08002706
2707 // Update the workspace transition step as well
2708 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002709 }
2710
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002711 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002712 * Things to test when changing the following seven functions.
2713 * - Home from workspace
2714 * - from center screen
2715 * - from other screens
2716 * - Home from all apps
2717 * - from center screen
2718 * - from other screens
2719 * - Back from all apps
2720 * - from center screen
2721 * - from other screens
2722 * - Launch app from workspace and quit
2723 * - with back
2724 * - with home
2725 * - Launch app from all apps and quit
2726 * - with back
2727 * - with home
2728 * - Go to a screen that's not the default, then all
2729 * apps, and launch and app, and go back
2730 * - with back
2731 * -with home
2732 * - On workspace, long press power and go back
2733 * - with back
2734 * - with home
2735 * - On all apps, long press power and go back
2736 * - with back
2737 * - with home
2738 * - On workspace, power off
2739 * - On all apps, power off
2740 * - Launch an app and turn off the screen while in that app
2741 * - Go back with home key
2742 * - Go back with back key TODO: make this not go to workspace
2743 * - From all apps
2744 * - From workspace
2745 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2746 * - From all apps
2747 * - From the center workspace
2748 * - From another workspace
2749 */
2750
2751 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002752 * Zoom the camera out from the workspace to reveal 'toView'.
2753 * Assumes that the view to show is anchored at either the very top or very bottom
2754 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002755 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002756 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002757 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2758 showAppsCustomizeHelper(animated, springLoaded, contentType);
2759 }
2760 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2761 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002762 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002763 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002764 mStateAnimation.cancel();
2765 mStateAnimation = null;
2766 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002767 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002768
Winson Chungf0ea4d32011-06-06 14:27:16 -07002769 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2770 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2771 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002772 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002773 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002774 final int startDelay =
2775 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002776
Michael Jurkab3e22d92011-10-31 15:58:33 -07002777 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002778
Michael Jurkad74c9842011-07-10 12:44:21 -07002779 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002780 Animator workspaceAnim =
2781 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002782 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2783 // Set the content type for the all apps space
2784 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2785 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002786
2787 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002788 toView.setScaleX(scale);
2789 toView.setScaleY(scale);
2790 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2791 scaleAnim.
2792 scaleX(1f).scaleY(1f).
2793 setDuration(duration).
2794 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002795
Winson Chungf0ea4d32011-06-06 14:27:16 -07002796 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002797 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002798 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002799 .ofFloat(toView, "alpha", 0f, 1f)
2800 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002801 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002802 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2803 @Override
2804 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002805 if (animation == null) {
2806 throw new RuntimeException("animation is null");
2807 }
Winson Chung70442722012-02-10 15:43:22 -08002808 float t = (Float) animation.getAnimatedValue();
2809 dispatchOnLauncherTransitionStep(fromView, t);
2810 dispatchOnLauncherTransitionStep(toView, t);
2811 }
2812 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002813
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002814 // toView should appear right at the end of the workspace shrink
2815 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002816 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002817 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002818 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002819
2820 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002821 boolean animationCancelled = false;
2822
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002823 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002824 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002825 // Prepare the position
2826 toView.setTranslationX(0.0f);
2827 toView.setTranslationY(0.0f);
2828 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002829 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002830 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002831 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002832 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002833 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2834 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002835
Winson Chungc7d2b602012-05-16 17:02:20 -07002836 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002837 if (mSearchDropTargetBar != null) {
2838 mSearchDropTargetBar.hideSearchBar(false);
2839 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002840 }
2841
Adam Cohencff6af82011-09-13 14:51:53 -07002842 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002843 public void onAnimationCancel(Animator animation) {
2844 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002845 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002846 });
2847
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002848 if (workspaceAnim != null) {
2849 mStateAnimation.play(workspaceAnim);
2850 }
Michael Jurka1899a362011-11-03 13:50:45 -07002851
2852 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002854 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2855 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002856
2857 // If any of the objects being animated haven't been measured/laid out
2858 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002859 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002860 (mWorkspace.getMeasuredWidth() == 0) ||
2861 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002862 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002863 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002864
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002865 final AnimatorSet stateAnimation = mStateAnimation;
2866 final Runnable startAnimRunnable = new Runnable() {
2867 public void run() {
2868 // Check that mStateAnimation hasn't changed while
2869 // we waited for a layout/draw pass
2870 if (mStateAnimation != stateAnimation)
2871 return;
2872 setPivotsForZoom(toView, scale);
2873 dispatchOnLauncherTransitionStart(fromView, animated, false);
2874 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002875 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002876 }
2877 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002878 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002879 final ViewTreeObserver observer = toView.getViewTreeObserver();
2880 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2881 public void onGlobalLayout() {
2882 startAnimRunnable.run();
2883 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2884 }
2885 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002886 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002887 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002888 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002889 } else {
2890 toView.setTranslationX(0.0f);
2891 toView.setTranslationY(0.0f);
2892 toView.setScaleX(1.0f);
2893 toView.setScaleY(1.0f);
2894 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002895 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002896
Daniel Sandlere4f98912013-06-25 15:13:26 -04002897 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002898 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002899 if (mSearchDropTargetBar != null) {
2900 mSearchDropTargetBar.hideSearchBar(false);
2901 }
Michael Jurkaabded662011-03-04 12:06:57 -08002902 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002903 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002904 dispatchOnLauncherTransitionStart(fromView, animated, false);
2905 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002906 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002907 dispatchOnLauncherTransitionStart(toView, animated, false);
2908 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002909 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002910 }
2911
2912 /**
2913 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002914 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002915 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002916 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002917 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2918 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002919
Michael Jurkab3e22d92011-10-31 15:58:33 -07002920 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002921 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002922 mStateAnimation.cancel();
2923 mStateAnimation = null;
2924 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002925 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002926
Winson Chungf0ea4d32011-06-06 14:27:16 -07002927 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002928 final int fadeOutDuration =
2929 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002930 final float scaleFactor = (float)
2931 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2932 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002933 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002934 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002935 if (toState == State.WORKSPACE) {
2936 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2937 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002938 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002939 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2940 workspaceAnim = mWorkspace.getChangeStateAnimation(
2941 Workspace.State.SPRING_LOADED, animated);
2942 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002943
Michael Jurkab3e22d92011-10-31 15:58:33 -07002944 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002945 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002946 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002947 final LauncherViewPropertyAnimator scaleAnim =
2948 new LauncherViewPropertyAnimator(fromView);
2949 scaleAnim.
2950 scaleX(scaleFactor).scaleY(scaleFactor).
2951 setDuration(duration).
2952 setInterpolator(new Workspace.ZoomInInterpolator());
2953
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002954 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002955 .ofFloat(fromView, "alpha", 1f, 0f)
2956 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002957 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002958 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2959 @Override
2960 public void onAnimationUpdate(ValueAnimator animation) {
2961 float t = 1f - (Float) animation.getAnimatedValue();
2962 dispatchOnLauncherTransitionStep(fromView, t);
2963 dispatchOnLauncherTransitionStep(toView, t);
2964 }
2965 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002966
Michael Jurka2ecf9952012-06-18 12:52:28 -07002967 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002968
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002969 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2970 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002971 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002972
2973 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002974 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002975 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002976 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002977 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2978 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002979 if (onCompleteRunnable != null) {
2980 onCompleteRunnable.run();
2981 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002982 mAppsCustomizeContent.updateCurrentPageScroll();
2983 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002984 }
2985 });
2986
Winson Chungf0ea4d32011-06-06 14:27:16 -07002987 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002988 if (workspaceAnim != null) {
2989 mStateAnimation.play(workspaceAnim);
2990 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002991 dispatchOnLauncherTransitionStart(fromView, animated, true);
2992 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002993 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002994 } else {
2995 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002996 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002997 dispatchOnLauncherTransitionStart(fromView, animated, true);
2998 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002999 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003000 dispatchOnLauncherTransitionStart(toView, animated, true);
3001 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003002 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003003 }
3004
Michael Jurkae326f182011-11-21 14:05:46 -08003005 @Override
3006 public void onTrimMemory(int level) {
3007 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003008 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003009 mAppsCustomizeTabHost.onTrimMemory();
3010 }
3011 }
3012
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003013 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003014 showWorkspace(animated, null);
3015 }
3016
3017 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003018 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003019 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003020 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003021 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003022
Winson Chungc7d2b602012-05-16 17:02:20 -07003023 // Show the search bar (only animate if we were showing the drop target bar in spring
3024 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003025 if (mSearchDropTargetBar != null) {
3026 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3027 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003028
Michael Jurkab3e22d92011-10-31 15:58:33 -07003029 // Set focus to the AppsCustomize button
3030 if (mAllAppsButton != null) {
3031 mAllAppsButton.requestFocus();
3032 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003033 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003034
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003035 // Change the state *after* we've called all the transition code
3036 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003037
Winson Chung5fb63472011-02-02 17:03:37 -08003038 // Resume the auto-advance of widgets
3039 mUserPresent = true;
3040 updateRunning();
3041
alanv1d4fde62012-10-17 13:15:47 -07003042 // Send an accessibility event to announce the context change
3043 getWindow().getDecorView()
3044 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003045
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003046 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003047 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003048 }
3049
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003050 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003051 }
3052
Winson Chungc58497e2013-09-03 17:48:37 -07003053 void showAllApps(boolean animated,
3054 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003055 if (mState != State.WORKSPACE) return;
3056
Winson Chungc58497e2013-09-03 17:48:37 -07003057 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003058 mAppsCustomizeTabHost.requestFocus();
3059
Michael Jurkab3e22d92011-10-31 15:58:33 -07003060 // Change the state *after* we've called all the transition code
3061 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003062 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003063
3064 // Pause the auto-advance of widgets until we are out of AllApps
3065 mUserPresent = false;
3066 updateRunning();
3067 closeFolder();
3068
3069 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003070 getWindow().getDecorView()
3071 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003072 }
3073
Adam Cohen7777d962011-08-18 18:58:38 -07003074 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003075 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003076 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003077 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003078 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003079 }
Adam Cohen7777d962011-08-18 18:58:38 -07003080
Adam Cohened66b2b2012-01-23 17:28:51 -08003081 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3082 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003083 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3084
Winson Chunge7a03942011-08-05 15:05:12 -07003085 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003086 @Override
3087 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003088 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003089 // Before we show workspace, hide all apps again because
3090 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3091 // clean up our state transition functions
3092 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003093 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003094 } else {
3095 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003096 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003097 }
3098 }, (extendedDelay ?
3099 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3100 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3101 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003102
Michael Jurkad3ef3062010-11-23 16:23:58 -08003103 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003104 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003105 final boolean animated = true;
3106 final boolean springLoaded = true;
3107 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003108 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003109 }
3110 // Otherwise, we are not in spring loaded mode, so don't do anything.
3111 }
3112
Michael Jurkab3e22d92011-10-31 15:58:33 -07003113 void lockAllApps() {
3114 // TODO
3115 }
3116
3117 void unlockAllApps() {
3118 // TODO
3119 }
3120
Winson Chungf0ea4d32011-06-06 14:27:16 -07003121 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003122 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003123 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003124 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003125 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003126 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003127 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003128 int duration = 0;
3129 if (mSearchDropTargetBar != null) {
3130 duration = mSearchDropTargetBar.getTransitionInDuration();
3131 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003132 mHotseat.animate().alpha(1f).setDuration(duration);
3133 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003134 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003135 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003136 }
3137 }
3138 }
3139
3140 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003142 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003143 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003144 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003145 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003146 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003147 int duration = 0;
3148 if (mSearchDropTargetBar != null) {
3149 duration = mSearchDropTargetBar.getTransitionOutDuration();
3150 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003151 mHotseat.animate().alpha(0f).setDuration(duration);
3152 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003154 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003155 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003156 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003157 }
3158
Patrick Dubroy5f445422011-02-18 14:35:21 -08003159 /**
3160 * Add an item from all apps or customize onto the given workspace screen.
3161 * If layout is null, add to the current screen.
3162 */
3163 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003164 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003165 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003166 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003167 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003168
Winson Chungdff8ebb2011-09-08 17:25:31 -07003169 /** Maps the current orientation to an index for referencing orientation correct global icons */
3170 private int getCurrentOrientationIndexForGlobalIcons() {
3171 // default - 0, landscape - 1
3172 switch (getResources().getConfiguration().orientation) {
3173 case Configuration.ORIENTATION_LANDSCAPE:
3174 return 1;
3175 default:
3176 return 0;
3177 }
3178 }
3179
Michael Jurkaae65ee32012-04-30 11:45:54 -07003180 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003181 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003182 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003183 // Look for the toolbar icon specified in the activity meta-data
3184 Bundle metaData = packageManager.getActivityInfo(
3185 activityName, PackageManager.GET_META_DATA).metaData;
3186 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003187 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003188 if (iconResId != 0) {
3189 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003190 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003191 }
3192 }
3193 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003194 // This can happen if the activity defines an invalid drawable
3195 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3196 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003197 } catch (Resources.NotFoundException nfe) {
3198 // This can happen if the activity defines an invalid drawable
3199 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3200 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003201 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003202 return null;
3203 }
3204
3205 // if successful in getting icon, return it; otherwise, set button to use default drawable
3206 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003207 int buttonId, ComponentName activityName, int fallbackDrawableId,
3208 String toolbarResourceName) {
3209 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003210 Resources r = getResources();
3211 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3212 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003213
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003214 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003215 // If we were unable to find the icon via the meta-data, use a generic one
3216 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003217 toolbarIcon = r.getDrawable(fallbackDrawableId);
3218 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003219 if (button != null) {
3220 button.setCompoundDrawables(toolbarIcon, null, null, null);
3221 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003222 return null;
3223 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003224 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003225 if (button != null) {
3226 button.setCompoundDrawables(toolbarIcon, null, null, null);
3227 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003228 return toolbarIcon.getConstantState();
3229 }
3230 }
3231
3232 // if successful in getting icon, return it; otherwise, set button to use default drawable
3233 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003234 int buttonId, ComponentName activityName, int fallbackDrawableId,
3235 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003236 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003237 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003238
Michael Jurka19e0fc52011-07-22 18:00:21 -07003239 if (button != null) {
3240 // If we were unable to find the icon via the meta-data, use a
3241 // generic one
3242 if (toolbarIcon == null) {
3243 button.setImageResource(fallbackDrawableId);
3244 } else {
3245 button.setImageDrawable(toolbarIcon);
3246 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003247 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003248
3249 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3250
Michael Jurka0423dcf2010-10-05 14:56:18 -07003251 }
3252
Winson Chung1b884092012-06-08 17:13:02 -07003253 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003254 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003255 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003256 }
3257
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003258 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003259 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003260 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003261 }
3262
Winson Chungbb185bd2011-11-21 12:31:42 -08003263 private void invalidatePressedFocusedStates(View container, View button) {
3264 if (container instanceof HolographicLinearLayout) {
3265 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3266 layout.invalidatePressedFocusedStates();
3267 } else if (button instanceof HolographicImageView) {
3268 HolographicImageView view = (HolographicImageView) button;
3269 view.invalidatePressedFocusedStates();
3270 }
3271 }
3272
Cristina Stancu476493b2013-08-07 17:20:14 +01003273 public View getQsbBar() {
3274 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003275 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3276 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003277 }
3278 return mQsbBar;
3279 }
3280
3281 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003282 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003283 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003284 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003285 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003286
Winson Chung1cad91e2011-05-25 17:41:01 -07003287 final SearchManager searchManager =
3288 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3289 ComponentName activityName = searchManager.getGlobalSearchActivity();
3290 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003291 int coi = getCurrentOrientationIndexForGlobalIcons();
3292 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003293 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3294 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3295 if (sGlobalSearchIcon[coi] == null) {
3296 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3297 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3298 TOOLBAR_ICON_METADATA_NAME);
3299 }
3300
Winson Chungc51db6a2011-10-05 11:44:49 -07003301 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3302 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003303 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003304 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003305 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003306 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003307 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3308 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003309 if (searchButton != null) searchButton.setVisibility(View.GONE);
3310 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003311 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003312 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003313 }
3314 }
3315
Cristina Stancu476493b2013-08-07 17:20:14 +01003316 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003317 final View searchButtonContainer = findViewById(R.id.search_button_container);
3318 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003319 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003320 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003321 }
3322
Cristina Stancu476493b2013-08-07 17:20:14 +01003323 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003324 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003325 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003326
Winson Chungc51db6a2011-10-05 11:44:49 -07003327 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003328 final SearchManager searchManager =
3329 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3330 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3331
3332 ComponentName activityName = null;
3333 if (globalSearchActivity != null) {
3334 // Check if the global search activity handles voice search
3335 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3336 intent.setPackage(globalSearchActivity.getPackageName());
3337 activityName = intent.resolveActivity(getPackageManager());
3338 }
3339
3340 if (activityName == null) {
3341 // Fallback: check if an activity other than the global search activity
3342 // resolves this
3343 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3344 activityName = intent.resolveActivity(getPackageManager());
3345 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003346 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003347 int coi = getCurrentOrientationIndexForGlobalIcons();
3348 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003349 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3350 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3351 if (sVoiceSearchIcon[coi] == null) {
3352 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3353 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3354 TOOLBAR_ICON_METADATA_NAME);
3355 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003356 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003357 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003358 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003359 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003360 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003361 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003362 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003363 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003364 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003365 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003366 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003367 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003368
Cristina Stancu476493b2013-08-07 17:20:14 +01003369 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003370 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3371 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003372 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003373 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003374 }
3375
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003376 public void setVoiceButtonProxyVisible(boolean visible) {
3377 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3378 if (voiceButtonProxy != null) {
3379 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3380 }
3381 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003382 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003383 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003384 */
3385 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003386 if (!DISABLE_MARKET_BUTTON) {
3387 final View marketButton = findViewById(R.id.market_button);
3388 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3389 // Find the app market activity by resolving an intent.
3390 // (If multiple app markets are installed, it will return the ResolverActivity.)
3391 ComponentName activityName = intent.resolveActivity(getPackageManager());
3392 if (activityName != null) {
3393 int coi = getCurrentOrientationIndexForGlobalIcons();
3394 mAppMarketIntent = intent;
3395 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3396 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3397 TOOLBAR_ICON_METADATA_NAME);
3398 marketButton.setVisibility(View.VISIBLE);
3399 } else {
3400 // We should hide and disable the view so that we don't try and restore the visibility
3401 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3402 marketButton.setVisibility(View.GONE);
3403 marketButton.setEnabled(false);
3404 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003405 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003406 }
3407
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003408 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003409 if (!DISABLE_MARKET_BUTTON) {
3410 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3411 Resources r = getResources();
3412 Drawable marketIconDrawable = d.newDrawable(r);
3413 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3414 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3415 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003416
Winson Chungd64a6662013-09-30 11:06:59 -07003417 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3418 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003419 }
3420
Michael Jurkad7c28052012-04-27 15:43:36 -07003421 @Override
3422 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003423 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003424 final List<CharSequence> text = event.getText();
3425 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003426 // Populate event with a fake title based on the current state.
3427 if (mState == State.APPS_CUSTOMIZE) {
3428 text.add(getString(R.string.all_apps_button_label));
3429 } else {
3430 text.add(getString(R.string.all_apps_home_button_label));
3431 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003432 return result;
3433 }
3434
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003435 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003436 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003437 */
3438 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3439 @Override
3440 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003441 closeSystemDialogs();
3442 }
3443 }
3444
3445 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003446 * Receives notifications whenever the appwidgets are reset.
3447 */
3448 private class AppWidgetResetObserver extends ContentObserver {
3449 public AppWidgetResetObserver() {
3450 super(new Handler());
3451 }
3452
3453 @Override
3454 public void onChange(boolean selfChange) {
3455 onAppWidgetReset();
3456 }
3457 }
3458
3459 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003460 * If the activity is currently paused, signal that we need to run the passed Runnable
3461 * in onResume.
3462 *
3463 * This needs to be called from incoming places where resources might have been loaded
3464 * while we are paused. That is becaues the Configuration might be wrong
3465 * when we're not running, and if it comes back to what it was when we
3466 * were paused, we are not restarted.
3467 *
3468 * Implementation of the method from LauncherModel.Callbacks.
3469 *
3470 * @return true if we are currently paused. The caller might be able to
3471 * skip some work in that case since we will come back again.
3472 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003473 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003474 if (mPaused) {
3475 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003476 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003477 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003478 }
3479 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003480 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003481 return true;
3482 } else {
3483 return false;
3484 }
3485 }
3486
Michael Jurkac402cd92013-05-20 15:49:32 +02003487 private boolean waitUntilResume(Runnable run) {
3488 return waitUntilResume(run, false);
3489 }
3490
Michael Jurka1e2f4652013-07-08 18:03:46 -07003491 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003492 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003493 }
3494
Michael Jurka7607c2f2013-04-03 14:33:19 -07003495 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003496 * If the activity is currently paused, signal that we need to re-run the loader
3497 * in onResume.
3498 *
3499 * This needs to be called from incoming places where resources might have been loaded
3500 * while we are paused. That is becaues the Configuration might be wrong
3501 * when we're not running, and if it comes back to what it was when we
3502 * were paused, we are not restarted.
3503 *
3504 * Implementation of the method from LauncherModel.Callbacks.
3505 *
3506 * @return true if we are currently paused. The caller might be able to
3507 * skip some work in that case since we will come back again.
3508 */
3509 public boolean setLoadOnResume() {
3510 if (mPaused) {
3511 Log.i(TAG, "setLoadOnResume");
3512 mOnResumeNeedsLoad = true;
3513 return true;
3514 } else {
3515 return false;
3516 }
3517 }
3518
3519 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003520 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003521 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003522 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003523 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003524 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003525 } else {
3526 return SCREEN_COUNT / 2;
3527 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003528 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003529
Joe Onorato9c1289c2009-08-17 11:03:03 -04003530 /**
3531 * Refreshes the shortcuts shown on the workspace.
3532 *
3533 * Implementation of the method from LauncherModel.Callbacks.
3534 */
3535 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003536 // If we're starting binding all over again, clear any bind calls we'd postponed in
3537 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3538 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003539 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003540
Winson Chungd64d1762013-08-20 14:37:16 -07003541 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003542 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003543 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003544
Michael Jurka05bf644e2011-11-30 20:28:53 -08003545 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003546 if (mHotseat != null) {
3547 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003548 }
3549 }
3550
Adam Cohendcd297f2013-06-18 13:13:40 -07003551 @Override
3552 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003553 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003554
Adam Cohen5084cba2013-09-03 12:01:16 -07003555 // If there are no screens, we need to have an empty screen
3556 if (orderedScreenIds.size() == 0) {
3557 mWorkspace.addExtraEmptyScreen();
3558 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003559
3560 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003561 // setCurrentPage() so ensure that all pages are added before calling this).
3562 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003563 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3564 mWorkspace.createCustomContentPage();
3565 }
Winson Chung64359a52013-07-08 17:17:08 -07003566 }
3567
3568 @Override
3569 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003570 int count = orderedScreenIds.size();
3571 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003572 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003573 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003574 }
3575
Adam Cohen39a06042013-07-19 14:30:12 -07003576 private boolean shouldShowWeightWatcher() {
3577 String spKey = LauncherAppState.getSharedPreferencesKey();
3578 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003579 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003580
3581 return show;
3582 }
3583
Adam Cohen4caf2982013-08-20 18:54:31 -07003584 private boolean emailSent() {
3585 String spKey = LauncherAppState.getSharedPreferencesKey();
3586 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3587 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3588 return show;
3589 }
3590
3591 private void setEmailSent(boolean sent) {
3592 String spKey = LauncherAppState.getSharedPreferencesKey();
3593 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3594
3595 SharedPreferences.Editor editor = sp.edit();
3596 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3597 editor.commit();
3598 }
3599
Adam Cohen39a06042013-07-19 14:30:12 -07003600 private void toggleShowWeightWatcher() {
3601 String spKey = LauncherAppState.getSharedPreferencesKey();
3602 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3603 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3604
3605 show = !show;
3606
3607 SharedPreferences.Editor editor = sp.edit();
3608 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3609 editor.commit();
3610
3611 if (mWeightWatcher != null) {
3612 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3613 }
3614 }
3615
Winson Chungd64d1762013-08-20 14:37:16 -07003616 public void bindAppsAdded(final ArrayList<Long> newScreens,
3617 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003618 final ArrayList<ItemInfo> addAnimated,
3619 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003620 Runnable r = new Runnable() {
3621 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003622 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003623 }
3624 };
3625 if (waitUntilResume(r)) {
3626 return;
3627 }
3628
Winson Chungd64d1762013-08-20 14:37:16 -07003629 // Add the new screens
3630 bindAddScreens(newScreens);
3631
3632 // We add the items without animation on non-visible pages, and with
3633 // animations on the new page (which we will try and snap to).
3634 if (!addNotAnimated.isEmpty()) {
3635 bindItems(addNotAnimated, 0,
3636 addNotAnimated.size(), false);
3637 }
3638 if (!addAnimated.isEmpty()) {
3639 bindItems(addAnimated, 0,
3640 addAnimated.size(), true);
3641 }
Winson Chungc58497e2013-09-03 17:48:37 -07003642
3643 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3644 addedApps != null && mAppsCustomizeContent != null) {
3645 mAppsCustomizeContent.addApps(addedApps);
3646 }
Winson Chungd64d1762013-08-20 14:37:16 -07003647 }
3648
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003649 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003650 * Bind the items start-end from the list.
3651 *
3652 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003653 */
Winson Chung64359a52013-07-08 17:17:08 -07003654 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3655 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003656 Runnable r = new Runnable() {
3657 public void run() {
3658 bindItems(shortcuts, start, end, forceAnimateIcons);
3659 }
3660 };
3661 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003662 return;
3663 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003664
Winson Chungf0c6ae02012-03-21 16:10:31 -07003665 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003666 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3667 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003668 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003669 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003670 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003671 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003672 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003673
3674 // Short circuit if we are loading dock items for a configuration which has no dock
3675 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3676 mHotseat == null) {
3677 continue;
3678 }
3679
Joe Onorato9c1289c2009-08-17 11:03:03 -04003680 switch (item.itemType) {
3681 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3682 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003683 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003684 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003685
Winson Chung64359a52013-07-08 17:17:08 -07003686 /*
3687 * TODO: FIX collision case
3688 */
Winson Chungce376632013-07-11 16:12:41 -07003689 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3690 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3691 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3692 throw new RuntimeException("OCCUPIED");
3693 }
Winson Chung64359a52013-07-08 17:17:08 -07003694 }
3695
Adam Cohendcd297f2013-06-18 13:13:40 -07003696 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3697 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003698 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003699 // Animate all the applications up now
3700 shortcut.setAlpha(0f);
3701 shortcut.setScaleX(0f);
3702 shortcut.setScaleY(0f);
3703 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003704 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003705 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003706 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003707 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003708 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003709 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003710 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003711 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3712 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003713 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003714 default:
3715 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003716 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003717 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003718
Winson Chung997a9232013-07-24 15:33:46 -07003719 if (animateIcons) {
3720 // Animate to the correct page
3721 if (newShortcutsScreenId > -1) {
3722 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003723 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003724 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003725 // We post the animation slightly delayed to prevent slowdowns
3726 // when we are loading right after we return to launcher.
3727 mWorkspace.postDelayed(new Runnable() {
3728 public void run() {
3729 mWorkspace.snapToPage(newScreenIndex);
3730 mWorkspace.postDelayed(new Runnable() {
3731 public void run() {
3732 anim.playTogether(bounceAnims);
3733 anim.start();
3734 }
3735 }, NEW_APPS_ANIMATION_DELAY);
3736 }
3737 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003738 }
3739 }
Winson Chung64359a52013-07-08 17:17:08 -07003740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003741 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003742 }
3743
Joe Onorato9c1289c2009-08-17 11:03:03 -04003744 /**
3745 * Implementation of the method from LauncherModel.Callbacks.
3746 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003747 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003748 Runnable r = new Runnable() {
3749 public void run() {
3750 bindFolders(folders);
3751 }
3752 };
3753 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003754 return;
3755 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003756 sFolders.clear();
3757 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003759
3760 /**
3761 * Add the views for a widget to the workspace.
3762 *
3763 * Implementation of the method from LauncherModel.Callbacks.
3764 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003765 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003766 Runnable r = new Runnable() {
3767 public void run() {
3768 bindAppWidget(item);
3769 }
3770 };
3771 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003772 return;
3773 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003774
Daniel Sandler843e8602010-06-07 14:59:01 -04003775 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3776 if (DEBUG_WIDGETS) {
3777 Log.d(TAG, "bindAppWidget: " + item);
3778 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003779 final Workspace workspace = mWorkspace;
3780
3781 final int appWidgetId = item.appWidgetId;
3782 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003783 if (DEBUG_WIDGETS) {
3784 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3785 }
3786
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3788
Joe Onorato9c1289c2009-08-17 11:03:03 -04003789 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003790 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003791
Adam Cohendcd297f2013-06-18 13:13:40 -07003792 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003793 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003794 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3795
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 workspace.requestLayout();
3797
Daniel Sandler843e8602010-06-07 14:59:01 -04003798 if (DEBUG_WIDGETS) {
3799 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3800 + (SystemClock.uptimeMillis()-start) + "ms");
3801 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003802 }
3803
Adam Cohen1462de32012-07-24 22:34:36 -07003804 public void onPageBoundSynchronously(int page) {
3805 mSynchronouslyBoundPages.add(page);
3806 }
3807
Joe Onorato9c1289c2009-08-17 11:03:03 -04003808 /**
3809 * Callback saying that there aren't any more items to bind.
3810 *
3811 * Implementation of the method from LauncherModel.Callbacks.
3812 */
Adam Cohene25af792013-06-06 23:08:25 -07003813 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003814 Runnable r = new Runnable() {
3815 public void run() {
3816 finishBindingItems(upgradePath);
3817 }
3818 };
3819 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003820 return;
3821 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003822 if (mSavedState != null) {
3823 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003824 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003825 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003826 mSavedState = null;
3827 }
3828
Adam Cohen1462de32012-07-24 22:34:36 -07003829 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003831 // If we received the result of any pending adds while the loader was running (e.g. the
3832 // widget configuration forced an orientation change), process them now.
3833 for (int i = 0; i < sPendingAddList.size(); i++) {
3834 completeAdd(sPendingAddList.get(i));
3835 }
3836 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837
Winson Chungc51db6a2011-10-05 11:44:49 -07003838 // Update the market app icon as necessary (the other icons will be managed in response to
3839 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003840 if (!DISABLE_MARKET_BUTTON) {
3841 updateAppMarketIcon();
3842 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003843
Winson Chungf0c6ae02012-03-21 16:10:31 -07003844 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003845 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003846 mWorkspace.getUniqueComponents(true, null);
3847 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003848 }
Adam Cohen99894d92013-06-14 11:22:59 -07003849
Adam Cohen66a01fd2013-06-11 12:48:00 -07003850 mWorkspace.post(new Runnable() {
3851 @Override
3852 public void run() {
3853 onFinishBindingItems();
3854 }
3855 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003856 }
3857
Winson Chunga0b7e862013-09-05 16:03:15 -07003858 public boolean isAllAppsButtonRank(int rank) {
3859 if (mHotseat != null) {
3860 return mHotseat.isAllAppsButtonRank(rank);
3861 }
3862 return false;
3863 }
3864
Winson Chunga2413752012-04-03 14:22:34 -07003865 private boolean canRunNewAppsAnimation() {
3866 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3867 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3868 }
3869
Winson Chungc9168342013-06-26 14:54:55 -07003870 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3871 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3872 PropertyValuesHolder.ofFloat("alpha", 1f),
3873 PropertyValuesHolder.ofFloat("scaleX", 1f),
3874 PropertyValuesHolder.ofFloat("scaleY", 1f));
3875 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3876 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3877 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3878 return bounceAnim;
3879 }
3880
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003881 @Override
3882 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003883 boolean searchVisible = updateGlobalSearchIcon();
3884 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003885 if (mSearchDropTargetBar != null) {
3886 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3887 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003888 }
3889
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003890 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003891 * Add the icons for all apps.
3892 *
3893 * Implementation of the method from LauncherModel.Callbacks.
3894 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003895 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003896 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3897 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3898 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3899 getHotseat().addAllAppsFolder(mIconCache, apps,
3900 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3901 }
3902 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003903 }
Winson Chungc58497e2013-09-03 17:48:37 -07003904 } else {
3905 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3906 mAppsCustomizeContent != null) {
3907 mAppsCustomizeContent.setApps(apps);
3908 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003909 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003910 }
3911
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003912 @Override
3913 public boolean shouldShowApp(ResolveInfo app) {
3914 return true;
3915 }
3916
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917 /**
3918 * A package was updated.
3919 *
3920 * Implementation of the method from LauncherModel.Callbacks.
3921 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003922 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003923 Runnable r = new Runnable() {
3924 public void run() {
3925 bindAppsUpdated(apps);
3926 }
3927 };
3928 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003929 return;
3930 }
3931
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003932 if (mWorkspace != null) {
3933 mWorkspace.updateShortcuts(apps);
3934 }
Winson Chungc58497e2013-09-03 17:48:37 -07003935
3936 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3937 mAppsCustomizeContent != null) {
3938 mAppsCustomizeContent.updateApps(apps);
3939 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003940 }
3941
3942 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003943 * A package was uninstalled. We take both the super set of packageNames
3944 * in addition to specific applications to remove, the reason being that
3945 * this can be called when a package is updated as well. In that scenario,
3946 * we only remove specific components from the workspace, where as
3947 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003948 *
3949 * Implementation of the method from LauncherModel.Callbacks.
3950 */
Winson Chung83892cc2013-05-01 16:53:33 -07003951 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003952 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003953 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003954 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003955 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003956 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003957 }
Winson Chungd64d1762013-08-20 14:37:16 -07003958 };
3959 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003960 return;
3961 }
3962
Winson Chung64359a52013-07-08 17:17:08 -07003963 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003964 mWorkspace.removeItemsByPackageName(packageNames);
3965 } else {
3966 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003967 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003968
Winson Chunga1820962011-10-03 16:31:06 -07003969 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003970 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003971
3972 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3973 mAppsCustomizeContent != null) {
3974 mAppsCustomizeContent.removeApps(appInfos);
3975 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003976 }
Joe Onoratobe386092009-11-17 17:32:16 -08003977
3978 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003979 * A number of packages were updated.
3980 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003981 private ArrayList<Object> mWidgetsAndShortcuts;
3982 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003983 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003984 bindPackagesUpdated(mWidgetsAndShortcuts);
3985 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003986 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003987 };
3988
3989 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3990 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3991 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003992 return;
3993 }
3994
Winson Chung64359a52013-07-08 17:17:08 -07003995 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003996 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3997 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003998 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003999 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004000 }
4001
Winson Chung400438b2011-01-16 17:53:48 -08004002 private int mapConfigurationOriActivityInfoOri(int configOri) {
4003 final Display d = getWindowManager().getDefaultDisplay();
4004 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4005 switch (d.getRotation()) {
4006 case Surface.ROTATION_0:
4007 case Surface.ROTATION_180:
4008 // We are currently in the same basic orientation as the natural orientation
4009 naturalOri = configOri;
4010 break;
4011 case Surface.ROTATION_90:
4012 case Surface.ROTATION_270:
4013 // We are currently in the other basic orientation to the natural orientation
4014 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4015 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4016 break;
4017 }
4018
4019 int[] oriMap = {
4020 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4021 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4022 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4023 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4024 };
4025 // Since the map starts at portrait, we need to offset if this device's natural orientation
4026 // is landscape.
4027 int indexOffset = 0;
4028 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4029 indexOffset = 1;
4030 }
4031 return oriMap[(d.getRotation() + indexOffset) % 4];
4032 }
Adam Cohen446e9402011-09-15 18:21:21 -07004033
Winson Chung4b919f82012-05-01 10:44:08 -07004034 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004035 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004036 getResources().getBoolean(R.bool.allow_rotation);
4037 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004038 }
Winson Chung4b919f82012-05-01 10:44:08 -07004039 public void lockScreenOrientation() {
4040 if (isRotationEnabled()) {
4041 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4042 .getConfiguration().orientation));
4043 }
4044 }
4045 public void unlockScreenOrientation(boolean immediate) {
4046 if (isRotationEnabled()) {
4047 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004048 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004049 } else {
4050 mHandler.postDelayed(new Runnable() {
4051 public void run() {
4052 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4053 }
4054 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004055 }
Winson Chung4b919f82012-05-01 10:44:08 -07004056 }
Winson Chung400438b2011-01-16 17:53:48 -08004057 }
4058
Winson Chung82f55532011-08-09 14:14:23 -07004059 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004060 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004061 if (DISABLE_CLINGS) {
4062 return false;
4063 }
4064
Brett Chabot2a9e2282011-08-23 15:03:13 -07004065 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004066 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004067
Michael Jurkae233a8b2013-03-19 13:49:20 +01004068 // Restricted secondary users (child mode) will potentially have very few apps
4069 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004070// boolean supportsLimitedUsers =
4071// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4072// Account[] accounts = AccountManager.get(this).getAccounts();
4073// if (supportsLimitedUsers && accounts.length == 0) {
4074// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4075// Bundle restrictions = um.getUserRestrictions();
4076// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4077// return false;
4078// }
4079// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004080 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004081 }
Michael Jurka22143132012-10-04 17:42:38 +02004082
Winson Chungfa545132013-09-26 17:45:32 -07004083 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004084 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004085 Cling cling = (Cling) findViewById(clingId);
4086 View scrim = null;
4087 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004088 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004089 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004090 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004091 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004092 cling.show(animate, SHOW_CLING_DURATION);
4093
4094 if (dimNavBarVisibilty) {
4095 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4096 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004097 }
4098 }
4099 return cling;
4100 }
Michael Jurka22143132012-10-04 17:42:38 +02004101
Winson Chungaf40f202013-09-18 18:26:31 -07004102 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4103 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004104 // To catch cases where siblings of top-level views are made invisible, just check whether
4105 // the cling is directly set to GONE before dismissing it.
4106 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004107 final Runnable cleanUpClingCb = new Runnable() {
4108 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004109 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004110 // We should update the shared preferences on a background thread
4111 new Thread("dismissClingThread") {
4112 public void run() {
4113 SharedPreferences.Editor editor = mSharedPrefs.edit();
4114 editor.putBoolean(flag, true);
4115 editor.commit();
4116 }
4117 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004118 if (postAnimationCb != null) {
4119 postAnimationCb.run();
4120 }
4121 }
4122 };
4123 if (duration <= 0) {
4124 cleanUpClingCb.run();
4125 } else {
4126 cling.hide(duration, cleanUpClingCb);
4127 }
Michael Jurka22143132012-10-04 17:42:38 +02004128 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004129
4130 if (restoreNavBarVisibilty) {
4131 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4132 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4133 }
Winson Chung82f55532011-08-09 14:14:23 -07004134 }
4135 }
Michael Jurka22143132012-10-04 17:42:38 +02004136
Winson Chung9d9d74f2011-09-19 11:49:12 -07004137 private void removeCling(int id) {
4138 final View cling = findViewById(id);
4139 if (cling != null) {
4140 final ViewGroup parent = (ViewGroup) cling.getParent();
4141 parent.post(new Runnable() {
4142 @Override
4143 public void run() {
4144 parent.removeView(cling);
4145 }
4146 });
Michael Jurka22143132012-10-04 17:42:38 +02004147 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004148 }
4149 }
Michael Jurka974c3862012-05-22 22:00:31 -07004150
4151 private boolean skipCustomClingIfNoAccounts() {
4152 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4153 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4154 if (customCling) {
4155 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004156 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004157 Account[] accounts = am.getAccountsByType("com.google");
4158 return accounts.length == 0;
4159 }
4160 return false;
4161 }
4162
Winson Chungaf40f202013-09-18 18:26:31 -07004163 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004164 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004165 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004166 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004167 // If we're not using the default workspace layout, replace workspace cling
4168 // with a custom workspace cling (usually specified in an overlay)
4169 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004170 if (!DISABLE_CUSTOM_CLINGS) {
4171 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4172 getResources().getBoolean(R.bool.config_useCustomClings)) {
4173 // Use a custom cling
4174 View cling = findViewById(R.id.workspace_cling);
4175 ViewGroup clingParent = (ViewGroup) cling.getParent();
4176 int clingIndex = clingParent.indexOfChild(cling);
4177 clingParent.removeViewAt(clingIndex);
4178 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4179 clingParent.addView(customCling, clingIndex);
4180 customCling.setId(R.id.workspace_cling);
4181 }
4182 }
4183 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4184 if (cling != null) {
4185 String sbHintStr = getFirstRunClingSearchBarHint();
4186 String ccHintStr = getFirstRunCustomContentHint();
4187 if (!sbHintStr.isEmpty()) {
4188 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4189 sbHint.setText(sbHintStr);
4190 sbHint.setVisibility(View.VISIBLE);
4191 }
4192 if (!ccHintStr.isEmpty()) {
4193 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4194 ccHint.setText(ccHintStr);
4195 ccHint.setVisibility(View.VISIBLE);
4196 }
Michael Jurka45355c42012-10-08 13:21:35 +02004197 }
Winson Chungfa545132013-09-26 17:45:32 -07004198 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004199 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004200 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004201 }
4202 }
Winson Chungaf40f202013-09-18 18:26:31 -07004203
Winson Chunge6eabff2013-09-24 11:01:23 -07004204 protected String getFirstRunClingSearchBarHint() {
4205 return "";
4206 }
4207 protected String getFirstRunCustomContentHint() {
4208 return "";
4209 }
4210
Winson Chungaf40f202013-09-18 18:26:31 -07004211 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004212 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004213 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004214 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004215 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004216 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004217 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004218 }
4219 }
4220 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004221 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004222 if (isClingsEnabled() &&
4223 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004224 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4225 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004226 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004227 } else {
4228 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004229 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004230 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004231 }
Michael Jurka104c4562013-07-08 18:03:46 -07004232 protected SharedPreferences getSharedPrefs() {
4233 return mSharedPrefs;
4234 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004235 public boolean isFolderClingVisible() {
4236 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004237 if (cling != null) {
4238 return cling.getVisibility() == View.VISIBLE;
4239 }
4240 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004241 }
Winson Chungaf40f202013-09-18 18:26:31 -07004242 public void dismissFirstRunCling(View v) {
4243 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4244 Runnable cb = new Runnable() {
4245 public void run() {
4246 // Show the workspace cling next
4247 showFirstRunWorkspaceCling();
4248 }
4249 };
4250 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4251 DISMISS_CLING_DURATION, false);
4252 }
Winson Chung82f55532011-08-09 14:14:23 -07004253 public void dismissWorkspaceCling(View v) {
4254 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004255 Runnable cb = null;
4256 if (v == null) {
4257 cb = new Runnable() {
4258 public void run() {
4259 mWorkspace.enterOverviewMode();
4260 }
4261 };
4262 }
4263 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4264 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004265 }
4266 public void dismissFolderCling(View v) {
4267 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004268 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4269 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004270 }
4271
Winson Chung80baf5a2010-08-09 16:03:15 -07004272 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004273 * Prints out out state for debugging.
4274 */
4275 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004276 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004277 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004278 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4279 Log.d(TAG, "mRestoring=" + mRestoring);
4280 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4281 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004282 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004283 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004284
Winson Chung785d2eb2011-04-14 16:08:02 -07004285 if (mAppsCustomizeContent != null) {
4286 mAppsCustomizeContent.dumpState();
4287 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004288 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004289 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004290
4291 @Override
4292 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4293 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004294 synchronized (sDumpLogs) {
4295 writer.println(" ");
4296 writer.println("Debug logs: ");
4297 for (int i = 0; i < sDumpLogs.size(); i++) {
4298 writer.println(" " + sDumpLogs.get(i));
4299 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004300 }
4301 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004302
4303 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004304 if (DEBUG_DUMP_LOG) {
4305 synchronized (sDumpLogs) {
4306 Log.d(TAG, "");
4307 Log.d(TAG, "*********************");
4308 Log.d(TAG, "Launcher debug logs: ");
4309 for (int i = 0; i < sDumpLogs.size(); i++) {
4310 Log.d(TAG, " " + sDumpLogs.get(i));
4311 }
4312 Log.d(TAG, "*********************");
4313 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004314 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004315 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004316 }
4317
4318 public static void addDumpLog(String tag, String log, boolean debugLog) {
4319 if (debugLog) {
4320 Log.d(tag, log);
4321 }
Winson Chungede41292013-09-19 16:27:36 -07004322 if (DEBUG_DUMP_LOG) {
4323 sDateStamp.setTime(System.currentTimeMillis());
4324 synchronized (sDumpLogs) {
4325 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004326 }
Winson Chungede41292013-09-19 16:27:36 -07004327 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004328 }
4329
Winson Chungede41292013-09-19 16:27:36 -07004330 public void dumpLogsToLocalData() {
4331 if (DEBUG_DUMP_LOG) {
4332 new Thread("DumpLogsToLocalData") {
4333 @Override
4334 public void run() {
4335 boolean success = false;
4336 sDateStamp.setTime(sRunStart);
4337 String FILENAME = sDateStamp.getMonth() + "-"
4338 + sDateStamp.getDay() + "_"
4339 + sDateStamp.getHours() + "-"
4340 + sDateStamp.getMinutes() + "_"
4341 + sDateStamp.getSeconds() + ".txt";
4342
4343 FileOutputStream fos = null;
4344 File outFile = null;
4345 try {
4346 outFile = new File(getFilesDir(), FILENAME);
4347 outFile.createNewFile();
4348 fos = new FileOutputStream(outFile);
4349 } catch (Exception e) {
4350 e.printStackTrace();
4351 }
4352 if (fos != null) {
4353 PrintWriter writer = new PrintWriter(fos);
4354
4355 writer.println(" ");
4356 writer.println("Debug logs: ");
4357 synchronized (sDumpLogs) {
4358 for (int i = 0; i < sDumpLogs.size(); i++) {
4359 writer.println(" " + sDumpLogs.get(i));
4360 }
4361 }
4362 writer.close();
4363 }
4364 try {
4365 if (fos != null) {
4366 fos.close();
4367 success = true;
4368 }
4369 } catch (IOException e) {
4370 e.printStackTrace();
4371 }
4372 }
4373 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004374 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004375 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004376}
Michael Jurka2763be32011-02-24 11:19:57 -08004377
Michael Jurkaabded662011-03-04 12:06:57 -08004378interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004379 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004380 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004381 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004382 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004383 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004384}