blob: 8f0fddea9c1f54651c4bb8fb6e91d9dd01e38994 [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;
Adam Cohen7564d982013-06-06 23:11:58 -0700277 private static final boolean DISABLE_CLINGS = true;
Winson Chunge6eabff2013-09-24 11:01:23 -0700278 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static LocaleConfiguration sLocaleConfiguration = null;
281
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700282 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700284 private Intent mAppMarketIntent = null;
285
Adam Cohended9f8d2010-11-03 13:25:16 -0700286 // Related to the auto-advancing of widgets
287 private final int ADVANCE_MSG = 1;
288 private final int mAdvanceInterval = 20000;
289 private final int mAdvanceStagger = 250;
290 private long mAutoAdvanceSentTime;
291 private long mAutoAdvanceTimeLeft = -1;
292 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
293 new HashMap<View, AppWidgetProviderInfo>();
294
Winson Chung400438b2011-01-16 17:53:48 -0800295 // Determines how long to wait after a rotation before restoring the screen orientation to
296 // match the sensor state.
297 private final int mRestoreScreenOrientationDelay = 500;
298
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700300 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
302 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
Craig Mautner360310b2012-10-26 15:13:08 -0700304 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700305
Adam Cohen1462de32012-07-24 22:34:36 -0700306 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
307
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700308 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700309 static Date sDateStamp = new Date();
310 static DateFormat sDateFormat =
311 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
312 static long sRunStart = System.currentTimeMillis();
313 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700314
Winson Chung46353de2012-02-16 14:05:10 -0800315 // We only want to get the SharedPreferences once since it does an FS stat each time we get
316 // it from the context.
317 private SharedPreferences mSharedPrefs;
318
Adam Cohene25af792013-06-06 23:08:25 -0700319 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
320
Winson Chungf0c6ae02012-03-21 16:10:31 -0700321 // Holds the page that we need to animate to, and the icon views that we need to animate up
322 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700323 private ImageView mFolderIconImageView;
324 private Bitmap mFolderIconBitmap;
325 private Canvas mFolderIconCanvas;
326 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700327
Michael Jurkaddd62e92011-02-16 17:49:14 -0800328 private BubbleTextView mWaitingForResume;
329
Michael Jurka22143132012-10-04 17:42:38 +0200330 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
331 = new HideFromAccessibilityHelper();
332
Michael Jurkac1f5d262011-09-30 19:32:27 -0700333 private Runnable mBuildLayersRunnable = new Runnable() {
334 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700335 if (mWorkspace != null) {
336 mWorkspace.buildPageHardwareLayers();
337 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700338 }
339 };
340
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800341 private static ArrayList<PendingAddArguments> sPendingAddList
342 = new ArrayList<PendingAddArguments>();
343
Michael Jurka0a457bf2012-11-19 14:05:05 -0800344 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
345
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800346 private static class PendingAddArguments {
347 int requestCode;
348 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700349 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700350 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800351 int cellX;
352 int cellY;
353 }
354
Daniel Sandlerff02d492013-08-05 02:12:05 -0400355 private Stats mStats;
356
Michael Jurka0a457bf2012-11-19 14:05:05 -0800357 private static boolean isPropertyEnabled(String propertyName) {
358 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700359 }
360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 @Override
362 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700363 if (DEBUG_STRICT_MODE) {
364 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
365 .detectDiskReads()
366 .detectDiskWrites()
367 .detectNetwork() // or .detectAll() for all detectable problems
368 .penaltyLog()
369 .build());
370 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
371 .detectLeakedSqlLiteObjects()
372 .detectLeakedClosableObjects()
373 .penaltyLog()
374 .penaltyDeath()
375 .build());
376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400379
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400381 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700382
383 // Determine the dynamic grid properties
384 Point smallestSize = new Point();
385 Point largestSize = new Point();
386 Point realSize = new Point();
387 Display display = getWindowManager().getDefaultDisplay();
388 display.getCurrentSizeRange(smallestSize, largestSize);
389 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700390 DisplayMetrics dm = new DisplayMetrics();
391 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700392 // Lazy-initialize the dynamic grid
393 DeviceProfile grid = app.initDynamicGrid(this,
394 Math.min(smallestSize.x, smallestSize.y),
395 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700396 realSize.x, realSize.y,
397 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700398
399 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400400 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700401 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800402 mModel = app.setLauncher(this);
403 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400404 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700406
Daniel Sandlerff02d492013-08-05 02:12:05 -0400407 mStats = new Stats(this);
408
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700409 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
411 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700412
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700413 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
414 // this also ensures that any synchronous binding below doesn't re-trigger another
415 // LauncherModel load.
416 mPaused = false;
417
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200419 android.os.Debug.startMethodTracing(
420 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 }
422
423 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 setContentView(R.layout.launcher);
425 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100426 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800428 registerContentObservers();
429
Joe Onorato7c312c12009-08-13 21:36:53 -0700430 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700431
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 mSavedState = savedInstanceState;
433 restoreState(mSavedState);
434
Winson Chunga12a2502010-12-20 14:41:35 -0800435 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700436 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200437 mAppsCustomizeContent.onPackagesUpdated(
438 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700439 }
Winson Chunga12a2502010-12-20 14:41:35 -0800440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 if (PROFILE_STARTUP) {
442 android.os.Debug.stopMethodTracing();
443 }
444
445 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700446 if (sPausedFromUserAction) {
447 // If the user leaves launcher, then we should just load items asynchronously when
448 // they return.
449 mModel.startLoader(true, -1);
450 } else {
451 // We only load the page synchronously if the user rotates (or triggers a
452 // configuration change) while launcher is in the foreground
453 mModel.startLoader(true, mWorkspace.getCurrentPage());
454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 // For handling default keys
458 mDefaultKeySsb = new SpannableStringBuilder();
459 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800460
461 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
462 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800463
Adam Cohenf9426d52012-06-04 17:26:21 -0700464 updateGlobalIcons();
465
466 // On large interfaces, we want the screen to auto-rotate based on the current orientation
467 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700468
469 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700470 }
471
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 protected void onUserLeaveHint() {
473 super.onUserLeaveHint();
474 sPausedFromUserAction = true;
475 }
476
Winson Chung98ca0f72013-07-29 12:58:51 -0700477 /** To be overriden by subclasses to hint to Launcher that we have custom content */
478 protected boolean hasCustomContentToLeft() {
479 return false;
480 }
481
Dave Hawkeya8881582013-09-17 15:55:33 -0600482 /**
483 * To be overridden by subclasses to create the custom content and call
484 * {@link #addToCustomContentPage}. This will only be invoked if
485 * {@link #hasCustomContentToLeft()} is {@code true}.
486 */
487 protected void addCustomContentToLeft() {
488 }
489
490 /**
491 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
492 * ensure the custom content page is added or removed if necessary.
493 */
494 protected void invalidateHasCustomContentToLeft() {
495 if (mWorkspace.getScreenOrder().isEmpty()) {
496 // Not bound yet, wait for bindScreens to be called.
497 return;
498 }
499
500 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
501 // Create the custom content page and call the subclass to populate it.
502 mWorkspace.createCustomContentPage();
503 addCustomContentToLeft();
504 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
505 mWorkspace.removeCustomContentPage();
506 }
507 }
508
Adam Cohenf9426d52012-06-04 17:26:21 -0700509 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700510 boolean searchVisible = false;
511 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800512 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700513 int coi = getCurrentOrientationIndexForGlobalIcons();
514 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
515 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700516 updateAppMarketIcon();
517 searchVisible = updateGlobalSearchIcon();
518 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700519 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700520 if (sGlobalSearchIcon[coi] != null) {
521 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700523 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700524 if (sVoiceSearchIcon[coi] != null) {
525 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700526 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700527 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700528 if (sAppMarketIcon[coi] != null) {
529 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800530 }
Winson Chungadf0c182012-08-23 14:59:07 -0700531 if (mSearchDropTargetBar != null) {
532 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
533 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800534 }
Romain Guycbb89e42009-06-08 15:52:54 -0700535
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800536 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700537 if (sLocaleConfiguration == null) {
538 new AsyncTask<Void, Void, LocaleConfiguration>() {
539 @Override
540 protected LocaleConfiguration doInBackground(Void... unused) {
541 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
542 readConfiguration(Launcher.this, localeConfiguration);
543 return localeConfiguration;
544 }
545
546 @Override
547 protected void onPostExecute(LocaleConfiguration result) {
548 sLocaleConfiguration = result;
549 checkForLocaleChange(); // recursive, but now with a locale configuration
550 }
551 }.execute();
552 return;
553 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700554
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 final Configuration configuration = getResources().getConfiguration();
556
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700557 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final String locale = configuration.locale.toString();
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final int mcc = configuration.mcc;
562
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700563 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final int mnc = configuration.mnc;
565
Romain Guy84f296c2009-11-04 15:00:44 -0800566 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567
Romain Guy84f296c2009-11-04 15:00:44 -0800568 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700569 sLocaleConfiguration.locale = locale;
570 sLocaleConfiguration.mcc = mcc;
571 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700572
Joe Onorato0589f0f2010-02-08 13:44:00 -0800573 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574
575 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
576 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700577 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 public void run() {
579 writeConfiguration(Launcher.this, localeConfiguration);
580 }
581 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700582 }
583 }
584
585 private static class LocaleConfiguration {
586 public String locale;
587 public int mcc = -1;
588 public int mnc = -1;
589 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700590
Romain Guy98d01652009-06-30 16:21:04 -0700591 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
592 DataInputStream in = null;
593 try {
594 in = new DataInputStream(context.openFileInput(PREFERENCES));
595 configuration.locale = in.readUTF();
596 configuration.mcc = in.readInt();
597 configuration.mnc = in.readInt();
598 } catch (FileNotFoundException e) {
599 // Ignore
600 } catch (IOException e) {
601 // Ignore
602 } finally {
603 if (in != null) {
604 try {
605 in.close();
606 } catch (IOException e) {
607 // Ignore
608 }
609 }
610 }
611 }
612
613 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
614 DataOutputStream out = null;
615 try {
616 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
617 out.writeUTF(configuration.locale);
618 out.writeInt(configuration.mcc);
619 out.writeInt(configuration.mnc);
620 out.flush();
621 } catch (FileNotFoundException e) {
622 // Ignore
623 } catch (IOException e) {
624 //noinspection ResultOfMethodCallIgnored
625 context.getFileStreamPath(PREFERENCES).delete();
626 } finally {
627 if (out != null) {
628 try {
629 out.close();
630 } catch (IOException e) {
631 // Ignore
632 }
633 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800634 }
635 }
636
Anton Hanssona2f665f2013-09-26 12:18:32 +0100637 public Stats getStats() {
638 return mStats;
639 }
640
Bjorn Bringertc459e522013-06-07 19:36:01 +0100641 public LayoutInflater getInflater() {
642 return mInflater;
643 }
644
Adam Cohen716b51e2011-06-30 12:09:54 -0700645 public DragLayer getDragLayer() {
646 return mDragLayer;
647 }
648
Winson Chung36a62fe2012-05-06 18:04:42 -0700649 boolean isDraggingEnabled() {
650 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
651 // that is subsequently removed from the workspace in startBinding().
652 return !mModel.isLoadingWorkspace();
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 static int getScreen() {
656 synchronized (sLock) {
657 return sScreen;
658 }
659 }
660
661 static void setScreen(int screen) {
662 synchronized (sLock) {
663 sScreen = screen;
664 }
665 }
666
Winson Chung557d6ed2011-07-08 15:34:52 -0700667 /**
668 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
669 * a configuration step, this allows the proper animations to run after other transitions.
670 */
671 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700672 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800673 switch (args.requestCode) {
674 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700675 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700676 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800677 break;
678 case REQUEST_PICK_SHORTCUT:
679 processShortcut(args.intent);
680 break;
681 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700682 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700683 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700684 result = true;
685 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 case REQUEST_CREATE_APPWIDGET:
687 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700688 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 result = true;
690 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 }
Michael Jurka27614d22012-04-02 06:40:22 -0700692 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
693 // if you turned the screen off and then back while in All Apps, Launcher would not
694 // return to the workspace. Clearing mAddInfo.container here fixes this issue
695 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700696 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800697 }
698
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 protected void onActivityResult(
701 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700702 // Reset the startActivity waiting flag
703 mWaitingForResult = false;
704
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 if (requestCode == REQUEST_BIND_APPWIDGET) {
706 int appWidgetId = data != null ?
707 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
708 if (resultCode == RESULT_CANCELED) {
709 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
710 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700711 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 }
713 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200714 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
715 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
716 mWorkspace.exitOverviewMode(false);
717 }
718 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700719 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200720
Winson Chung557d6ed2011-07-08 15:34:52 -0700721 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800722 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
723 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700724
Adam Cohened66b2b2012-01-23 17:28:51 -0800725 // We have special handling for widgets
726 if (isWidgetDrop) {
727 int appWidgetId = data != null ?
728 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700729 if (appWidgetId < 0) {
730 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
731 "widget configuration activity.");
732 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
733 } else {
734 completeTwoStageWidgetDrop(resultCode, appWidgetId);
735 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800736 return;
737 }
738
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 // The pattern used here is that a user PICKs a specific application,
740 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700741
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
743 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700744 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 final PendingAddArguments args = new PendingAddArguments();
746 args.requestCode = requestCode;
747 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700748 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700749 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700750 args.cellX = mPendingAddInfo.cellX;
751 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 if (isWorkspaceLocked()) {
753 sPendingAddList.add(args);
754 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700755 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800758 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700759 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800760 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
761 null);
762 }
763
764 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700765 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700766 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 Runnable onCompleteRunnable = null;
768 int animationType = 0;
769
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700770 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 if (resultCode == RESULT_OK) {
772 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
773 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700774 mPendingAddWidgetInfo);
775 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 onCompleteRunnable = new Runnable() {
777 @Override
778 public void run() {
779 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700780 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
782 null);
783 }
784 };
785 } else if (resultCode == RESULT_CANCELED) {
786 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
787 onCompleteRunnable = new Runnable() {
788 @Override
789 public void run() {
790 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
791 null);
792 }
793 };
794 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700795 if (mDragLayer.getAnimatedView() != null) {
796 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
797 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
798 animationType, boundWidget, true);
799 } else {
800 // The animated view may be null in the case of a rotation during widget configuration
801 onCompleteRunnable.run();
802 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800803 }
804
805 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700806 protected void onStop() {
807 super.onStop();
808 FirstFrameAnimatorHelper.setIsVisible(false);
809 }
810
811 @Override
812 protected void onStart() {
813 super.onStart();
814 FirstFrameAnimatorHelper.setIsVisible(true);
815 }
816
817 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200819 long startTime = 0;
820 if (DEBUG_RESUME_TIME) {
821 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400822 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200823 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700825
Winson Chung4a2afa32012-07-19 14:53:05 -0700826 // Restore the previous launcher state
827 if (mOnResumeState == State.WORKSPACE) {
828 showWorkspace(false);
829 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700830 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700831 }
832 mOnResumeState = State.NONE;
833
Craig Mautner360310b2012-10-26 15:13:08 -0700834 // Background was set to gradient in onPause(), restore to black if in all apps.
835 setWorkspaceBackground(mState == State.WORKSPACE);
836
Winson Chungde0fb8f2012-05-08 14:37:08 -0700837 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700838 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700839
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 }
Adam Cohen06dff352012-06-01 17:17:08 -0700888 // It is possible that widgets can receive updates while launcher is not in the foreground.
889 // Consequently, the widgets will be inflated in the orientation of the foreground activity
890 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
891 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700892 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700893
894 // Again, as with the above scenario, it's possible that one or more of the global icons
895 // were updated in the wrong orientation.
896 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200897 if (DEBUG_RESUME_TIME) {
898 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
899 }
Adam Cohen06dff352012-06-01 17:17:08 -0700900 }
901
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700903 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700904 // Ensure that items added to Launcher are queued until Launcher returns
905 InstallShortcutReceiver.enableInstallQueue();
906
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700907 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700908 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800909 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700910 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700911 }
Romain Guycbb89e42009-06-08 15:52:54 -0700912
Adam Cohen66a01fd2013-06-11 12:48:00 -0700913 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600914 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
915 addCustomContentToLeft();
916 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700917 }
918
Adam Cohenbffe7452013-07-22 18:21:45 -0700919 QSBScroller mQsbScroller = new QSBScroller() {
920 int scrollY = 0;
921
922 @Override
923 public void setScrollY(int scroll) {
924 scrollY = scroll;
925
926 if (mWorkspace.isOnOrMovingToCustomContent()) {
927 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100928 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700929 }
930 }
931 };
932
933 public void resetQSBScroll() {
934 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100935 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700936 }
937
938 public interface CustomContentCallbacks {
939 // Custom content is completely shown
940 public void onShow();
941
942 // Custom content is completely hidden
943 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700944
945 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
946 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700947 }
948
Adam Cohen30bacb22013-08-29 14:25:25 -0700949 protected void startSettings() {
950 }
951
Adam Cohenbffe7452013-07-22 18:21:45 -0700952 public interface QSBScroller {
953 public void setScrollY(int scrollY);
954 }
955
Adam Cohen66a01fd2013-06-11 12:48:00 -0700956 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700957 public QSBScroller addToCustomContentPage(View customContent) {
958 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 }
960
Winson Chung98ca0f72013-07-29 12:58:51 -0700961 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700962 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700963 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700964 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700965 }
966
Adam Cohenedb40762013-07-18 16:45:45 -0700967 // The custom content needs to offset its content to account for the QSB
968 public int getTopOffsetForCustomContent() {
969 return mWorkspace.getPaddingTop();
970 }
971
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700972 @Override
973 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400974 // Flag the loader to stop early before switching
975 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700976 if (mAppsCustomizeContent != null) {
977 mAppsCustomizeContent.surrender();
978 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800979 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700980 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700981
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800982 // We can't hide the IME if it was forced open. So don't bother
983 /*
984 @Override
985 public void onWindowFocusChanged(boolean hasFocus) {
986 super.onWindowFocusChanged(hasFocus);
987
988 if (hasFocus) {
989 final InputMethodManager inputManager = (InputMethodManager)
990 getSystemService(Context.INPUT_METHOD_SERVICE);
991 WindowManager.LayoutParams lp = getWindow().getAttributes();
992 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
993 android.os.Handler()) {
994 protected void onReceiveResult(int resultCode, Bundle resultData) {
995 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
996 }
997 });
998 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
999 }
1000 }
1001 */
1002
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 private boolean acceptFilter() {
1004 final InputMethodManager inputManager = (InputMethodManager)
1005 getSystemService(Context.INPUT_METHOD_SERVICE);
1006 return !inputManager.isFullscreenMode();
1007 }
1008
1009 @Override
1010 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001011 final int uniChar = event.getUnicodeChar();
1012 final boolean handled = super.onKeyDown(keyCode, event);
1013 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1014 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1016 keyCode, event);
1017 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001018 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001019 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001020 // showSearchDialog()
1021 // If there are multiple keystrokes before the search dialog takes focus,
1022 // onSearchRequested() will be called for every keystroke,
1023 // but it is idempotent, so it's fine.
1024 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025 }
1026 }
1027
Joe Onorato8a9625e2010-01-28 15:55:35 -08001028 // Eat the long press event so the keyboard doesn't come up.
1029 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1030 return true;
1031 }
1032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 return handled;
1034 }
1035
Karl Rosaen138a0412009-04-23 19:00:21 -07001036 private String getTypedText() {
1037 return mDefaultKeySsb.toString();
1038 }
1039
1040 private void clearTypedText() {
1041 mDefaultKeySsb.clear();
1042 mDefaultKeySsb.clearSpans();
1043 Selection.setSelection(mDefaultKeySsb, 0);
1044 }
1045
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001047 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1048 * State
1049 */
1050 private static State intToState(int stateOrdinal) {
1051 State state = State.WORKSPACE;
1052 final State[] stateValues = State.values();
1053 for (int i = 0; i < stateValues.length; i++) {
1054 if (stateValues[i].ordinal() == stateOrdinal) {
1055 state = stateValues[i];
1056 break;
1057 }
1058 }
1059 return state;
1060 }
1061
1062 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 * Restores the previous state, if it exists.
1064 *
1065 * @param savedState The previous state.
1066 */
1067 private void restoreState(Bundle savedState) {
1068 if (savedState == null) {
1069 return;
1070 }
1071
Michael Jurka883f55b2010-10-21 15:47:14 -07001072 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001073 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001074 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001075 }
1076
Winson Chungf0c6ae02012-03-21 16:10:31 -07001077 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001079 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 }
1081
Winson Chung3d503fb2011-07-13 17:25:49 -07001082 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001083 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001084
Winson Chung3d503fb2011-07-13 17:25:49 -07001085 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1086 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001087 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1089 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001090 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1091 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1092 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001093 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 mRestoring = true;
1095 }
1096
1097 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1098 if (renameFolder) {
1099 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001100 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 mRestoring = true;
1102 }
Winson Chunga12a2502010-12-20 14:41:35 -08001103
Winson Chung785d2eb2011-04-14 16:08:02 -07001104 // Restore the AppsCustomize tab
1105 if (mAppsCustomizeTabHost != null) {
1106 String curTab = savedState.getString("apps_customize_currentTab");
1107 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001108 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001109 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001110 mAppsCustomizeContent.loadAssociatedPages(
1111 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 }
1113
Winson Chung5afbf7b2011-07-25 11:53:08 -07001114 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1115 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 }
1118
1119 /**
1120 * Finds all the views we need and configure them properly.
1121 */
1122 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001123 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001124
Craig Mautner360310b2012-10-26 15:13:08 -07001125 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001126 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1127 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001128
John Spurlock77e1f472013-09-11 10:09:51 -04001129 mLauncherView.setSystemUiVisibility(
1130 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001131 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132
Winson Chung4c98d922011-05-31 16:50:48 -07001133 // Setup the drag layer
1134 mDragLayer.setup(this, dragController);
1135
Winson Chung3d503fb2011-07-13 17:25:49 -07001136 // Setup the hotseat
1137 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1138 if (mHotseat != null) {
1139 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001140 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001141 }
1142
Adam Cohenf358a4b2013-07-23 16:47:31 -07001143 mOverviewPanel = findViewById(R.id.overview_panel);
1144 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1145 @Override
1146 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001147 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001148 }
1149 });
1150 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1151 @Override
1152 public void onClick(View arg0) {
1153 startWallpaper();
1154 }
1155 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001156 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1157 @Override
1158 public void onClick(View arg0) {
1159 startSettings();
1160 }
1161 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001162 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001163
Winson Chung4c98d922011-05-31 16:50:48 -07001164 // Setup the workspace
1165 mWorkspace.setHapticFeedbackEnabled(false);
1166 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001167 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001168 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001169
Winson Chungf0ea4d32011-06-06 14:27:16 -07001170 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001171 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001172
Winson Chungf0ea4d32011-06-06 14:27:16 -07001173 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001174 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001175 mAppsCustomizeContent = (AppsCustomizePagedView)
1176 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1177 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001178
Winson Chung3d503fb2011-07-13 17:25:49 -07001179 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001180 dragController.setDragScoller(mWorkspace);
1181 dragController.setScrollView(mDragLayer);
1182 dragController.setMoveTarget(mWorkspace);
1183 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001184 if (mSearchDropTargetBar != null) {
1185 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001186 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001187
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001188 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001189 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001190 mWeightWatcher = new WeightWatcher(this);
1191 mWeightWatcher.setAlpha(0.5f);
1192 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001193 new FrameLayout.LayoutParams(
1194 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001195 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 Gravity.BOTTOM)
1197 );
Adam Cohen39a06042013-07-19 14:30:12 -07001198
1199 boolean show = shouldShowWeightWatcher();
1200 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001201 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 }
1203
1204 /**
1205 * Creates a view representing a shortcut.
1206 *
1207 * @param info The data structure describing the shortcut.
1208 *
1209 * @return A View inflated from R.layout.application.
1210 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001211 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001213 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 }
1215
1216 /**
1217 * Creates a view representing a shortcut inflated from the specified resource.
1218 *
1219 * @param layoutResId The id of the XML layout used to create the shortcut.
1220 * @param parent The group the shortcut belongs to.
1221 * @param info The data structure describing the shortcut.
1222 *
1223 * @return A View inflated from layoutResId.
1224 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001225 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001226 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1227 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 return favorite;
1230 }
1231
1232 /**
1233 * Add an application shortcut to the workspace.
1234 *
1235 * @param data The intent describing the application.
1236 * @param cellInfo The position on screen where to create the shortcut.
1237 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001238 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001239 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001240 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001241
Adam Cohenfbba09b2011-07-18 21:43:05 -07001242 // First we check if we already know the exact location where we want to add this item.
1243 if (cellX >= 0 && cellY >= 0) {
1244 cellXY[0] = cellX;
1245 cellXY[1] = cellY;
1246 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001247 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001248 return;
1249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001251 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001252
Romain Guy73b979d2009-06-09 12:57:21 -07001253 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001254 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001256 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001257 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001258 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001259 } else {
1260 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 }
1262 }
Romain Guycbb89e42009-06-08 15:52:54 -07001263
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 /**
1265 * Add a shortcut to the workspace.
1266 *
1267 * @param data The intent describing the shortcut.
1268 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001269 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001270 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001271 int cellY) {
1272 int[] cellXY = mTmpAddItemCellCoordinates;
1273 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001275
Michael Jurkad3ef3062010-11-23 16:23:58 -08001276 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001277
Adam Cohen558baaf2011-08-15 15:22:57 -07001278 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001279 if (info == null) {
1280 return;
1281 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001282 final View view = createShortcut(info);
1283
Adam Cohenfbba09b2011-07-18 21:43:05 -07001284 // First we check if we already know the exact location where we want to add this item.
1285 if (cellX >= 0 && cellY >= 0) {
1286 cellXY[0] = cellX;
1287 cellXY[1] = cellY;
1288 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001289
1290 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001291 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001292 true, null,null)) {
1293 return;
1294 }
1295 DragObject dragObject = new DragObject();
1296 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001297 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1298 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001299 return;
1300 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001302 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001303 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001304 foundCellSpan = (result != null);
1305 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001306 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001307 }
1308
1309 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001310 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001311 return;
1312 }
1313
Adam Cohendcd297f2013-06-18 13:13:40 -07001314 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315
1316 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001317 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001318 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 }
1320 }
1321
Adam Cohen2f093b62012-04-30 18:59:53 -07001322 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1323 int minHeight) {
1324 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001325 // We want to account for the extra amount of padding that we are adding to the widget
1326 // to ensure that it gets the full amount of space that it has requested
1327 int requiredWidth = minWidth + padding.left + padding.right;
1328 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001329 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001330 }
1331
Adam Cohen2f093b62012-04-30 18:59:53 -07001332 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1333 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1337 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001338 }
1339
Adam Cohen2f093b62012-04-30 18:59:53 -07001340 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1341 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001342 }
1343
Adam Cohen2f093b62012-04-30 18:59:53 -07001344 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1345 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001346 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001347 }
1348
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001350 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001352 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001353 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001355 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001356 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1357 if (appWidgetInfo == null) {
1358 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1359 }
Romain Guycbb89e42009-06-08 15:52:54 -07001360
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001361 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001362 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001363
Adam Cohen2f093b62012-04-30 18:59:53 -07001364 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1365 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001366
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001368 // We have saved the position to which the widget was dragged-- this really only matters
1369 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 int[] cellXY = mTmpAddItemCellCoordinates;
1371 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001372 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001373 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1375 cellXY[0] = mPendingAddInfo.cellX;
1376 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001377 spanXY[0] = mPendingAddInfo.spanX;
1378 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001379 foundCellSpan = true;
1380 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001381 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001382 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001383 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1384 spanXY[1], cellXY, finalSpan);
1385 spanXY[0] = finalSpan[0];
1386 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001387 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001389 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001390 }
1391
Michael Jurka0280c3b2010-09-17 15:00:07 -07001392 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001393 if (appWidgetId != -1) {
1394 // Deleting an app widget ID is a void call but writes to disk before returning
1395 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001396 new Thread("deleteAppWidgetId") {
1397 public void run() {
1398 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1399 }
1400 }.start();
1401 }
Winson Chung93eef082012-03-23 15:59:27 -07001402 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001403 return;
1404 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001405
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001406 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001407 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1408 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 launcherInfo.spanX = spanXY[0];
1410 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001411 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1412 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001413
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001415 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416
1417 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001418 if (hostView == null) {
1419 // Perform actual inflation because we're live
1420 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1421 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1422 } else {
1423 // The AppWidgetHostView has already been inflated and instantiated
1424 launcherInfo.hostView = hostView;
1425 }
Romain Guycbb89e42009-06-08 15:52:54 -07001426
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001428 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001429 launcherInfo.notifyWidgetSizeChanged(this);
1430
Adam Cohendcd297f2013-06-18 13:13:40 -07001431 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001432 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001433
1434 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001436 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001437 }
Romain Guycbb89e42009-06-08 15:52:54 -07001438
Adam Cohended9f8d2010-11-03 13:25:16 -07001439 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1440 @Override
1441 public void onReceive(Context context, Intent intent) {
1442 final String action = intent.getAction();
1443 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1444 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001445 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001446 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001447
Winson Chungc100e8e2011-08-09 16:02:43 -07001448 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001449 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001450 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001451 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001452 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001453 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1454 mUserPresent = true;
1455 updateRunning();
1456 }
1457 }
1458 };
1459
1460 @Override
1461 public void onAttachedToWindow() {
1462 super.onAttachedToWindow();
1463
1464 // Listen for broadcasts related to user-presence
1465 final IntentFilter filter = new IntentFilter();
1466 filter.addAction(Intent.ACTION_SCREEN_OFF);
1467 filter.addAction(Intent.ACTION_USER_PRESENT);
1468 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001469 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001470 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001471 mVisible = true;
1472 }
1473
1474 @Override
1475 public void onDetachedFromWindow() {
1476 super.onDetachedFromWindow();
1477 mVisible = false;
1478
Adam Cohend113e0c2010-11-11 10:48:05 -08001479 if (mAttached) {
1480 unregisterReceiver(mReceiver);
1481 mAttached = false;
1482 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001483 updateRunning();
1484 }
1485
1486 public void onWindowVisibilityChanged(int visibility) {
1487 mVisible = visibility == View.VISIBLE;
1488 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001489 // The following code used to be in onResume, but it turns out onResume is called when
1490 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1491 // is a more appropriate event to handle
1492 if (mVisible) {
1493 mAppsCustomizeTabHost.onWindowVisible();
1494 if (!mWorkspaceLoading) {
1495 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001496 // We want to let Launcher draw itself at least once before we force it to build
1497 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001498 // apps is nice and speedy.
1499 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001500 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001501 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001502 if (mStarted) return;
1503 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001504 // We delay the layer building a bit in order to give
1505 // other message processing a time to run. In particular
1506 // this avoids a delay in hiding the IME if it was
1507 // currently shown, because doing that may involve
1508 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001509 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001510 final ViewTreeObserver.OnDrawListener listener = this;
1511 mWorkspace.post(new Runnable() {
1512 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001513 if (mWorkspace != null &&
1514 mWorkspace.getViewTreeObserver() != null) {
1515 mWorkspace.getViewTreeObserver().
1516 removeOnDrawListener(listener);
1517 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001518 }
1519 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001520 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001521 }
1522 });
1523 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001524 // When Launcher comes back to foreground, a different Activity might be responsible for
1525 // the app market intent, so refresh the icon
1526 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001527 clearTypedText();
1528 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001529 }
1530
1531 private void sendAdvanceMessage(long delay) {
1532 mHandler.removeMessages(ADVANCE_MSG);
1533 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1534 mHandler.sendMessageDelayed(msg, delay);
1535 mAutoAdvanceSentTime = System.currentTimeMillis();
1536 }
1537
1538 private void updateRunning() {
1539 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1540 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1541 mAutoAdvanceRunning = autoAdvanceRunning;
1542 if (autoAdvanceRunning) {
1543 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1544 sendAdvanceMessage(delay);
1545 } else {
1546 if (!mWidgetsToAdvance.isEmpty()) {
1547 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1548 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1549 }
1550 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001551 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001552 }
1553 }
1554 }
1555
1556 private final Handler mHandler = new Handler() {
1557 @Override
1558 public void handleMessage(Message msg) {
1559 if (msg.what == ADVANCE_MSG) {
1560 int i = 0;
1561 for (View key: mWidgetsToAdvance.keySet()) {
1562 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1563 final int delay = mAdvanceStagger * i;
1564 if (v instanceof Advanceable) {
1565 postDelayed(new Runnable() {
1566 public void run() {
1567 ((Advanceable) v).advance();
1568 }
1569 }, delay);
1570 }
1571 i++;
1572 }
1573 sendAdvanceMessage(mAdvanceInterval);
1574 }
1575 }
1576 };
1577
1578 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001579 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001580 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1581 if (v instanceof Advanceable) {
1582 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001583 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 updateRunning();
1585 }
1586 }
1587
1588 void removeWidgetToAutoAdvance(View hostView) {
1589 if (mWidgetsToAdvance.containsKey(hostView)) {
1590 mWidgetsToAdvance.remove(hostView);
1591 updateRunning();
1592 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001593 }
1594
Joe Onorato9c1289c2009-08-17 11:03:03 -04001595 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001597 launcherInfo.hostView = null;
1598 }
1599
Winson Chung93eef082012-03-23 15:59:27 -07001600 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1601 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1602 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 }
1604
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001605 public LauncherAppWidgetHost getAppWidgetHost() {
1606 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607 }
Romain Guycbb89e42009-06-08 15:52:54 -07001608
Winson Chunga9abd0e2010-10-27 17:18:37 -07001609 public LauncherModel getModel() {
1610 return mModel;
1611 }
1612
Bjorn Bringertc459e522013-06-07 19:36:01 +01001613 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001614 getWindow().closeAllPanels();
1615
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001616 // Whatever we were doing is hereby canceled.
1617 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001618 }
1619
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 @Override
1621 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001622 long startTime = 0;
1623 if (DEBUG_RESUME_TIME) {
1624 startTime = System.currentTimeMillis();
1625 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 super.onNewIntent(intent);
1627
1628 // Close the menu
1629 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001630 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001631 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001632
Jamie Genniscb222e82012-10-23 15:44:26 -07001633 final boolean alreadyOnHome =
1634 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001635 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001636
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 Runnable processIntent = new Runnable() {
1638 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001639 if (mWorkspace == null) {
1640 // Can be cases where mWorkspace is null, this prevents a NPE
1641 return;
1642 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001643 Folder openFolder = mWorkspace.getOpenFolder();
1644 // In all these cases, only animate if we're already on home
1645 mWorkspace.exitWidgetResizeMode();
1646 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1647 openFolder == null) {
1648 mWorkspace.moveToDefaultScreen(true);
1649 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001650
Jamie Genniscb222e82012-10-23 15:44:26 -07001651 closeFolder();
1652 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001653
Jamie Genniscb222e82012-10-23 15:44:26 -07001654 // If we are already on home, then just animate back to the workspace,
1655 // otherwise, just wait until onResume to set the state back to Workspace
1656 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001657 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 } else {
1659 mOnResumeState = State.WORKSPACE;
1660 }
1661
1662 final View v = getWindow().peekDecorView();
1663 if (v != null && v.getWindowToken() != null) {
1664 InputMethodManager imm = (InputMethodManager)getSystemService(
1665 INPUT_METHOD_SERVICE);
1666 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1667 }
1668
Winson Chung7819a562013-09-19 15:55:45 -07001669 // Reset the apps customize page
1670 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001671 mAppsCustomizeTabHost.reset();
1672 }
1673 }
1674 };
1675
1676 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1677 // Delay processing of the intent to allow the status bar animation to finish
1678 // first in order to avoid janky animations.
1679 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001680 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001681 // Process the intent immediately.
1682 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001683 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001684
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685 }
Michael Jurka447bf842013-05-15 14:52:15 +02001686 if (DEBUG_RESUME_TIME) {
1687 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1688 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
1690
Adam Cohen040a5d22013-09-16 17:09:33 -07001691 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1692 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001693 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001694 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001695 }
1696 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001697 protected void showWorkspaceAndExitOverviewMode() {
1698 showWorkspaceAndExitOverviewMode(true);
1699 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001700
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001702 public void onRestoreInstanceState(Bundle state) {
1703 super.onRestoreInstanceState(state);
1704 for (int page: mSynchronouslyBoundPages) {
1705 mWorkspace.restoreInstanceStateForChild(page);
1706 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 }
1708
1709 @Override
1710 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001711 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001712 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713
Michael Jurka883f55b2010-10-21 15:47:14 -07001714 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001715 // We close any open folder since it will not be re-opened, and we need to make sure
1716 // this state is reflected.
1717 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718
Adam Cohendcd297f2013-06-18 13:13:40 -07001719 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001720 mWaitingForResult) {
1721 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001722 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001723 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1724 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001725 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1726 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1727 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 }
1729
1730 if (mFolderInfo != null && mWaitingForResult) {
1731 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1732 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1733 }
Michael Jurka946ad472010-07-09 18:05:18 -07001734
Winson Chung785d2eb2011-04-14 16:08:02 -07001735 // Save the current AppsCustomize tab
1736 if (mAppsCustomizeTabHost != null) {
1737 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1738 if (currentTabTag != null) {
1739 outState.putString("apps_customize_currentTab", currentTabTag);
1740 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001741 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1742 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001743 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745
1746 @Override
1747 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001749
Winson Chunge7a03942011-08-05 15:05:12 -07001750 // Remove all pending runnables
1751 mHandler.removeMessages(ADVANCE_MSG);
1752 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001753 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001754
Winson Chungcd2b0142011-06-08 16:02:26 -07001755 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001756 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001757 mModel.stopLoader();
1758 app.setLauncher(null);
1759
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001761 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001763 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001765 mAppWidgetHost = null;
1766
1767 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768
1769 TextKeyListener.getInstance().release();
1770
Winson Chung81b52252012-08-27 15:34:29 -07001771 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1772 // to prevent leaking Launcher activities on orientation change.
1773 if (mModel != null) {
1774 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1775 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001776
1777 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001778 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001779
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001780 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001781 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1782 mWorkspace.removeAllViews();
1783 mWorkspace = null;
1784 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001785
Michael Jurka2ecf9952012-06-18 12:52:28 -07001786 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 }
1788
Adam Cohena9cf38f2011-05-02 15:36:58 -07001789 public DragController getDragController() {
1790 return mDragController;
1791 }
1792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 @Override
1794 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001795 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 super.startActivityForResult(intent, requestCode);
1797 }
1798
Winson Chung70d72102011-08-12 11:24:35 -07001799 /**
1800 * Indicates that we want global search for this activity by setting the globalSearch
1801 * argument for {@link #startSearch} to true.
1802 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001804 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001806
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001807 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001808
Karl Rosaen138a0412009-04-23 19:00:21 -07001809 if (initialQuery == null) {
1810 // Use any text typed in the launcher as the initial query
1811 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001812 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001813 if (appSearchData == null) {
1814 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001815 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
Winson Chungadf0c182012-08-23 14:59:07 -07001817 Rect sourceBounds = new Rect();
1818 if (mSearchDropTargetBar != null) {
1819 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1820 }
Romain Guycbb89e42009-06-08 15:52:54 -07001821
Bjorn Bringertc459e522013-06-07 19:36:01 +01001822 startSearch(initialQuery, selectInitialQuery,
1823 appSearchData, sourceBounds);
1824 }
1825
1826 public void startSearch(String initialQuery,
1827 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001828 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001829 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001830 }
1831
1832 /**
1833 * Starts the global search activity. This code is a copied from SearchManager
1834 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001835 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001836 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001837 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001838 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1839 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1840 if (globalSearchActivity == null) {
1841 Log.w(TAG, "No global search activity found.");
1842 return;
1843 }
1844 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1845 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1846 intent.setComponent(globalSearchActivity);
1847 // Make sure that we have a Bundle to put source in
1848 if (appSearchData == null) {
1849 appSearchData = new Bundle();
1850 } else {
1851 appSearchData = new Bundle(appSearchData);
1852 }
1853 // Set source to package name of app that starts global search, if not set already.
1854 if (!appSearchData.containsKey("source")) {
1855 appSearchData.putString("source", getPackageName());
1856 }
1857 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1858 if (!TextUtils.isEmpty(initialQuery)) {
1859 intent.putExtra(SearchManager.QUERY, initialQuery);
1860 }
1861 if (selectInitialQuery) {
1862 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1863 }
1864 intent.setSourceBounds(sourceBounds);
1865 try {
1866 startActivity(intent);
1867 } catch (ActivityNotFoundException ex) {
1868 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1869 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 }
1871
Winson Chung70d72102011-08-12 11:24:35 -07001872 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001873 public boolean onPrepareOptionsMenu(Menu menu) {
1874 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001875 if (!mWorkspace.isInOverviewMode()) {
1876 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001877 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001878 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001879 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001881 @Override
1882 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001883 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001884 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001885 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001886 }
1887
Joe Onorato9c1289c2009-08-17 11:03:03 -04001888 public boolean isWorkspaceLocked() {
1889 return mWorkspaceLoading || mWaitingForResult;
1890 }
1891
Michael Jurka0280c3b2010-09-17 15:00:07 -07001892 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001893 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001894 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001895 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1896 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001897 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001898 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001899 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001900
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001901 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1902 AppWidgetProviderInfo appWidgetInfo) {
1903 if (appWidgetInfo.configure != null) {
1904 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001905
Bjorn Bringert7984c942009-12-09 15:38:25 +00001906 // Launch over to configure widget, if needed
1907 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001908 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001909 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001910 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001912 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001913 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001914 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001915 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001916 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 }
1918 }
Romain Guycbb89e42009-06-08 15:52:54 -07001919
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001920 protected void moveToCustomContentScreen(boolean animate) {
1921 mWorkspace.moveToCustomContentScreen(animate);
1922 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001923 /**
1924 * Process a shortcut drop.
1925 *
1926 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001927 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001928 * @param cell The cell it should be added to, optional
1929 * @param position The location on the screen where it was dropped, optional
1930 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001931 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001932 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001933 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001934 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001935 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001936 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001937
1938 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001939 mPendingAddInfo.cellX = cell[0];
1940 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001941 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001942
1943 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1944 createShortcutIntent.setComponent(componentName);
1945 processShortcut(createShortcutIntent);
1946 }
1947
Adam Cohenfbba09b2011-07-18 21:43:05 -07001948 /**
1949 * Process a widget drop.
1950 *
1951 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001952 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001953 * @param cell The cell it should be added to, optional
1954 * @param position The location on the screen where it was dropped, optional
1955 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001957 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001958 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001960 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001961 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001962 mPendingAddInfo.minSpanX = info.minSpanX;
1963 mPendingAddInfo.minSpanY = info.minSpanY;
1964
Adam Cohenfbba09b2011-07-18 21:43:05 -07001965 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 mPendingAddInfo.cellX = cell[0];
1967 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001968 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001969 if (span != null) {
1970 mPendingAddInfo.spanX = span[0];
1971 mPendingAddInfo.spanY = span[1];
1972 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001973
Adam Cohened66b2b2012-01-23 17:28:51 -08001974 AppWidgetHostView hostView = info.boundWidget;
1975 int appWidgetId;
1976 if (hostView != null) {
1977 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001978 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001979 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001980 // In this case, we either need to start an activity to get permission to bind
1981 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001982 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001983 Bundle options = info.bindOptions;
1984
1985 boolean success = false;
1986 if (options != null) {
1987 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1988 info.componentName, options);
1989 } else {
1990 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1991 info.componentName);
1992 }
1993 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001994 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001995 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001996 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001997 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1998 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1999 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002000 // TODO: we need to make sure that this accounts for the options bundle.
2001 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002002 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2003 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002004 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002005 }
2006
Joe Onoratodeb98af2010-02-19 14:59:39 -08002007 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002008 // Handle case where user selected "Applications"
2009 String applicationName = getResources().getString(R.string.group_applications);
2010 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002012 if (applicationName != null && applicationName.equals(shortcutName)) {
2013 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2014 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2017 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002018 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002019 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002020 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002021 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002022 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 }
2024
Winson Chung24ab2f12010-09-16 14:10:47 -07002025 void processWallpaper(Intent intent) {
2026 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2027 }
2028
Adam Cohendcd297f2013-06-18 13:13:40 -07002029 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002030 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002031 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002032 folderInfo.title = getText(R.string.folder_name);
2033
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002035 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002036 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002037 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038
2039 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 FolderIcon newFolder =
2041 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002042 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002043 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002044 // Force measure the new folder icon
2045 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2046 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002047 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 }
Romain Guycbb89e42009-06-08 15:52:54 -07002049
Joe Onorato9c1289c2009-08-17 11:03:03 -04002050 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002051 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002052 }
2053
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002054 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002055 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002057 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002058 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 }
2060
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002061 protected ComponentName getWallpaperPickerComponent() {
2062 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2063 }
2064
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002065 /**
2066 * Registers various content observers. The current implementation registers
2067 * only a favorites observer to keep track of the favorites applications.
2068 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002069 private void registerContentObservers() {
2070 ContentResolver resolver = getContentResolver();
2071 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2072 true, mWidgetObserver);
2073 }
2074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 @Override
2076 public boolean dispatchKeyEvent(KeyEvent event) {
2077 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2078 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002080 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002081 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002082 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002083 dumpState();
2084 return true;
2085 }
2086 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002087 }
2088 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2089 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002090 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 return true;
2092 }
2093 }
2094
2095 return super.dispatchKeyEvent(event);
2096 }
2097
Joe Onorato88ec0992009-11-19 13:16:06 -08002098 @Override
2099 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002100 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002101 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002102 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002103 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002104 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002105 Folder openFolder = mWorkspace.getOpenFolder();
2106 if (openFolder.isEditingName()) {
2107 openFolder.dismissEditingName();
2108 } else {
2109 closeFolder();
2110 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002111 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002112 mWorkspace.exitWidgetResizeMode();
2113
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002114 // Back button is a no-op here, but give at least some feedback for the button press
2115 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002116 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002117 }
2118
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002120 * Re-listen when widgets are reset.
2121 */
2122 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002123 if (mAppWidgetHost != null) {
2124 mAppWidgetHost.startListening();
2125 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002126 }
2127
2128 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002129 * Launches the intent referred by the clicked shortcut.
2130 *
2131 * @param v The view representing the clicked shortcut.
2132 */
2133 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002134 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2135 // view has detached (it's possible for this to happen if the view is removed mid touch).
2136 if (v.getWindowToken() == null) {
2137 return;
2138 }
2139
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002140 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002141 return;
2142 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002143
Adam Cohen1697b792013-09-17 19:08:21 -07002144 if (v instanceof Workspace) {
2145 if (mWorkspace.isInOverviewMode()) {
2146 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002147 }
2148 return;
2149 }
2150
2151 if (v instanceof CellLayout) {
2152 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002153 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002154 }
2155 }
2156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002158 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002160 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2161 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002162
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002163 // Check for special shortcuts
2164 if (intent.getComponent() != null) {
2165 final String shortcutClass = intent.getComponent().getClassName();
2166
2167 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002168 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002169 return;
2170 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2171 MemoryDumpActivity.startDump(this);
2172 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002173 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2174 toggleShowWeightWatcher();
2175 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002176 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002177 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002178
2179 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002180 int[] pos = new int[2];
2181 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002182 intent.setSourceBounds(new Rect(pos[0], pos[1],
2183 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002184
2185 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002186
Daniel Sandlerff02d492013-08-05 02:12:05 -04002187 mStats.recordLaunch(intent, shortcut);
2188
Michael Jurkaddd62e92011-02-16 17:49:14 -08002189 if (success && v instanceof BubbleTextView) {
2190 mWaitingForResume = (BubbleTextView) v;
2191 mWaitingForResume.setStayPressed(true);
2192 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002193 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002194 if (v instanceof FolderIcon) {
2195 FolderIcon fi = (FolderIcon) v;
2196 handleFolderClick(fi);
2197 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002198 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002199 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002200 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002201 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002202 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002203 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 }
2205 }
2206
Michael Jurka0e260592010-06-30 17:07:39 -07002207 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002208 return false;
2209 }
2210
Michael Jurkaaf442092010-06-10 17:01:57 -07002211 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002212 * Event handler for the search button
2213 *
2214 * @param v The view that was clicked.
2215 */
2216 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002217 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2218
Amith Yamasania135ba82011-08-09 17:42:01 -07002219 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002220 }
2221
2222 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002223 * Event handler for the voice button
2224 *
2225 * @param v The view that was clicked.
2226 */
2227 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002228 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002229
Bjorn Bringertc459e522013-06-07 19:36:01 +01002230 startVoice();
2231 }
2232
2233 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002234 try {
2235 final SearchManager searchManager =
2236 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2237 ComponentName activityName = searchManager.getGlobalSearchActivity();
2238 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002239 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002240 if (activityName != null) {
2241 intent.setPackage(activityName.getPackageName());
2242 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002243 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002244 } catch (ActivityNotFoundException e) {
2245 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002246 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002247 startActivitySafely(null, intent, "onClickVoiceButton");
2248 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002249 }
2250
2251 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002252 * Event handler for the "grid" button that appears on the home screen, which
2253 * enters all apps mode.
2254 *
2255 * @param v The view that was clicked.
2256 */
2257 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002258 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002259 }
2260
2261 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002262 // Provide the same haptic feedback that the system offers for virtual keys.
2263 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002264 }
2265
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002266 public void onClickAppMarketButton(View v) {
2267 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002268 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002269 } else {
2270 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002271 }
2272 }
2273
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002274 /**
2275 * Called when the user stops interacting with the launcher.
2276 * This implies that the user is now on the homescreen and is not doing housekeeping.
2277 */
2278 protected void onInteractionEnd() {}
2279
2280 /**
2281 * Called when the user starts interacting with the launcher.
2282 * The possible interactions are:
2283 * - open all apps
2284 * - reorder an app shortcut, or a widget
2285 * - open the overview mode.
2286 * This is a good time to stop doing things that only make sense
2287 * when the user is on the homescreen and not doing housekeeping.
2288 */
2289 protected void onInteractionBegin() {}
2290
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002291 void startApplicationDetailsActivity(ComponentName componentName) {
2292 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002293 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2294 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002295 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002296 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002297 }
2298
Michael Jurka1e2f4652013-07-08 18:03:46 -07002299 // returns true if the activity was started
2300 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002301 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002302 // System applications cannot be installed. For now, show a toast explaining that.
2303 // We may give them the option of disabling apps this way.
2304 int messageId = R.string.uninstall_system_app_text;
2305 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002306 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002307 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002308 String packageName = componentName.getPackageName();
2309 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002310 Intent intent = new Intent(
2311 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002312 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2313 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002314 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002315 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002316 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002317 }
2318
Michael Jurka86a720e2012-05-09 11:23:23 -07002319 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002323 // Only launch using the new animation if the shortcut has not opted out (this is a
2324 // private contract between launcher and may be ignored in the future).
2325 boolean useLaunchAnimation = (v != null) &&
2326 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2327 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002328 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2329 v.getMeasuredWidth(), v.getMeasuredHeight());
2330
2331 startActivity(intent, opts.toBundle());
2332 } else {
2333 startActivity(intent);
2334 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002335 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 } catch (SecurityException e) {
2337 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002338 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002340 "or use the exported attribute for this activity. "
2341 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002343 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002344 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002345
Michael Jurka86a720e2012-05-09 11:23:23 -07002346 boolean startActivitySafely(View v, Intent intent, Object tag) {
2347 boolean success = false;
2348 try {
2349 success = startActivity(v, intent, tag);
2350 } catch (ActivityNotFoundException e) {
2351 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2352 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2353 }
2354 return success;
2355 }
2356
Adam Cohena9cf38f2011-05-02 15:36:58 -07002357 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002358 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002359 Folder openFolder = mWorkspace.getFolderForTag(info);
2360
2361 // If the folder info reports that the associated folder is open, then verify that
2362 // it is actually opened. There have been a few instances where this gets out of sync.
2363 if (info.opened && openFolder == null) {
2364 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002365 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002366 info.opened = false;
2367 }
2368
Adam Cohenfb91f302012-06-11 15:45:18 -07002369 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 // Close any open folder
2371 closeFolder();
2372 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002373 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 } else {
2375 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376 int folderScreen;
2377 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002378 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 // .. and close it
2380 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002381 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 // Close any folder open on the current screen
2383 closeFolder();
2384 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002385 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 }
2387 }
2388 }
2389 }
2390
Adam Cohen268c4752012-06-06 17:47:33 -07002391 /**
2392 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2393 * in the DragLayer in the exact absolute location of the original FolderIcon.
2394 */
2395 private void copyFolderIconToImage(FolderIcon fi) {
2396 final int width = fi.getMeasuredWidth();
2397 final int height = fi.getMeasuredHeight();
2398
2399 // Lazy load ImageView, Bitmap and Canvas
2400 if (mFolderIconImageView == null) {
2401 mFolderIconImageView = new ImageView(this);
2402 }
2403 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2404 mFolderIconBitmap.getHeight() != height) {
2405 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2406 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2407 }
2408
2409 DragLayer.LayoutParams lp;
2410 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2411 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2412 } else {
2413 lp = new DragLayer.LayoutParams(width, height);
2414 }
2415
Adam Cohen307fe232012-08-16 17:55:58 -07002416 // The layout from which the folder is being opened may be scaled, adjust the starting
2417 // view size by this scale factor.
2418 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002419 lp.customPosition = true;
2420 lp.x = mRectForFolderAnimation.left;
2421 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002422 lp.width = (int) (scale * width);
2423 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002424
2425 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2426 fi.draw(mFolderIconCanvas);
2427 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002428 if (fi.getFolder() != null) {
2429 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2430 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002431 }
Adam Cohen268c4752012-06-06 17:47:33 -07002432 // Just in case this image view is still in the drag layer from a previous animation,
2433 // we remove it and re-add it.
2434 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2435 mDragLayer.removeView(mFolderIconImageView);
2436 }
2437 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002438 if (fi.getFolder() != null) {
2439 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002440 }
Adam Cohen268c4752012-06-06 17:47:33 -07002441 }
2442
Adam Cohen2801caf2011-05-13 20:57:39 -07002443 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002444 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002445 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2446 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2447 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2448
Adam Cohenc51934b2011-07-26 21:07:43 -07002449 FolderInfo info = (FolderInfo) fi.getTag();
2450 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2451 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002452 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2453 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002454 }
2455
Adam Cohen268c4752012-06-06 17:47:33 -07002456 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2457 copyFolderIconToImage(fi);
2458 fi.setVisibility(View.INVISIBLE);
2459
Michael Jurka2ecf9952012-06-18 12:52:28 -07002460 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002461 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002462 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2463 oa.start();
2464 }
2465
Adam Cohen268c4752012-06-06 17:47:33 -07002466 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002467 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002468 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2469 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2470 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2471
Adam Cohen268c4752012-06-06 17:47:33 -07002472 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002473
Adam Cohen268c4752012-06-06 17:47:33 -07002474 // We remove and re-draw the FolderIcon in-case it has changed
2475 mDragLayer.removeView(mFolderIconImageView);
2476 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002477 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002478 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002479 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002480 oa.addListener(new AnimatorListenerAdapter() {
2481 @Override
2482 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002483 if (cl != null) {
2484 cl.clearFolderLeaveBehind();
2485 // Remove the ImageView copy of the FolderIcon and make the original visible.
2486 mDragLayer.removeView(mFolderIconImageView);
2487 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002488 }
2489 }
2490 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002491 oa.start();
2492 }
2493
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002494 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002495 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002496 * is animated relative to the specified View. If the View is null, no animation
2497 * is played.
2498 *
2499 * @param folderInfo The FolderInfo describing the folder to open.
2500 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002501 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002502 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002503 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002504
Adam Cohena9cf38f2011-05-02 15:36:58 -07002505 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002506
Adam Cohen4554ee12011-08-03 16:13:21 -07002507 // Just verify that the folder hasn't already been added to the DragLayer.
2508 // There was a one-off crash where the folder had a parent already.
2509 if (folder.getParent() == null) {
2510 mDragLayer.addView(folder);
2511 mDragController.addDropTarget((DropTarget) folder);
2512 } else {
2513 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2514 folder.getParent() + ").");
2515 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002517 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002518
2519 // Notify the accessibility manager that this folder "window" has appeared and occluded
2520 // the workspace items
2521 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2522 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002523 }
2524
2525 public void closeFolder() {
2526 Folder folder = mWorkspace.getOpenFolder();
2527 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002528 if (folder.isEditingName()) {
2529 folder.dismissEditingName();
2530 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002531 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002532
2533 // Dismiss the folder cling
2534 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002535 }
2536 }
2537
2538 void closeFolder(Folder folder) {
2539 folder.getInfo().opened = false;
2540
2541 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2542 if (parent != null) {
2543 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2544 shrinkAndFadeInFolderIcon(fi);
2545 }
2546 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002547
2548 // Notify the accessibility manager that this folder "window" has disappeard and no
2549 // longer occludeds the workspace items
2550 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002551 }
2552
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002553 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002554 if (!isDraggingEnabled()) return false;
2555 if (isWorkspaceLocked()) return false;
2556 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557
Adam Cohen1697b792013-09-17 19:08:21 -07002558 if (v instanceof Workspace) {
2559 if (!mWorkspace.isInOverviewMode()) {
2560 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2561 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2562 mWorkspace.enterOverviewMode();
2563 }
2564 return true;
2565 }
2566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002568 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 }
2570
Michael Jurka0280c3b2010-09-17 15:00:07 -07002571 resetAddInfo();
2572 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002573 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002574 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002575 return true;
2576 }
2577
Winson Chung3d503fb2011-07-13 17:25:49 -07002578 // The hotseat touch handling does not go through Workspace, and we always allow long press
2579 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002580 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002581 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2582 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002583 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002584 // User long pressed on empty space
2585 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2586 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2587 // Disabling reordering until we sort out some issues.
2588 if (mWorkspace.isInOverviewMode()) {
2589 mWorkspace.startReordering(v);
2590 } else {
2591 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002592 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002594 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002595 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002596 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002597 }
2598 }
2599 }
2600 return true;
2601 }
2602
Winson Chung3d503fb2011-07-13 17:25:49 -07002603 boolean isHotseatLayout(View layout) {
2604 return mHotseat != null && layout != null &&
2605 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2606 }
2607 Hotseat getHotseat() {
2608 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002609 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002610 View getOverviewPanel() {
2611 return mOverviewPanel;
2612 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002613 SearchDropTargetBar getSearchBar() {
2614 return mSearchDropTargetBar;
2615 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002616
Winson Chung3d503fb2011-07-13 17:25:49 -07002617 /**
2618 * Returns the CellLayout of the specified container at the specified screen.
2619 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002620 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002621 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2622 if (mHotseat != null) {
2623 return mHotseat.getLayout();
2624 } else {
2625 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002626 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002627 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002628 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002629 }
2630 }
2631
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002632 Workspace getWorkspace() {
2633 return mWorkspace;
2634 }
2635
Daniel Sandler843e8602010-06-07 14:59:01 -04002636 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002637 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002638 }
2639
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002640 /**
2641 * Helper method for the cameraZoomIn/cameraZoomOut animations
2642 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 * @param scaleFactor The scale factor used for the zoom
2644 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002645 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002647 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002648 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002649
Craig Mautner360310b2012-10-26 15:13:08 -07002650 private void setWorkspaceBackground(boolean workspace) {
2651 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002652 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002653 }
2654
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002655 void updateWallpaperVisibility(boolean visible) {
2656 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2657 int curflags = getWindow().getAttributes().flags
2658 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2659 if (wpflags != curflags) {
2660 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2661 }
Craig Mautner360310b2012-10-26 15:13:08 -07002662 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002663 }
2664
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002665 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2666 if (v instanceof LauncherTransitionable) {
2667 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2668 }
2669 }
2670
Michael Jurkabed61d22012-02-14 22:51:29 -08002671 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2672 if (v instanceof LauncherTransitionable) {
2673 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2674 }
Winson Chung70442722012-02-10 15:43:22 -08002675
2676 // Update the workspace transition step as well
2677 dispatchOnLauncherTransitionStep(v, 0f);
2678 }
2679
2680 private void dispatchOnLauncherTransitionStep(View v, float t) {
2681 if (v instanceof LauncherTransitionable) {
2682 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2683 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002684 }
2685
2686 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2687 if (v instanceof LauncherTransitionable) {
2688 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2689 }
Winson Chung70442722012-02-10 15:43:22 -08002690
2691 // Update the workspace transition step as well
2692 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002693 }
2694
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002695 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002696 * Things to test when changing the following seven functions.
2697 * - Home from workspace
2698 * - from center screen
2699 * - from other screens
2700 * - Home from all apps
2701 * - from center screen
2702 * - from other screens
2703 * - Back from all apps
2704 * - from center screen
2705 * - from other screens
2706 * - Launch app from workspace and quit
2707 * - with back
2708 * - with home
2709 * - Launch app from all apps and quit
2710 * - with back
2711 * - with home
2712 * - Go to a screen that's not the default, then all
2713 * apps, and launch and app, and go back
2714 * - with back
2715 * -with home
2716 * - On workspace, long press power and go back
2717 * - with back
2718 * - with home
2719 * - On all apps, long press power and go back
2720 * - with back
2721 * - with home
2722 * - On workspace, power off
2723 * - On all apps, power off
2724 * - Launch an app and turn off the screen while in that app
2725 * - Go back with home key
2726 * - Go back with back key TODO: make this not go to workspace
2727 * - From all apps
2728 * - From workspace
2729 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2730 * - From all apps
2731 * - From the center workspace
2732 * - From another workspace
2733 */
2734
2735 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002736 * Zoom the camera out from the workspace to reveal 'toView'.
2737 * Assumes that the view to show is anchored at either the very top or very bottom
2738 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002739 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002740 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002741 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2742 showAppsCustomizeHelper(animated, springLoaded, contentType);
2743 }
2744 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2745 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002746 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002747 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002748 mStateAnimation.cancel();
2749 mStateAnimation = null;
2750 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002751 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002752
Winson Chungf0ea4d32011-06-06 14:27:16 -07002753 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2754 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2755 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002756 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002757 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002758 final int startDelay =
2759 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002760
Michael Jurkab3e22d92011-10-31 15:58:33 -07002761 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002762
Michael Jurkad74c9842011-07-10 12:44:21 -07002763 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002764 Animator workspaceAnim =
2765 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002766 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2767 // Set the content type for the all apps space
2768 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2769 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002770
2771 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002772 toView.setScaleX(scale);
2773 toView.setScaleY(scale);
2774 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2775 scaleAnim.
2776 scaleX(1f).scaleY(1f).
2777 setDuration(duration).
2778 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002779
Winson Chungf0ea4d32011-06-06 14:27:16 -07002780 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002781 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002782 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002783 .ofFloat(toView, "alpha", 0f, 1f)
2784 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002785 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002786 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2787 @Override
2788 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002789 if (animation == null) {
2790 throw new RuntimeException("animation is null");
2791 }
Winson Chung70442722012-02-10 15:43:22 -08002792 float t = (Float) animation.getAnimatedValue();
2793 dispatchOnLauncherTransitionStep(fromView, t);
2794 dispatchOnLauncherTransitionStep(toView, t);
2795 }
2796 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002797
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002798 // toView should appear right at the end of the workspace shrink
2799 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002800 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002801 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002802 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002803
2804 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002805 boolean animationCancelled = false;
2806
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002807 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002808 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002809 // Prepare the position
2810 toView.setTranslationX(0.0f);
2811 toView.setTranslationY(0.0f);
2812 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002813 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002814 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002815 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002816 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002817 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2818 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002819
Winson Chungc7d2b602012-05-16 17:02:20 -07002820 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002821 if (mSearchDropTargetBar != null) {
2822 mSearchDropTargetBar.hideSearchBar(false);
2823 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002824 }
2825
Adam Cohencff6af82011-09-13 14:51:53 -07002826 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002827 public void onAnimationCancel(Animator animation) {
2828 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002829 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002830 });
2831
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002832 if (workspaceAnim != null) {
2833 mStateAnimation.play(workspaceAnim);
2834 }
Michael Jurka1899a362011-11-03 13:50:45 -07002835
2836 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002837
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002838 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2839 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002840
2841 // If any of the objects being animated haven't been measured/laid out
2842 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002843 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002844 (mWorkspace.getMeasuredWidth() == 0) ||
2845 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002846 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002847 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002848
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002849 final AnimatorSet stateAnimation = mStateAnimation;
2850 final Runnable startAnimRunnable = new Runnable() {
2851 public void run() {
2852 // Check that mStateAnimation hasn't changed while
2853 // we waited for a layout/draw pass
2854 if (mStateAnimation != stateAnimation)
2855 return;
2856 setPivotsForZoom(toView, scale);
2857 dispatchOnLauncherTransitionStart(fromView, animated, false);
2858 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002859 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002860 }
2861 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002862 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002863 final ViewTreeObserver observer = toView.getViewTreeObserver();
2864 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2865 public void onGlobalLayout() {
2866 startAnimRunnable.run();
2867 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2868 }
2869 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002870 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002871 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002872 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002873 } else {
2874 toView.setTranslationX(0.0f);
2875 toView.setTranslationY(0.0f);
2876 toView.setScaleX(1.0f);
2877 toView.setScaleY(1.0f);
2878 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002879 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002880
Daniel Sandlere4f98912013-06-25 15:13:26 -04002881 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002882 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002883 if (mSearchDropTargetBar != null) {
2884 mSearchDropTargetBar.hideSearchBar(false);
2885 }
Michael Jurkaabded662011-03-04 12:06:57 -08002886 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002887 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002888 dispatchOnLauncherTransitionStart(fromView, animated, false);
2889 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002890 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002891 dispatchOnLauncherTransitionStart(toView, animated, false);
2892 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002893 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002894 }
2895
2896 /**
2897 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002898 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002899 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002900 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002901 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2902 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002903
Michael Jurkab3e22d92011-10-31 15:58:33 -07002904 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002905 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002906 mStateAnimation.cancel();
2907 mStateAnimation = null;
2908 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002909 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002910
Winson Chungf0ea4d32011-06-06 14:27:16 -07002911 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002912 final int fadeOutDuration =
2913 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002914 final float scaleFactor = (float)
2915 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2916 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002917 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002918 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002919 if (toState == State.WORKSPACE) {
2920 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2921 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002922 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002923 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2924 workspaceAnim = mWorkspace.getChangeStateAnimation(
2925 Workspace.State.SPRING_LOADED, animated);
2926 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002927
Michael Jurkab3e22d92011-10-31 15:58:33 -07002928 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002929 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002930 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002931 final LauncherViewPropertyAnimator scaleAnim =
2932 new LauncherViewPropertyAnimator(fromView);
2933 scaleAnim.
2934 scaleX(scaleFactor).scaleY(scaleFactor).
2935 setDuration(duration).
2936 setInterpolator(new Workspace.ZoomInInterpolator());
2937
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002938 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002939 .ofFloat(fromView, "alpha", 1f, 0f)
2940 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002941 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002942 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2943 @Override
2944 public void onAnimationUpdate(ValueAnimator animation) {
2945 float t = 1f - (Float) animation.getAnimatedValue();
2946 dispatchOnLauncherTransitionStep(fromView, t);
2947 dispatchOnLauncherTransitionStep(toView, t);
2948 }
2949 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002950
Michael Jurka2ecf9952012-06-18 12:52:28 -07002951 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002952
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002953 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2954 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002955 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002956
2957 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002958 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002959 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002960 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002961 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2962 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002963 if (onCompleteRunnable != null) {
2964 onCompleteRunnable.run();
2965 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002966 mAppsCustomizeContent.updateCurrentPageScroll();
2967 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002968 }
2969 });
2970
Winson Chungf0ea4d32011-06-06 14:27:16 -07002971 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002972 if (workspaceAnim != null) {
2973 mStateAnimation.play(workspaceAnim);
2974 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002975 dispatchOnLauncherTransitionStart(fromView, animated, true);
2976 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002977 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002978 } else {
2979 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002980 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002981 dispatchOnLauncherTransitionStart(fromView, animated, true);
2982 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002983 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002984 dispatchOnLauncherTransitionStart(toView, animated, true);
2985 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002986 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002987 }
2988
Michael Jurkae326f182011-11-21 14:05:46 -08002989 @Override
2990 public void onTrimMemory(int level) {
2991 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002992 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002993 mAppsCustomizeTabHost.onTrimMemory();
2994 }
2995 }
2996
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002997 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002998 showWorkspace(animated, null);
2999 }
3000
3001 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003002 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003003 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003004 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003005 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003006
Winson Chungc7d2b602012-05-16 17:02:20 -07003007 // Show the search bar (only animate if we were showing the drop target bar in spring
3008 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003009 if (mSearchDropTargetBar != null) {
3010 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3011 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003012
Michael Jurkab3e22d92011-10-31 15:58:33 -07003013 // Set focus to the AppsCustomize button
3014 if (mAllAppsButton != null) {
3015 mAllAppsButton.requestFocus();
3016 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003017 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003018
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003019 // Change the state *after* we've called all the transition code
3020 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003021
Winson Chung5fb63472011-02-02 17:03:37 -08003022 // Resume the auto-advance of widgets
3023 mUserPresent = true;
3024 updateRunning();
3025
alanv1d4fde62012-10-17 13:15:47 -07003026 // Send an accessibility event to announce the context change
3027 getWindow().getDecorView()
3028 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003029
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003030 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003031 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003032 }
3033
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003034 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003035 }
3036
Winson Chungc58497e2013-09-03 17:48:37 -07003037 void showAllApps(boolean animated,
3038 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003039 if (mState != State.WORKSPACE) return;
3040
Winson Chungc58497e2013-09-03 17:48:37 -07003041 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003042 mAppsCustomizeTabHost.requestFocus();
3043
Michael Jurkab3e22d92011-10-31 15:58:33 -07003044 // Change the state *after* we've called all the transition code
3045 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003046 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003047
3048 // Pause the auto-advance of widgets until we are out of AllApps
3049 mUserPresent = false;
3050 updateRunning();
3051 closeFolder();
3052
3053 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003054 getWindow().getDecorView()
3055 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003056 }
3057
Adam Cohen7777d962011-08-18 18:58:38 -07003058 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003059 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003060 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003061 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003062 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003063 }
Adam Cohen7777d962011-08-18 18:58:38 -07003064
Adam Cohened66b2b2012-01-23 17:28:51 -08003065 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3066 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003067 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3068
Winson Chunge7a03942011-08-05 15:05:12 -07003069 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003070 @Override
3071 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003072 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003073 // Before we show workspace, hide all apps again because
3074 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3075 // clean up our state transition functions
3076 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003077 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003078 } else {
3079 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003080 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003081 }
3082 }, (extendedDelay ?
3083 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3084 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3085 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003086
Michael Jurkad3ef3062010-11-23 16:23:58 -08003087 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003088 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003089 final boolean animated = true;
3090 final boolean springLoaded = true;
3091 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003092 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003093 }
3094 // Otherwise, we are not in spring loaded mode, so don't do anything.
3095 }
3096
Michael Jurkab3e22d92011-10-31 15:58:33 -07003097 void lockAllApps() {
3098 // TODO
3099 }
3100
3101 void unlockAllApps() {
3102 // TODO
3103 }
3104
Winson Chungf0ea4d32011-06-06 14:27:16 -07003105 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003106 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003107 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003108 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003109 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003110 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003111 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003112 int duration = 0;
3113 if (mSearchDropTargetBar != null) {
3114 duration = mSearchDropTargetBar.getTransitionInDuration();
3115 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003116 mHotseat.animate().alpha(1f).setDuration(duration);
3117 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003118 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003119 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003120 }
3121 }
3122 }
3123
3124 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003125 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003126 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003127 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003128 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003129 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003130 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003131 int duration = 0;
3132 if (mSearchDropTargetBar != null) {
3133 duration = mSearchDropTargetBar.getTransitionOutDuration();
3134 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003135 mHotseat.animate().alpha(0f).setDuration(duration);
3136 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003137 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003138 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003139 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003140 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003141 }
3142
Patrick Dubroy5f445422011-02-18 14:35:21 -08003143 /**
3144 * Add an item from all apps or customize onto the given workspace screen.
3145 * If layout is null, add to the current screen.
3146 */
3147 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003148 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003149 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003150 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003151 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003152
Winson Chungdff8ebb2011-09-08 17:25:31 -07003153 /** Maps the current orientation to an index for referencing orientation correct global icons */
3154 private int getCurrentOrientationIndexForGlobalIcons() {
3155 // default - 0, landscape - 1
3156 switch (getResources().getConfiguration().orientation) {
3157 case Configuration.ORIENTATION_LANDSCAPE:
3158 return 1;
3159 default:
3160 return 0;
3161 }
3162 }
3163
Michael Jurkaae65ee32012-04-30 11:45:54 -07003164 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003165 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003166 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003167 // Look for the toolbar icon specified in the activity meta-data
3168 Bundle metaData = packageManager.getActivityInfo(
3169 activityName, PackageManager.GET_META_DATA).metaData;
3170 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003171 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003172 if (iconResId != 0) {
3173 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003174 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003175 }
3176 }
3177 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003178 // This can happen if the activity defines an invalid drawable
3179 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3180 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003181 } catch (Resources.NotFoundException nfe) {
3182 // This can happen if the activity defines an invalid drawable
3183 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3184 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003185 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003186 return null;
3187 }
3188
3189 // if successful in getting icon, return it; otherwise, set button to use default drawable
3190 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003191 int buttonId, ComponentName activityName, int fallbackDrawableId,
3192 String toolbarResourceName) {
3193 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003194 Resources r = getResources();
3195 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3196 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003197
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003198 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003199 // If we were unable to find the icon via the meta-data, use a generic one
3200 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003201 toolbarIcon = r.getDrawable(fallbackDrawableId);
3202 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003203 if (button != null) {
3204 button.setCompoundDrawables(toolbarIcon, null, null, null);
3205 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003206 return null;
3207 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003208 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003209 if (button != null) {
3210 button.setCompoundDrawables(toolbarIcon, null, null, null);
3211 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003212 return toolbarIcon.getConstantState();
3213 }
3214 }
3215
3216 // if successful in getting icon, return it; otherwise, set button to use default drawable
3217 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003218 int buttonId, ComponentName activityName, int fallbackDrawableId,
3219 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003220 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003221 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003222
Michael Jurka19e0fc52011-07-22 18:00:21 -07003223 if (button != null) {
3224 // If we were unable to find the icon via the meta-data, use a
3225 // generic one
3226 if (toolbarIcon == null) {
3227 button.setImageResource(fallbackDrawableId);
3228 } else {
3229 button.setImageDrawable(toolbarIcon);
3230 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003231 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003232
3233 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3234
Michael Jurka0423dcf2010-10-05 14:56:18 -07003235 }
3236
Winson Chung1b884092012-06-08 17:13:02 -07003237 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003238 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003239 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003240 }
3241
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003242 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003243 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003244 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003245 }
3246
Winson Chungbb185bd2011-11-21 12:31:42 -08003247 private void invalidatePressedFocusedStates(View container, View button) {
3248 if (container instanceof HolographicLinearLayout) {
3249 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3250 layout.invalidatePressedFocusedStates();
3251 } else if (button instanceof HolographicImageView) {
3252 HolographicImageView view = (HolographicImageView) button;
3253 view.invalidatePressedFocusedStates();
3254 }
3255 }
3256
Cristina Stancu476493b2013-08-07 17:20:14 +01003257 public View getQsbBar() {
3258 if (mQsbBar == null) {
3259 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3260 }
3261 return mQsbBar;
3262 }
3263
3264 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003265 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003266 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003267 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003268 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003269
Winson Chung1cad91e2011-05-25 17:41:01 -07003270 final SearchManager searchManager =
3271 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3272 ComponentName activityName = searchManager.getGlobalSearchActivity();
3273 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003274 int coi = getCurrentOrientationIndexForGlobalIcons();
3275 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003276 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3277 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3278 if (sGlobalSearchIcon[coi] == null) {
3279 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3280 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3281 TOOLBAR_ICON_METADATA_NAME);
3282 }
3283
Winson Chungc51db6a2011-10-05 11:44:49 -07003284 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3285 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003286 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003287 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003288 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003289 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003290 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3291 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003292 if (searchButton != null) searchButton.setVisibility(View.GONE);
3293 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003294 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003295 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003296 }
3297 }
3298
Cristina Stancu476493b2013-08-07 17:20:14 +01003299 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003300 final View searchButtonContainer = findViewById(R.id.search_button_container);
3301 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003302 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003303 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003304 }
3305
Cristina Stancu476493b2013-08-07 17:20:14 +01003306 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003307 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003308 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003309
Winson Chungc51db6a2011-10-05 11:44:49 -07003310 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003311 final SearchManager searchManager =
3312 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3313 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3314
3315 ComponentName activityName = null;
3316 if (globalSearchActivity != null) {
3317 // Check if the global search activity handles voice search
3318 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3319 intent.setPackage(globalSearchActivity.getPackageName());
3320 activityName = intent.resolveActivity(getPackageManager());
3321 }
3322
3323 if (activityName == null) {
3324 // Fallback: check if an activity other than the global search activity
3325 // resolves this
3326 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3327 activityName = intent.resolveActivity(getPackageManager());
3328 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003329 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003330 int coi = getCurrentOrientationIndexForGlobalIcons();
3331 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003332 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3333 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3334 if (sVoiceSearchIcon[coi] == null) {
3335 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3336 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3337 TOOLBAR_ICON_METADATA_NAME);
3338 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003339 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003340 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003341 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003342 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003343 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003344 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003345 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003346 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003347 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003348 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003349 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003350 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003351
Cristina Stancu476493b2013-08-07 17:20:14 +01003352 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003353 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3354 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003355 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003356 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003357 }
3358
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003359 public void setVoiceButtonProxyVisible(boolean visible) {
3360 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3361 if (voiceButtonProxy != null) {
3362 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3363 }
3364 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003365 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003366 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003367 */
3368 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003369 final View marketButton = findViewById(R.id.market_button);
3370 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3371 // Find the app market activity by resolving an intent.
3372 // (If multiple app markets are installed, it will return the ResolverActivity.)
3373 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003374 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003375 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003376 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003377 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003378 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3379 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003380 marketButton.setVisibility(View.VISIBLE);
3381 } else {
3382 // We should hide and disable the view so that we don't try and restore the visibility
3383 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3384 marketButton.setVisibility(View.GONE);
3385 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003386 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003387 }
3388
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003389 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003390 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3391 Resources r = getResources();
3392 Drawable marketIconDrawable = d.newDrawable(r);
3393 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3394 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3395 marketIconDrawable.setBounds(0, 0, w, h);
3396
3397 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003398 }
3399
Michael Jurkad7c28052012-04-27 15:43:36 -07003400 @Override
3401 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003402 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003403 final List<CharSequence> text = event.getText();
3404 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003405 // Populate event with a fake title based on the current state.
3406 if (mState == State.APPS_CUSTOMIZE) {
3407 text.add(getString(R.string.all_apps_button_label));
3408 } else {
3409 text.add(getString(R.string.all_apps_home_button_label));
3410 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003411 return result;
3412 }
3413
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003414 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003415 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003416 */
3417 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3418 @Override
3419 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003420 closeSystemDialogs();
3421 }
3422 }
3423
3424 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003425 * Receives notifications whenever the appwidgets are reset.
3426 */
3427 private class AppWidgetResetObserver extends ContentObserver {
3428 public AppWidgetResetObserver() {
3429 super(new Handler());
3430 }
3431
3432 @Override
3433 public void onChange(boolean selfChange) {
3434 onAppWidgetReset();
3435 }
3436 }
3437
3438 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003439 * If the activity is currently paused, signal that we need to run the passed Runnable
3440 * in onResume.
3441 *
3442 * This needs to be called from incoming places where resources might have been loaded
3443 * while we are paused. That is becaues the Configuration might be wrong
3444 * when we're not running, and if it comes back to what it was when we
3445 * were paused, we are not restarted.
3446 *
3447 * Implementation of the method from LauncherModel.Callbacks.
3448 *
3449 * @return true if we are currently paused. The caller might be able to
3450 * skip some work in that case since we will come back again.
3451 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003452 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003453 if (mPaused) {
3454 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003455 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003456 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003457 }
3458 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003459 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003460 return true;
3461 } else {
3462 return false;
3463 }
3464 }
3465
Michael Jurkac402cd92013-05-20 15:49:32 +02003466 private boolean waitUntilResume(Runnable run) {
3467 return waitUntilResume(run, false);
3468 }
3469
Michael Jurka1e2f4652013-07-08 18:03:46 -07003470 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003471 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003472 }
3473
Michael Jurka7607c2f2013-04-03 14:33:19 -07003474 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003475 * If the activity is currently paused, signal that we need to re-run the loader
3476 * in onResume.
3477 *
3478 * This needs to be called from incoming places where resources might have been loaded
3479 * while we are paused. That is becaues the Configuration might be wrong
3480 * when we're not running, and if it comes back to what it was when we
3481 * were paused, we are not restarted.
3482 *
3483 * Implementation of the method from LauncherModel.Callbacks.
3484 *
3485 * @return true if we are currently paused. The caller might be able to
3486 * skip some work in that case since we will come back again.
3487 */
3488 public boolean setLoadOnResume() {
3489 if (mPaused) {
3490 Log.i(TAG, "setLoadOnResume");
3491 mOnResumeNeedsLoad = true;
3492 return true;
3493 } else {
3494 return false;
3495 }
3496 }
3497
3498 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003499 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003500 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003501 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003502 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003503 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003504 } else {
3505 return SCREEN_COUNT / 2;
3506 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003507 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003508
Joe Onorato9c1289c2009-08-17 11:03:03 -04003509 /**
3510 * Refreshes the shortcuts shown on the workspace.
3511 *
3512 * Implementation of the method from LauncherModel.Callbacks.
3513 */
3514 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003515 // If we're starting binding all over again, clear any bind calls we'd postponed in
3516 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3517 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003518 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003519
Winson Chungd64d1762013-08-20 14:37:16 -07003520 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003521 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003522 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003523
Michael Jurka05bf644e2011-11-30 20:28:53 -08003524 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003525 if (mHotseat != null) {
3526 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003527 }
3528 }
3529
Adam Cohendcd297f2013-06-18 13:13:40 -07003530 @Override
3531 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003532 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003533
Adam Cohen5084cba2013-09-03 12:01:16 -07003534 // If there are no screens, we need to have an empty screen
3535 if (orderedScreenIds.size() == 0) {
3536 mWorkspace.addExtraEmptyScreen();
3537 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003538
3539 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003540 // setCurrentPage() so ensure that all pages are added before calling this).
3541 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003542 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3543 mWorkspace.createCustomContentPage();
3544 }
Winson Chung64359a52013-07-08 17:17:08 -07003545 }
3546
3547 @Override
3548 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003549 int count = orderedScreenIds.size();
3550 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003551 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003552 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003553 }
3554
Adam Cohen39a06042013-07-19 14:30:12 -07003555 private boolean shouldShowWeightWatcher() {
3556 String spKey = LauncherAppState.getSharedPreferencesKey();
3557 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003558 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003559
3560 return show;
3561 }
3562
Adam Cohen4caf2982013-08-20 18:54:31 -07003563 private boolean emailSent() {
3564 String spKey = LauncherAppState.getSharedPreferencesKey();
3565 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3566 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3567 return show;
3568 }
3569
3570 private void setEmailSent(boolean sent) {
3571 String spKey = LauncherAppState.getSharedPreferencesKey();
3572 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3573
3574 SharedPreferences.Editor editor = sp.edit();
3575 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3576 editor.commit();
3577 }
3578
Adam Cohen39a06042013-07-19 14:30:12 -07003579 private void toggleShowWeightWatcher() {
3580 String spKey = LauncherAppState.getSharedPreferencesKey();
3581 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3582 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3583
3584 show = !show;
3585
3586 SharedPreferences.Editor editor = sp.edit();
3587 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3588 editor.commit();
3589
3590 if (mWeightWatcher != null) {
3591 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3592 }
3593 }
3594
Winson Chungd64d1762013-08-20 14:37:16 -07003595 public void bindAppsAdded(final ArrayList<Long> newScreens,
3596 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003597 final ArrayList<ItemInfo> addAnimated,
3598 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003599 Runnable r = new Runnable() {
3600 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003601 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003602 }
3603 };
3604 if (waitUntilResume(r)) {
3605 return;
3606 }
3607
Winson Chungd64d1762013-08-20 14:37:16 -07003608 // Add the new screens
3609 bindAddScreens(newScreens);
3610
3611 // We add the items without animation on non-visible pages, and with
3612 // animations on the new page (which we will try and snap to).
3613 if (!addNotAnimated.isEmpty()) {
3614 bindItems(addNotAnimated, 0,
3615 addNotAnimated.size(), false);
3616 }
3617 if (!addAnimated.isEmpty()) {
3618 bindItems(addAnimated, 0,
3619 addAnimated.size(), true);
3620 }
Winson Chungc58497e2013-09-03 17:48:37 -07003621
3622 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3623 addedApps != null && mAppsCustomizeContent != null) {
3624 mAppsCustomizeContent.addApps(addedApps);
3625 }
Winson Chungd64d1762013-08-20 14:37:16 -07003626 }
3627
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003628 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003629 * Bind the items start-end from the list.
3630 *
3631 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003632 */
Winson Chung64359a52013-07-08 17:17:08 -07003633 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3634 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003635 Runnable r = new Runnable() {
3636 public void run() {
3637 bindItems(shortcuts, start, end, forceAnimateIcons);
3638 }
3639 };
3640 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003641 return;
3642 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003643
Winson Chungf0c6ae02012-03-21 16:10:31 -07003644 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003645 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3646 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003647 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003648 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003649 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003650 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003651 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003652
3653 // Short circuit if we are loading dock items for a configuration which has no dock
3654 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3655 mHotseat == null) {
3656 continue;
3657 }
3658
Joe Onorato9c1289c2009-08-17 11:03:03 -04003659 switch (item.itemType) {
3660 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3661 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003662 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003663 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003664
Winson Chung64359a52013-07-08 17:17:08 -07003665 /*
3666 * TODO: FIX collision case
3667 */
Winson Chungce376632013-07-11 16:12:41 -07003668 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3669 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3670 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3671 throw new RuntimeException("OCCUPIED");
3672 }
Winson Chung64359a52013-07-08 17:17:08 -07003673 }
3674
Adam Cohendcd297f2013-06-18 13:13:40 -07003675 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3676 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003677 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003678 // Animate all the applications up now
3679 shortcut.setAlpha(0f);
3680 shortcut.setScaleX(0f);
3681 shortcut.setScaleY(0f);
3682 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003683 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003684 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003685 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003686 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003687 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003688 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003689 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003690 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3691 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003692 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003693 default:
3694 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003695 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003696 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003697
Winson Chung997a9232013-07-24 15:33:46 -07003698 if (animateIcons) {
3699 // Animate to the correct page
3700 if (newShortcutsScreenId > -1) {
3701 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003702 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003703 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003704 // We post the animation slightly delayed to prevent slowdowns
3705 // when we are loading right after we return to launcher.
3706 mWorkspace.postDelayed(new Runnable() {
3707 public void run() {
3708 mWorkspace.snapToPage(newScreenIndex);
3709 mWorkspace.postDelayed(new Runnable() {
3710 public void run() {
3711 anim.playTogether(bounceAnims);
3712 anim.start();
3713 }
3714 }, NEW_APPS_ANIMATION_DELAY);
3715 }
3716 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003717 }
3718 }
Winson Chung64359a52013-07-08 17:17:08 -07003719 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003720 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003721 }
3722
Joe Onorato9c1289c2009-08-17 11:03:03 -04003723 /**
3724 * Implementation of the method from LauncherModel.Callbacks.
3725 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003726 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003727 Runnable r = new Runnable() {
3728 public void run() {
3729 bindFolders(folders);
3730 }
3731 };
3732 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003733 return;
3734 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003735 sFolders.clear();
3736 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003737 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003738
3739 /**
3740 * Add the views for a widget to the workspace.
3741 *
3742 * Implementation of the method from LauncherModel.Callbacks.
3743 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003744 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003745 Runnable r = new Runnable() {
3746 public void run() {
3747 bindAppWidget(item);
3748 }
3749 };
3750 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003751 return;
3752 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003753
Daniel Sandler843e8602010-06-07 14:59:01 -04003754 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3755 if (DEBUG_WIDGETS) {
3756 Log.d(TAG, "bindAppWidget: " + item);
3757 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003758 final Workspace workspace = mWorkspace;
3759
3760 final int appWidgetId = item.appWidgetId;
3761 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003762 if (DEBUG_WIDGETS) {
3763 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3764 }
3765
Joe Onorato9c1289c2009-08-17 11:03:03 -04003766 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3767
Joe Onorato9c1289c2009-08-17 11:03:03 -04003768 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003769 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770
Adam Cohendcd297f2013-06-18 13:13:40 -07003771 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003772 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003773 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3774
Joe Onorato9c1289c2009-08-17 11:03:03 -04003775 workspace.requestLayout();
3776
Daniel Sandler843e8602010-06-07 14:59:01 -04003777 if (DEBUG_WIDGETS) {
3778 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3779 + (SystemClock.uptimeMillis()-start) + "ms");
3780 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003781 }
3782
Adam Cohen1462de32012-07-24 22:34:36 -07003783 public void onPageBoundSynchronously(int page) {
3784 mSynchronouslyBoundPages.add(page);
3785 }
3786
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787 /**
3788 * Callback saying that there aren't any more items to bind.
3789 *
3790 * Implementation of the method from LauncherModel.Callbacks.
3791 */
Adam Cohene25af792013-06-06 23:08:25 -07003792 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003793 Runnable r = new Runnable() {
3794 public void run() {
3795 finishBindingItems(upgradePath);
3796 }
3797 };
3798 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003799 return;
3800 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003801 if (mSavedState != null) {
3802 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003803 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003804 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805 mSavedState = null;
3806 }
3807
Adam Cohen1462de32012-07-24 22:34:36 -07003808 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003809
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003810 // If we received the result of any pending adds while the loader was running (e.g. the
3811 // widget configuration forced an orientation change), process them now.
3812 for (int i = 0; i < sPendingAddList.size(); i++) {
3813 completeAdd(sPendingAddList.get(i));
3814 }
3815 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003816
Winson Chungc51db6a2011-10-05 11:44:49 -07003817 // Update the market app icon as necessary (the other icons will be managed in response to
3818 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003819 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003820
Winson Chungf0c6ae02012-03-21 16:10:31 -07003821 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003822 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003823 mWorkspace.getUniqueComponents(true, null);
3824 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003825 }
Adam Cohen99894d92013-06-14 11:22:59 -07003826
Adam Cohen66a01fd2013-06-11 12:48:00 -07003827 mWorkspace.post(new Runnable() {
3828 @Override
3829 public void run() {
3830 onFinishBindingItems();
3831 }
3832 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003833 }
3834
Winson Chunga0b7e862013-09-05 16:03:15 -07003835 public boolean isAllAppsButtonRank(int rank) {
3836 if (mHotseat != null) {
3837 return mHotseat.isAllAppsButtonRank(rank);
3838 }
3839 return false;
3840 }
3841
Winson Chunga2413752012-04-03 14:22:34 -07003842 private boolean canRunNewAppsAnimation() {
3843 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3844 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3845 }
3846
Winson Chungc9168342013-06-26 14:54:55 -07003847 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3848 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3849 PropertyValuesHolder.ofFloat("alpha", 1f),
3850 PropertyValuesHolder.ofFloat("scaleX", 1f),
3851 PropertyValuesHolder.ofFloat("scaleY", 1f));
3852 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3853 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3854 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3855 return bounceAnim;
3856 }
3857
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003858 @Override
3859 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003860 boolean searchVisible = updateGlobalSearchIcon();
3861 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003862 if (mSearchDropTargetBar != null) {
3863 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3864 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003865 }
3866
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003867 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003868 * Add the icons for all apps.
3869 *
3870 * Implementation of the method from LauncherModel.Callbacks.
3871 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003872 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003873 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3874 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3875 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3876 getHotseat().addAllAppsFolder(mIconCache, apps,
3877 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3878 }
3879 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003880 }
Winson Chungc58497e2013-09-03 17:48:37 -07003881 } else {
3882 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3883 mAppsCustomizeContent != null) {
3884 mAppsCustomizeContent.setApps(apps);
3885 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003886 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003887 }
3888
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003889 @Override
3890 public boolean shouldShowApp(ResolveInfo app) {
3891 return true;
3892 }
3893
Joe Onorato9c1289c2009-08-17 11:03:03 -04003894 /**
3895 * A package was updated.
3896 *
3897 * Implementation of the method from LauncherModel.Callbacks.
3898 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003899 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003900 Runnable r = new Runnable() {
3901 public void run() {
3902 bindAppsUpdated(apps);
3903 }
3904 };
3905 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003906 return;
3907 }
3908
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003909 if (mWorkspace != null) {
3910 mWorkspace.updateShortcuts(apps);
3911 }
Winson Chungc58497e2013-09-03 17:48:37 -07003912
3913 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3914 mAppsCustomizeContent != null) {
3915 mAppsCustomizeContent.updateApps(apps);
3916 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917 }
3918
3919 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003920 * A package was uninstalled. We take both the super set of packageNames
3921 * in addition to specific applications to remove, the reason being that
3922 * this can be called when a package is updated as well. In that scenario,
3923 * we only remove specific components from the workspace, where as
3924 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003925 *
3926 * Implementation of the method from LauncherModel.Callbacks.
3927 */
Winson Chung83892cc2013-05-01 16:53:33 -07003928 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003929 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003930 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003931 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003932 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003933 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003934 }
Winson Chungd64d1762013-08-20 14:37:16 -07003935 };
3936 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003937 return;
3938 }
3939
Winson Chung64359a52013-07-08 17:17:08 -07003940 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003941 mWorkspace.removeItemsByPackageName(packageNames);
3942 } else {
3943 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003944 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003945
Winson Chunga1820962011-10-03 16:31:06 -07003946 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003947 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003948
3949 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3950 mAppsCustomizeContent != null) {
3951 mAppsCustomizeContent.removeApps(appInfos);
3952 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003953 }
Joe Onoratobe386092009-11-17 17:32:16 -08003954
3955 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003956 * A number of packages were updated.
3957 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003958 private ArrayList<Object> mWidgetsAndShortcuts;
3959 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003960 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003961 bindPackagesUpdated(mWidgetsAndShortcuts);
3962 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003963 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003964 };
3965
3966 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3967 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3968 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003969 return;
3970 }
3971
Winson Chung64359a52013-07-08 17:17:08 -07003972 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003973 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3974 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003975 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003976 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003977 }
3978
Winson Chung400438b2011-01-16 17:53:48 -08003979 private int mapConfigurationOriActivityInfoOri(int configOri) {
3980 final Display d = getWindowManager().getDefaultDisplay();
3981 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3982 switch (d.getRotation()) {
3983 case Surface.ROTATION_0:
3984 case Surface.ROTATION_180:
3985 // We are currently in the same basic orientation as the natural orientation
3986 naturalOri = configOri;
3987 break;
3988 case Surface.ROTATION_90:
3989 case Surface.ROTATION_270:
3990 // We are currently in the other basic orientation to the natural orientation
3991 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3992 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3993 break;
3994 }
3995
3996 int[] oriMap = {
3997 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3998 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3999 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4000 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4001 };
4002 // Since the map starts at portrait, we need to offset if this device's natural orientation
4003 // is landscape.
4004 int indexOffset = 0;
4005 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4006 indexOffset = 1;
4007 }
4008 return oriMap[(d.getRotation() + indexOffset) % 4];
4009 }
Adam Cohen446e9402011-09-15 18:21:21 -07004010
Winson Chung4b919f82012-05-01 10:44:08 -07004011 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004012 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004013 getResources().getBoolean(R.bool.allow_rotation);
4014 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004015 }
Winson Chung4b919f82012-05-01 10:44:08 -07004016 public void lockScreenOrientation() {
4017 if (isRotationEnabled()) {
4018 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4019 .getConfiguration().orientation));
4020 }
4021 }
4022 public void unlockScreenOrientation(boolean immediate) {
4023 if (isRotationEnabled()) {
4024 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004025 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004026 } else {
4027 mHandler.postDelayed(new Runnable() {
4028 public void run() {
4029 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4030 }
4031 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004032 }
Winson Chung4b919f82012-05-01 10:44:08 -07004033 }
Winson Chung400438b2011-01-16 17:53:48 -08004034 }
4035
Winson Chung82f55532011-08-09 14:14:23 -07004036 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004037 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004038 if (DISABLE_CLINGS) {
4039 return false;
4040 }
4041
Brett Chabot2a9e2282011-08-23 15:03:13 -07004042 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004043 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004044
Michael Jurkae233a8b2013-03-19 13:49:20 +01004045 // Restricted secondary users (child mode) will potentially have very few apps
4046 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004047// boolean supportsLimitedUsers =
4048// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4049// Account[] accounts = AccountManager.get(this).getAccounts();
4050// if (supportsLimitedUsers && accounts.length == 0) {
4051// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4052// Bundle restrictions = um.getUserRestrictions();
4053// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4054// return false;
4055// }
4056// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004057 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004058 }
Michael Jurka22143132012-10-04 17:42:38 +02004059
Winson Chungaf40f202013-09-18 18:26:31 -07004060 private Cling initCling(int clingId, int[] positionData, boolean animate,
4061 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004062 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004063 if (cling != null) {
4064 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004065 cling.show(animate, SHOW_CLING_DURATION);
4066
4067 if (dimNavBarVisibilty) {
4068 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4069 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004070 }
4071 }
4072 return cling;
4073 }
Michael Jurka22143132012-10-04 17:42:38 +02004074
Winson Chungaf40f202013-09-18 18:26:31 -07004075 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4076 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004077 // To catch cases where siblings of top-level views are made invisible, just check whether
4078 // the cling is directly set to GONE before dismissing it.
4079 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004080 final Runnable cleanUpClingCb = new Runnable() {
4081 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004082 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004083 /*
Winson Chung46353de2012-02-16 14:05:10 -08004084 // We should update the shared preferences on a background thread
4085 new Thread("dismissClingThread") {
4086 public void run() {
4087 SharedPreferences.Editor editor = mSharedPrefs.edit();
4088 editor.putBoolean(flag, true);
4089 editor.commit();
4090 }
4091 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004092 */
4093 if (postAnimationCb != null) {
4094 postAnimationCb.run();
4095 }
4096 }
4097 };
4098 if (duration <= 0) {
4099 cleanUpClingCb.run();
4100 } else {
4101 cling.hide(duration, cleanUpClingCb);
4102 }
Michael Jurka22143132012-10-04 17:42:38 +02004103 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004104
4105 if (restoreNavBarVisibilty) {
4106 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4107 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4108 }
Winson Chung82f55532011-08-09 14:14:23 -07004109 }
4110 }
Michael Jurka22143132012-10-04 17:42:38 +02004111
Winson Chung9d9d74f2011-09-19 11:49:12 -07004112 private void removeCling(int id) {
4113 final View cling = findViewById(id);
4114 if (cling != null) {
4115 final ViewGroup parent = (ViewGroup) cling.getParent();
4116 parent.post(new Runnable() {
4117 @Override
4118 public void run() {
4119 parent.removeView(cling);
4120 }
4121 });
Michael Jurka22143132012-10-04 17:42:38 +02004122 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004123 }
4124 }
Michael Jurka974c3862012-05-22 22:00:31 -07004125
4126 private boolean skipCustomClingIfNoAccounts() {
4127 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4128 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4129 if (customCling) {
4130 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004131 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004132 Account[] accounts = am.getAccountsByType("com.google");
4133 return accounts.length == 0;
4134 }
4135 return false;
4136 }
4137
Winson Chungaf40f202013-09-18 18:26:31 -07004138 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004139 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004140 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004141 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004142 // If we're not using the default workspace layout, replace workspace cling
4143 // with a custom workspace cling (usually specified in an overlay)
4144 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004145 if (!DISABLE_CUSTOM_CLINGS) {
4146 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4147 getResources().getBoolean(R.bool.config_useCustomClings)) {
4148 // Use a custom cling
4149 View cling = findViewById(R.id.workspace_cling);
4150 ViewGroup clingParent = (ViewGroup) cling.getParent();
4151 int clingIndex = clingParent.indexOfChild(cling);
4152 clingParent.removeViewAt(clingIndex);
4153 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4154 clingParent.addView(customCling, clingIndex);
4155 customCling.setId(R.id.workspace_cling);
4156 }
4157 }
4158 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4159 if (cling != null) {
4160 String sbHintStr = getFirstRunClingSearchBarHint();
4161 String ccHintStr = getFirstRunCustomContentHint();
4162 if (!sbHintStr.isEmpty()) {
4163 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4164 sbHint.setText(sbHintStr);
4165 sbHint.setVisibility(View.VISIBLE);
4166 }
4167 if (!ccHintStr.isEmpty()) {
4168 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4169 ccHint.setText(ccHintStr);
4170 ccHint.setVisibility(View.VISIBLE);
4171 }
Michael Jurka45355c42012-10-08 13:21:35 +02004172 }
Winson Chungaf40f202013-09-18 18:26:31 -07004173 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004174 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004175 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004176 }
4177 }
Winson Chungaf40f202013-09-18 18:26:31 -07004178
Winson Chunge6eabff2013-09-24 11:01:23 -07004179 protected String getFirstRunClingSearchBarHint() {
4180 return "";
4181 }
4182 protected String getFirstRunCustomContentHint() {
4183 return "";
4184 }
4185
Winson Chungaf40f202013-09-18 18:26:31 -07004186 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004187 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004188 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004189 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4190 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004191 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004192 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004193 }
4194 }
4195 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004196 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004197 if (isClingsEnabled() &&
4198 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004199 Cling cling = initCling(R.id.folder_cling, null, true, true);
4200 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004201 } else {
4202 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004203 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004204 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004205 }
Michael Jurka104c4562013-07-08 18:03:46 -07004206 protected SharedPreferences getSharedPrefs() {
4207 return mSharedPrefs;
4208 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004209 public boolean isFolderClingVisible() {
4210 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004211 if (cling != null) {
4212 return cling.getVisibility() == View.VISIBLE;
4213 }
4214 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004215 }
Winson Chungaf40f202013-09-18 18:26:31 -07004216 public void dismissFirstRunCling(View v) {
4217 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4218 Runnable cb = new Runnable() {
4219 public void run() {
4220 // Show the workspace cling next
4221 showFirstRunWorkspaceCling();
4222 }
4223 };
4224 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4225 DISMISS_CLING_DURATION, false);
4226 }
Winson Chung82f55532011-08-09 14:14:23 -07004227 public void dismissWorkspaceCling(View v) {
4228 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004229 Runnable cb = null;
4230 if (v == null) {
4231 cb = new Runnable() {
4232 public void run() {
4233 mWorkspace.enterOverviewMode();
4234 }
4235 };
4236 }
4237 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4238 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004239 }
4240 public void dismissFolderCling(View v) {
4241 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004242 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4243 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004244 }
4245
Winson Chung80baf5a2010-08-09 16:03:15 -07004246 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004247 * Prints out out state for debugging.
4248 */
4249 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004250 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004251 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004252 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4253 Log.d(TAG, "mRestoring=" + mRestoring);
4254 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4255 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004256 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004257 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004258
Winson Chung785d2eb2011-04-14 16:08:02 -07004259 if (mAppsCustomizeContent != null) {
4260 mAppsCustomizeContent.dumpState();
4261 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004262 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004263 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004264
4265 @Override
4266 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4267 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004268 synchronized (sDumpLogs) {
4269 writer.println(" ");
4270 writer.println("Debug logs: ");
4271 for (int i = 0; i < sDumpLogs.size(); i++) {
4272 writer.println(" " + sDumpLogs.get(i));
4273 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004274 }
4275 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004276
4277 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004278 if (DEBUG_DUMP_LOG) {
4279 synchronized (sDumpLogs) {
4280 Log.d(TAG, "");
4281 Log.d(TAG, "*********************");
4282 Log.d(TAG, "Launcher debug logs: ");
4283 for (int i = 0; i < sDumpLogs.size(); i++) {
4284 Log.d(TAG, " " + sDumpLogs.get(i));
4285 }
4286 Log.d(TAG, "*********************");
4287 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004288 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004289 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004290 }
4291
4292 public static void addDumpLog(String tag, String log, boolean debugLog) {
4293 if (debugLog) {
4294 Log.d(tag, log);
4295 }
Winson Chungede41292013-09-19 16:27:36 -07004296 if (DEBUG_DUMP_LOG) {
4297 sDateStamp.setTime(System.currentTimeMillis());
4298 synchronized (sDumpLogs) {
4299 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004300 }
Winson Chungede41292013-09-19 16:27:36 -07004301 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004302 }
4303
Winson Chungede41292013-09-19 16:27:36 -07004304 public void dumpLogsToLocalData() {
4305 if (DEBUG_DUMP_LOG) {
4306 new Thread("DumpLogsToLocalData") {
4307 @Override
4308 public void run() {
4309 boolean success = false;
4310 sDateStamp.setTime(sRunStart);
4311 String FILENAME = sDateStamp.getMonth() + "-"
4312 + sDateStamp.getDay() + "_"
4313 + sDateStamp.getHours() + "-"
4314 + sDateStamp.getMinutes() + "_"
4315 + sDateStamp.getSeconds() + ".txt";
4316
4317 FileOutputStream fos = null;
4318 File outFile = null;
4319 try {
4320 outFile = new File(getFilesDir(), FILENAME);
4321 outFile.createNewFile();
4322 fos = new FileOutputStream(outFile);
4323 } catch (Exception e) {
4324 e.printStackTrace();
4325 }
4326 if (fos != null) {
4327 PrintWriter writer = new PrintWriter(fos);
4328
4329 writer.println(" ");
4330 writer.println("Debug logs: ");
4331 synchronized (sDumpLogs) {
4332 for (int i = 0; i < sDumpLogs.size(); i++) {
4333 writer.println(" " + sDumpLogs.get(i));
4334 }
4335 }
4336 writer.close();
4337 }
4338 try {
4339 if (fos != null) {
4340 fos.close();
4341 success = true;
4342 }
4343 } catch (IOException e) {
4344 e.printStackTrace();
4345 }
4346 }
4347 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004348 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004349 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004350}
Michael Jurka2763be32011-02-24 11:19:57 -08004351
Michael Jurkaabded662011-03-04 12:06:57 -08004352interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004353 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004354 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004355 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004356 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004357 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004358}