blob: 5bb4f7512cd625776d9e8efc071d50d06da3cda8 [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()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002560 if (mWorkspace.enterOverviewMode()) {
2561 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2562 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2563 return true;
2564 } else {
2565 return false;
2566 }
Adam Cohen1697b792013-09-17 19:08:21 -07002567 }
Adam Cohen1697b792013-09-17 19:08:21 -07002568 }
2569
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002570 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002571 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 }
2573
Michael Jurka0280c3b2010-09-17 15:00:07 -07002574 resetAddInfo();
2575 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002576 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002577 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002578 return true;
2579 }
2580
Winson Chung3d503fb2011-07-13 17:25:49 -07002581 // The hotseat touch handling does not go through Workspace, and we always allow long press
2582 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002583 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002584 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2585 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002586 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002587 // User long pressed on empty space
2588 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2589 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2590 // Disabling reordering until we sort out some issues.
2591 if (mWorkspace.isInOverviewMode()) {
2592 mWorkspace.startReordering(v);
2593 } else {
2594 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002595 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002596 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002597 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002598 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002599 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002600 }
2601 }
2602 }
2603 return true;
2604 }
2605
Winson Chung3d503fb2011-07-13 17:25:49 -07002606 boolean isHotseatLayout(View layout) {
2607 return mHotseat != null && layout != null &&
2608 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2609 }
2610 Hotseat getHotseat() {
2611 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002612 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002613 View getOverviewPanel() {
2614 return mOverviewPanel;
2615 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002616 SearchDropTargetBar getSearchBar() {
2617 return mSearchDropTargetBar;
2618 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002619
Winson Chung3d503fb2011-07-13 17:25:49 -07002620 /**
2621 * Returns the CellLayout of the specified container at the specified screen.
2622 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002623 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002624 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2625 if (mHotseat != null) {
2626 return mHotseat.getLayout();
2627 } else {
2628 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002629 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002630 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002631 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002632 }
2633 }
2634
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002635 Workspace getWorkspace() {
2636 return mWorkspace;
2637 }
2638
Daniel Sandler843e8602010-06-07 14:59:01 -04002639 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002640 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002641 }
2642
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 /**
2644 * Helper method for the cameraZoomIn/cameraZoomOut animations
2645 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 * @param scaleFactor The scale factor used for the zoom
2647 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002648 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002649 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002650 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002651 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002652
Craig Mautner360310b2012-10-26 15:13:08 -07002653 private void setWorkspaceBackground(boolean workspace) {
2654 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002655 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002656 }
2657
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002658 void updateWallpaperVisibility(boolean visible) {
2659 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2660 int curflags = getWindow().getAttributes().flags
2661 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2662 if (wpflags != curflags) {
2663 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2664 }
Craig Mautner360310b2012-10-26 15:13:08 -07002665 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002666 }
2667
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002668 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2669 if (v instanceof LauncherTransitionable) {
2670 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2671 }
2672 }
2673
Michael Jurkabed61d22012-02-14 22:51:29 -08002674 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2675 if (v instanceof LauncherTransitionable) {
2676 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2677 }
Winson Chung70442722012-02-10 15:43:22 -08002678
2679 // Update the workspace transition step as well
2680 dispatchOnLauncherTransitionStep(v, 0f);
2681 }
2682
2683 private void dispatchOnLauncherTransitionStep(View v, float t) {
2684 if (v instanceof LauncherTransitionable) {
2685 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2686 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002687 }
2688
2689 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2690 if (v instanceof LauncherTransitionable) {
2691 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2692 }
Winson Chung70442722012-02-10 15:43:22 -08002693
2694 // Update the workspace transition step as well
2695 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002696 }
2697
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002698 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002699 * Things to test when changing the following seven functions.
2700 * - Home from workspace
2701 * - from center screen
2702 * - from other screens
2703 * - Home from all apps
2704 * - from center screen
2705 * - from other screens
2706 * - Back from all apps
2707 * - from center screen
2708 * - from other screens
2709 * - Launch app from workspace and quit
2710 * - with back
2711 * - with home
2712 * - Launch app from all apps and quit
2713 * - with back
2714 * - with home
2715 * - Go to a screen that's not the default, then all
2716 * apps, and launch and app, and go back
2717 * - with back
2718 * -with home
2719 * - On workspace, long press power and go back
2720 * - with back
2721 * - with home
2722 * - On all apps, long press power and go back
2723 * - with back
2724 * - with home
2725 * - On workspace, power off
2726 * - On all apps, power off
2727 * - Launch an app and turn off the screen while in that app
2728 * - Go back with home key
2729 * - Go back with back key TODO: make this not go to workspace
2730 * - From all apps
2731 * - From workspace
2732 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2733 * - From all apps
2734 * - From the center workspace
2735 * - From another workspace
2736 */
2737
2738 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002739 * Zoom the camera out from the workspace to reveal 'toView'.
2740 * Assumes that the view to show is anchored at either the very top or very bottom
2741 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002742 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002743 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002744 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2745 showAppsCustomizeHelper(animated, springLoaded, contentType);
2746 }
2747 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2748 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002749 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002750 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002751 mStateAnimation.cancel();
2752 mStateAnimation = null;
2753 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002754 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002755
Winson Chungf0ea4d32011-06-06 14:27:16 -07002756 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2757 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2758 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002759 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002760 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002761 final int startDelay =
2762 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002763
Michael Jurkab3e22d92011-10-31 15:58:33 -07002764 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002765
Michael Jurkad74c9842011-07-10 12:44:21 -07002766 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002767 Animator workspaceAnim =
2768 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002769 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2770 // Set the content type for the all apps space
2771 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2772 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002773
2774 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002775 toView.setScaleX(scale);
2776 toView.setScaleY(scale);
2777 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2778 scaleAnim.
2779 scaleX(1f).scaleY(1f).
2780 setDuration(duration).
2781 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002782
Winson Chungf0ea4d32011-06-06 14:27:16 -07002783 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002784 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002785 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002786 .ofFloat(toView, "alpha", 0f, 1f)
2787 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002788 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002789 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2790 @Override
2791 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002792 if (animation == null) {
2793 throw new RuntimeException("animation is null");
2794 }
Winson Chung70442722012-02-10 15:43:22 -08002795 float t = (Float) animation.getAnimatedValue();
2796 dispatchOnLauncherTransitionStep(fromView, t);
2797 dispatchOnLauncherTransitionStep(toView, t);
2798 }
2799 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002800
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002801 // toView should appear right at the end of the workspace shrink
2802 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002803 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002804 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002805 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002806
2807 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002808 boolean animationCancelled = false;
2809
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002810 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002811 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002812 // Prepare the position
2813 toView.setTranslationX(0.0f);
2814 toView.setTranslationY(0.0f);
2815 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002816 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002817 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002818 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002819 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002820 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2821 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002822
Winson Chungc7d2b602012-05-16 17:02:20 -07002823 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002824 if (mSearchDropTargetBar != null) {
2825 mSearchDropTargetBar.hideSearchBar(false);
2826 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002827 }
2828
Adam Cohencff6af82011-09-13 14:51:53 -07002829 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002830 public void onAnimationCancel(Animator animation) {
2831 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002832 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002833 });
2834
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002835 if (workspaceAnim != null) {
2836 mStateAnimation.play(workspaceAnim);
2837 }
Michael Jurka1899a362011-11-03 13:50:45 -07002838
2839 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002840
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002841 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2842 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002843
2844 // If any of the objects being animated haven't been measured/laid out
2845 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002846 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002847 (mWorkspace.getMeasuredWidth() == 0) ||
2848 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002850 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002852 final AnimatorSet stateAnimation = mStateAnimation;
2853 final Runnable startAnimRunnable = new Runnable() {
2854 public void run() {
2855 // Check that mStateAnimation hasn't changed while
2856 // we waited for a layout/draw pass
2857 if (mStateAnimation != stateAnimation)
2858 return;
2859 setPivotsForZoom(toView, scale);
2860 dispatchOnLauncherTransitionStart(fromView, animated, false);
2861 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002862 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002863 }
2864 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002865 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002866 final ViewTreeObserver observer = toView.getViewTreeObserver();
2867 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2868 public void onGlobalLayout() {
2869 startAnimRunnable.run();
2870 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2871 }
2872 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002873 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002874 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002875 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002876 } else {
2877 toView.setTranslationX(0.0f);
2878 toView.setTranslationY(0.0f);
2879 toView.setScaleX(1.0f);
2880 toView.setScaleY(1.0f);
2881 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002882 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002883
Daniel Sandlere4f98912013-06-25 15:13:26 -04002884 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002885 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002886 if (mSearchDropTargetBar != null) {
2887 mSearchDropTargetBar.hideSearchBar(false);
2888 }
Michael Jurkaabded662011-03-04 12:06:57 -08002889 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002890 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002891 dispatchOnLauncherTransitionStart(fromView, animated, false);
2892 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002893 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002894 dispatchOnLauncherTransitionStart(toView, animated, false);
2895 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002896 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002897 }
2898
2899 /**
2900 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002901 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002902 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002903 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002904 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2905 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002906
Michael Jurkab3e22d92011-10-31 15:58:33 -07002907 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002908 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002909 mStateAnimation.cancel();
2910 mStateAnimation = null;
2911 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002912 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002913
Winson Chungf0ea4d32011-06-06 14:27:16 -07002914 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002915 final int fadeOutDuration =
2916 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002917 final float scaleFactor = (float)
2918 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2919 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002920 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002921 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002922 if (toState == State.WORKSPACE) {
2923 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2924 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002925 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002926 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2927 workspaceAnim = mWorkspace.getChangeStateAnimation(
2928 Workspace.State.SPRING_LOADED, animated);
2929 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002930
Michael Jurkab3e22d92011-10-31 15:58:33 -07002931 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002932 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002933 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002934 final LauncherViewPropertyAnimator scaleAnim =
2935 new LauncherViewPropertyAnimator(fromView);
2936 scaleAnim.
2937 scaleX(scaleFactor).scaleY(scaleFactor).
2938 setDuration(duration).
2939 setInterpolator(new Workspace.ZoomInInterpolator());
2940
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002941 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002942 .ofFloat(fromView, "alpha", 1f, 0f)
2943 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002944 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002945 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2946 @Override
2947 public void onAnimationUpdate(ValueAnimator animation) {
2948 float t = 1f - (Float) animation.getAnimatedValue();
2949 dispatchOnLauncherTransitionStep(fromView, t);
2950 dispatchOnLauncherTransitionStep(toView, t);
2951 }
2952 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002953
Michael Jurka2ecf9952012-06-18 12:52:28 -07002954 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002955
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002956 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2957 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002958 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002959
2960 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002961 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002962 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002963 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002964 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2965 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002966 if (onCompleteRunnable != null) {
2967 onCompleteRunnable.run();
2968 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002969 mAppsCustomizeContent.updateCurrentPageScroll();
2970 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002971 }
2972 });
2973
Winson Chungf0ea4d32011-06-06 14:27:16 -07002974 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002975 if (workspaceAnim != null) {
2976 mStateAnimation.play(workspaceAnim);
2977 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002978 dispatchOnLauncherTransitionStart(fromView, animated, true);
2979 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002980 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002981 } else {
2982 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002983 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002984 dispatchOnLauncherTransitionStart(fromView, animated, true);
2985 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002986 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002987 dispatchOnLauncherTransitionStart(toView, animated, true);
2988 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002989 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002990 }
2991
Michael Jurkae326f182011-11-21 14:05:46 -08002992 @Override
2993 public void onTrimMemory(int level) {
2994 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002995 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002996 mAppsCustomizeTabHost.onTrimMemory();
2997 }
2998 }
2999
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003000 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003001 showWorkspace(animated, null);
3002 }
3003
3004 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003005 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003006 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003007 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003008 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003009
Winson Chungc7d2b602012-05-16 17:02:20 -07003010 // Show the search bar (only animate if we were showing the drop target bar in spring
3011 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003012 if (mSearchDropTargetBar != null) {
3013 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3014 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003015
Michael Jurkab3e22d92011-10-31 15:58:33 -07003016 // Set focus to the AppsCustomize button
3017 if (mAllAppsButton != null) {
3018 mAllAppsButton.requestFocus();
3019 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003020 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003021
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003022 // Change the state *after* we've called all the transition code
3023 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003024
Winson Chung5fb63472011-02-02 17:03:37 -08003025 // Resume the auto-advance of widgets
3026 mUserPresent = true;
3027 updateRunning();
3028
alanv1d4fde62012-10-17 13:15:47 -07003029 // Send an accessibility event to announce the context change
3030 getWindow().getDecorView()
3031 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003032
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003033 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003034 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003035 }
3036
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003037 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003038 }
3039
Winson Chungc58497e2013-09-03 17:48:37 -07003040 void showAllApps(boolean animated,
3041 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003042 if (mState != State.WORKSPACE) return;
3043
Winson Chungc58497e2013-09-03 17:48:37 -07003044 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003045 mAppsCustomizeTabHost.requestFocus();
3046
Michael Jurkab3e22d92011-10-31 15:58:33 -07003047 // Change the state *after* we've called all the transition code
3048 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003049 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003050
3051 // Pause the auto-advance of widgets until we are out of AllApps
3052 mUserPresent = false;
3053 updateRunning();
3054 closeFolder();
3055
3056 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003057 getWindow().getDecorView()
3058 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003059 }
3060
Adam Cohen7777d962011-08-18 18:58:38 -07003061 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003062 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003063 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003064 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003065 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003066 }
Adam Cohen7777d962011-08-18 18:58:38 -07003067
Adam Cohened66b2b2012-01-23 17:28:51 -08003068 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3069 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003070 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3071
Winson Chunge7a03942011-08-05 15:05:12 -07003072 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003073 @Override
3074 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003075 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003076 // Before we show workspace, hide all apps again because
3077 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3078 // clean up our state transition functions
3079 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003080 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003081 } else {
3082 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003083 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003084 }
3085 }, (extendedDelay ?
3086 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3087 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3088 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003089
Michael Jurkad3ef3062010-11-23 16:23:58 -08003090 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003091 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003092 final boolean animated = true;
3093 final boolean springLoaded = true;
3094 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003095 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003096 }
3097 // Otherwise, we are not in spring loaded mode, so don't do anything.
3098 }
3099
Michael Jurkab3e22d92011-10-31 15:58:33 -07003100 void lockAllApps() {
3101 // TODO
3102 }
3103
3104 void unlockAllApps() {
3105 // TODO
3106 }
3107
Winson Chungf0ea4d32011-06-06 14:27:16 -07003108 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003109 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003110 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003111 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003112 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003113 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003114 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003115 int duration = 0;
3116 if (mSearchDropTargetBar != null) {
3117 duration = mSearchDropTargetBar.getTransitionInDuration();
3118 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003119 mHotseat.animate().alpha(1f).setDuration(duration);
3120 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003121 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003122 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003123 }
3124 }
3125 }
3126
3127 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003128 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003129 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003130 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003131 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003132 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003133 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003134 int duration = 0;
3135 if (mSearchDropTargetBar != null) {
3136 duration = mSearchDropTargetBar.getTransitionOutDuration();
3137 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003138 mHotseat.animate().alpha(0f).setDuration(duration);
3139 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003140 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003142 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003143 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003144 }
3145
Patrick Dubroy5f445422011-02-18 14:35:21 -08003146 /**
3147 * Add an item from all apps or customize onto the given workspace screen.
3148 * If layout is null, add to the current screen.
3149 */
3150 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003151 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003152 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003153 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003154 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003155
Winson Chungdff8ebb2011-09-08 17:25:31 -07003156 /** Maps the current orientation to an index for referencing orientation correct global icons */
3157 private int getCurrentOrientationIndexForGlobalIcons() {
3158 // default - 0, landscape - 1
3159 switch (getResources().getConfiguration().orientation) {
3160 case Configuration.ORIENTATION_LANDSCAPE:
3161 return 1;
3162 default:
3163 return 0;
3164 }
3165 }
3166
Michael Jurkaae65ee32012-04-30 11:45:54 -07003167 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003168 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003169 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003170 // Look for the toolbar icon specified in the activity meta-data
3171 Bundle metaData = packageManager.getActivityInfo(
3172 activityName, PackageManager.GET_META_DATA).metaData;
3173 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003174 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003175 if (iconResId != 0) {
3176 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003177 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003178 }
3179 }
3180 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003181 // This can happen if the activity defines an invalid drawable
3182 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3183 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003184 } catch (Resources.NotFoundException nfe) {
3185 // This can happen if the activity defines an invalid drawable
3186 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3187 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003188 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003189 return null;
3190 }
3191
3192 // if successful in getting icon, return it; otherwise, set button to use default drawable
3193 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003194 int buttonId, ComponentName activityName, int fallbackDrawableId,
3195 String toolbarResourceName) {
3196 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003197 Resources r = getResources();
3198 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3199 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003200
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003201 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003202 // If we were unable to find the icon via the meta-data, use a generic one
3203 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003204 toolbarIcon = r.getDrawable(fallbackDrawableId);
3205 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003206 if (button != null) {
3207 button.setCompoundDrawables(toolbarIcon, null, null, null);
3208 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003209 return null;
3210 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003211 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003212 if (button != null) {
3213 button.setCompoundDrawables(toolbarIcon, null, null, null);
3214 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003215 return toolbarIcon.getConstantState();
3216 }
3217 }
3218
3219 // if successful in getting icon, return it; otherwise, set button to use default drawable
3220 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003221 int buttonId, ComponentName activityName, int fallbackDrawableId,
3222 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003223 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003224 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003225
Michael Jurka19e0fc52011-07-22 18:00:21 -07003226 if (button != null) {
3227 // If we were unable to find the icon via the meta-data, use a
3228 // generic one
3229 if (toolbarIcon == null) {
3230 button.setImageResource(fallbackDrawableId);
3231 } else {
3232 button.setImageDrawable(toolbarIcon);
3233 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003234 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003235
3236 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3237
Michael Jurka0423dcf2010-10-05 14:56:18 -07003238 }
3239
Winson Chung1b884092012-06-08 17:13:02 -07003240 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003241 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003242 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003243 }
3244
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003245 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003246 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003247 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003248 }
3249
Winson Chungbb185bd2011-11-21 12:31:42 -08003250 private void invalidatePressedFocusedStates(View container, View button) {
3251 if (container instanceof HolographicLinearLayout) {
3252 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3253 layout.invalidatePressedFocusedStates();
3254 } else if (button instanceof HolographicImageView) {
3255 HolographicImageView view = (HolographicImageView) button;
3256 view.invalidatePressedFocusedStates();
3257 }
3258 }
3259
Cristina Stancu476493b2013-08-07 17:20:14 +01003260 public View getQsbBar() {
3261 if (mQsbBar == null) {
3262 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3263 }
3264 return mQsbBar;
3265 }
3266
3267 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003268 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003269 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003270 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003271 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003272
Winson Chung1cad91e2011-05-25 17:41:01 -07003273 final SearchManager searchManager =
3274 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3275 ComponentName activityName = searchManager.getGlobalSearchActivity();
3276 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003277 int coi = getCurrentOrientationIndexForGlobalIcons();
3278 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003279 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3280 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3281 if (sGlobalSearchIcon[coi] == null) {
3282 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3283 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3284 TOOLBAR_ICON_METADATA_NAME);
3285 }
3286
Winson Chungc51db6a2011-10-05 11:44:49 -07003287 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3288 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003289 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003290 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003291 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003292 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003293 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3294 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003295 if (searchButton != null) searchButton.setVisibility(View.GONE);
3296 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003297 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003298 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003299 }
3300 }
3301
Cristina Stancu476493b2013-08-07 17:20:14 +01003302 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003303 final View searchButtonContainer = findViewById(R.id.search_button_container);
3304 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003305 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003306 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003307 }
3308
Cristina Stancu476493b2013-08-07 17:20:14 +01003309 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003310 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003311 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003312
Winson Chungc51db6a2011-10-05 11:44:49 -07003313 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003314 final SearchManager searchManager =
3315 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3316 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3317
3318 ComponentName activityName = null;
3319 if (globalSearchActivity != null) {
3320 // Check if the global search activity handles voice search
3321 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3322 intent.setPackage(globalSearchActivity.getPackageName());
3323 activityName = intent.resolveActivity(getPackageManager());
3324 }
3325
3326 if (activityName == null) {
3327 // Fallback: check if an activity other than the global search activity
3328 // resolves this
3329 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3330 activityName = intent.resolveActivity(getPackageManager());
3331 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003332 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003333 int coi = getCurrentOrientationIndexForGlobalIcons();
3334 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003335 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3336 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3337 if (sVoiceSearchIcon[coi] == null) {
3338 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3339 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3340 TOOLBAR_ICON_METADATA_NAME);
3341 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003342 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003343 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003344 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003345 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003346 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003347 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003348 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003349 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003350 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003351 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003352 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003353 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003354
Cristina Stancu476493b2013-08-07 17:20:14 +01003355 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003356 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3357 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003358 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003359 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003360 }
3361
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003362 public void setVoiceButtonProxyVisible(boolean visible) {
3363 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3364 if (voiceButtonProxy != null) {
3365 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3366 }
3367 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003368 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003369 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003370 */
3371 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003372 final View marketButton = findViewById(R.id.market_button);
3373 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3374 // Find the app market activity by resolving an intent.
3375 // (If multiple app markets are installed, it will return the ResolverActivity.)
3376 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003377 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003378 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003379 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003380 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003381 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3382 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003383 marketButton.setVisibility(View.VISIBLE);
3384 } else {
3385 // We should hide and disable the view so that we don't try and restore the visibility
3386 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3387 marketButton.setVisibility(View.GONE);
3388 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003389 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003390 }
3391
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003392 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003393 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3394 Resources r = getResources();
3395 Drawable marketIconDrawable = d.newDrawable(r);
3396 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3397 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3398 marketIconDrawable.setBounds(0, 0, w, h);
3399
3400 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003401 }
3402
Michael Jurkad7c28052012-04-27 15:43:36 -07003403 @Override
3404 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003405 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003406 final List<CharSequence> text = event.getText();
3407 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003408 // Populate event with a fake title based on the current state.
3409 if (mState == State.APPS_CUSTOMIZE) {
3410 text.add(getString(R.string.all_apps_button_label));
3411 } else {
3412 text.add(getString(R.string.all_apps_home_button_label));
3413 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003414 return result;
3415 }
3416
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003417 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003418 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003419 */
3420 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3421 @Override
3422 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003423 closeSystemDialogs();
3424 }
3425 }
3426
3427 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003428 * Receives notifications whenever the appwidgets are reset.
3429 */
3430 private class AppWidgetResetObserver extends ContentObserver {
3431 public AppWidgetResetObserver() {
3432 super(new Handler());
3433 }
3434
3435 @Override
3436 public void onChange(boolean selfChange) {
3437 onAppWidgetReset();
3438 }
3439 }
3440
3441 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003442 * If the activity is currently paused, signal that we need to run the passed Runnable
3443 * in onResume.
3444 *
3445 * This needs to be called from incoming places where resources might have been loaded
3446 * while we are paused. That is becaues the Configuration might be wrong
3447 * when we're not running, and if it comes back to what it was when we
3448 * were paused, we are not restarted.
3449 *
3450 * Implementation of the method from LauncherModel.Callbacks.
3451 *
3452 * @return true if we are currently paused. The caller might be able to
3453 * skip some work in that case since we will come back again.
3454 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003455 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003456 if (mPaused) {
3457 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003458 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003459 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003460 }
3461 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003462 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003463 return true;
3464 } else {
3465 return false;
3466 }
3467 }
3468
Michael Jurkac402cd92013-05-20 15:49:32 +02003469 private boolean waitUntilResume(Runnable run) {
3470 return waitUntilResume(run, false);
3471 }
3472
Michael Jurka1e2f4652013-07-08 18:03:46 -07003473 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003474 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003475 }
3476
Michael Jurka7607c2f2013-04-03 14:33:19 -07003477 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003478 * If the activity is currently paused, signal that we need to re-run the loader
3479 * in onResume.
3480 *
3481 * This needs to be called from incoming places where resources might have been loaded
3482 * while we are paused. That is becaues the Configuration might be wrong
3483 * when we're not running, and if it comes back to what it was when we
3484 * were paused, we are not restarted.
3485 *
3486 * Implementation of the method from LauncherModel.Callbacks.
3487 *
3488 * @return true if we are currently paused. The caller might be able to
3489 * skip some work in that case since we will come back again.
3490 */
3491 public boolean setLoadOnResume() {
3492 if (mPaused) {
3493 Log.i(TAG, "setLoadOnResume");
3494 mOnResumeNeedsLoad = true;
3495 return true;
3496 } else {
3497 return false;
3498 }
3499 }
3500
3501 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003502 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003503 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003504 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003505 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003506 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003507 } else {
3508 return SCREEN_COUNT / 2;
3509 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003510 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003511
Joe Onorato9c1289c2009-08-17 11:03:03 -04003512 /**
3513 * Refreshes the shortcuts shown on the workspace.
3514 *
3515 * Implementation of the method from LauncherModel.Callbacks.
3516 */
3517 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003518 // If we're starting binding all over again, clear any bind calls we'd postponed in
3519 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3520 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003521 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003522
Winson Chungd64d1762013-08-20 14:37:16 -07003523 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003524 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003525 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003526
Michael Jurka05bf644e2011-11-30 20:28:53 -08003527 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003528 if (mHotseat != null) {
3529 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003530 }
3531 }
3532
Adam Cohendcd297f2013-06-18 13:13:40 -07003533 @Override
3534 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003535 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003536
Adam Cohen5084cba2013-09-03 12:01:16 -07003537 // If there are no screens, we need to have an empty screen
3538 if (orderedScreenIds.size() == 0) {
3539 mWorkspace.addExtraEmptyScreen();
3540 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003541
3542 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003543 // setCurrentPage() so ensure that all pages are added before calling this).
3544 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003545 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3546 mWorkspace.createCustomContentPage();
3547 }
Winson Chung64359a52013-07-08 17:17:08 -07003548 }
3549
3550 @Override
3551 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003552 int count = orderedScreenIds.size();
3553 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003554 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003555 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003556 }
3557
Adam Cohen39a06042013-07-19 14:30:12 -07003558 private boolean shouldShowWeightWatcher() {
3559 String spKey = LauncherAppState.getSharedPreferencesKey();
3560 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003561 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003562
3563 return show;
3564 }
3565
Adam Cohen4caf2982013-08-20 18:54:31 -07003566 private boolean emailSent() {
3567 String spKey = LauncherAppState.getSharedPreferencesKey();
3568 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3569 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3570 return show;
3571 }
3572
3573 private void setEmailSent(boolean sent) {
3574 String spKey = LauncherAppState.getSharedPreferencesKey();
3575 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3576
3577 SharedPreferences.Editor editor = sp.edit();
3578 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3579 editor.commit();
3580 }
3581
Adam Cohen39a06042013-07-19 14:30:12 -07003582 private void toggleShowWeightWatcher() {
3583 String spKey = LauncherAppState.getSharedPreferencesKey();
3584 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3585 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3586
3587 show = !show;
3588
3589 SharedPreferences.Editor editor = sp.edit();
3590 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3591 editor.commit();
3592
3593 if (mWeightWatcher != null) {
3594 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3595 }
3596 }
3597
Winson Chungd64d1762013-08-20 14:37:16 -07003598 public void bindAppsAdded(final ArrayList<Long> newScreens,
3599 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003600 final ArrayList<ItemInfo> addAnimated,
3601 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003602 Runnable r = new Runnable() {
3603 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003604 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003605 }
3606 };
3607 if (waitUntilResume(r)) {
3608 return;
3609 }
3610
Winson Chungd64d1762013-08-20 14:37:16 -07003611 // Add the new screens
3612 bindAddScreens(newScreens);
3613
3614 // We add the items without animation on non-visible pages, and with
3615 // animations on the new page (which we will try and snap to).
3616 if (!addNotAnimated.isEmpty()) {
3617 bindItems(addNotAnimated, 0,
3618 addNotAnimated.size(), false);
3619 }
3620 if (!addAnimated.isEmpty()) {
3621 bindItems(addAnimated, 0,
3622 addAnimated.size(), true);
3623 }
Winson Chungc58497e2013-09-03 17:48:37 -07003624
3625 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3626 addedApps != null && mAppsCustomizeContent != null) {
3627 mAppsCustomizeContent.addApps(addedApps);
3628 }
Winson Chungd64d1762013-08-20 14:37:16 -07003629 }
3630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003631 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003632 * Bind the items start-end from the list.
3633 *
3634 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003635 */
Winson Chung64359a52013-07-08 17:17:08 -07003636 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3637 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003638 Runnable r = new Runnable() {
3639 public void run() {
3640 bindItems(shortcuts, start, end, forceAnimateIcons);
3641 }
3642 };
3643 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003644 return;
3645 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003646
Winson Chungf0c6ae02012-03-21 16:10:31 -07003647 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003648 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3649 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003650 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003651 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003652 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003653 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003654 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003655
3656 // Short circuit if we are loading dock items for a configuration which has no dock
3657 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3658 mHotseat == null) {
3659 continue;
3660 }
3661
Joe Onorato9c1289c2009-08-17 11:03:03 -04003662 switch (item.itemType) {
3663 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3664 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003665 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003666 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003667
Winson Chung64359a52013-07-08 17:17:08 -07003668 /*
3669 * TODO: FIX collision case
3670 */
Winson Chungce376632013-07-11 16:12:41 -07003671 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3672 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3673 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3674 throw new RuntimeException("OCCUPIED");
3675 }
Winson Chung64359a52013-07-08 17:17:08 -07003676 }
3677
Adam Cohendcd297f2013-06-18 13:13:40 -07003678 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3679 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003680 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003681 // Animate all the applications up now
3682 shortcut.setAlpha(0f);
3683 shortcut.setScaleX(0f);
3684 shortcut.setScaleY(0f);
3685 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003686 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003687 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003688 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003689 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003690 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003691 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003692 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003693 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3694 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003695 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003696 default:
3697 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003698 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003699 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003700
Winson Chung997a9232013-07-24 15:33:46 -07003701 if (animateIcons) {
3702 // Animate to the correct page
3703 if (newShortcutsScreenId > -1) {
3704 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003705 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003706 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003707 // We post the animation slightly delayed to prevent slowdowns
3708 // when we are loading right after we return to launcher.
3709 mWorkspace.postDelayed(new Runnable() {
3710 public void run() {
3711 mWorkspace.snapToPage(newScreenIndex);
3712 mWorkspace.postDelayed(new Runnable() {
3713 public void run() {
3714 anim.playTogether(bounceAnims);
3715 anim.start();
3716 }
3717 }, NEW_APPS_ANIMATION_DELAY);
3718 }
3719 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003720 }
3721 }
Winson Chung64359a52013-07-08 17:17:08 -07003722 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003723 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003724 }
3725
Joe Onorato9c1289c2009-08-17 11:03:03 -04003726 /**
3727 * Implementation of the method from LauncherModel.Callbacks.
3728 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003729 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003730 Runnable r = new Runnable() {
3731 public void run() {
3732 bindFolders(folders);
3733 }
3734 };
3735 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003736 return;
3737 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003738 sFolders.clear();
3739 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003741
3742 /**
3743 * Add the views for a widget to the workspace.
3744 *
3745 * Implementation of the method from LauncherModel.Callbacks.
3746 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003747 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003748 Runnable r = new Runnable() {
3749 public void run() {
3750 bindAppWidget(item);
3751 }
3752 };
3753 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003754 return;
3755 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003756
Daniel Sandler843e8602010-06-07 14:59:01 -04003757 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3758 if (DEBUG_WIDGETS) {
3759 Log.d(TAG, "bindAppWidget: " + item);
3760 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003761 final Workspace workspace = mWorkspace;
3762
3763 final int appWidgetId = item.appWidgetId;
3764 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003765 if (DEBUG_WIDGETS) {
3766 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3767 }
3768
Joe Onorato9c1289c2009-08-17 11:03:03 -04003769 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3770
Joe Onorato9c1289c2009-08-17 11:03:03 -04003771 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003772 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003773
Adam Cohendcd297f2013-06-18 13:13:40 -07003774 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003775 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003776 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3777
Joe Onorato9c1289c2009-08-17 11:03:03 -04003778 workspace.requestLayout();
3779
Daniel Sandler843e8602010-06-07 14:59:01 -04003780 if (DEBUG_WIDGETS) {
3781 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3782 + (SystemClock.uptimeMillis()-start) + "ms");
3783 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003784 }
3785
Adam Cohen1462de32012-07-24 22:34:36 -07003786 public void onPageBoundSynchronously(int page) {
3787 mSynchronouslyBoundPages.add(page);
3788 }
3789
Joe Onorato9c1289c2009-08-17 11:03:03 -04003790 /**
3791 * Callback saying that there aren't any more items to bind.
3792 *
3793 * Implementation of the method from LauncherModel.Callbacks.
3794 */
Adam Cohene25af792013-06-06 23:08:25 -07003795 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003796 Runnable r = new Runnable() {
3797 public void run() {
3798 finishBindingItems(upgradePath);
3799 }
3800 };
3801 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003802 return;
3803 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003804 if (mSavedState != null) {
3805 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003806 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003808 mSavedState = null;
3809 }
3810
Adam Cohen1462de32012-07-24 22:34:36 -07003811 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003813 // If we received the result of any pending adds while the loader was running (e.g. the
3814 // widget configuration forced an orientation change), process them now.
3815 for (int i = 0; i < sPendingAddList.size(); i++) {
3816 completeAdd(sPendingAddList.get(i));
3817 }
3818 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819
Winson Chungc51db6a2011-10-05 11:44:49 -07003820 // Update the market app icon as necessary (the other icons will be managed in response to
3821 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003822 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003823
Winson Chungf0c6ae02012-03-21 16:10:31 -07003824 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003825 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003826 mWorkspace.getUniqueComponents(true, null);
3827 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003828 }
Adam Cohen99894d92013-06-14 11:22:59 -07003829
Adam Cohen66a01fd2013-06-11 12:48:00 -07003830 mWorkspace.post(new Runnable() {
3831 @Override
3832 public void run() {
3833 onFinishBindingItems();
3834 }
3835 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003836 }
3837
Winson Chunga0b7e862013-09-05 16:03:15 -07003838 public boolean isAllAppsButtonRank(int rank) {
3839 if (mHotseat != null) {
3840 return mHotseat.isAllAppsButtonRank(rank);
3841 }
3842 return false;
3843 }
3844
Winson Chunga2413752012-04-03 14:22:34 -07003845 private boolean canRunNewAppsAnimation() {
3846 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3847 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3848 }
3849
Winson Chungc9168342013-06-26 14:54:55 -07003850 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3851 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3852 PropertyValuesHolder.ofFloat("alpha", 1f),
3853 PropertyValuesHolder.ofFloat("scaleX", 1f),
3854 PropertyValuesHolder.ofFloat("scaleY", 1f));
3855 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3856 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3857 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3858 return bounceAnim;
3859 }
3860
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003861 @Override
3862 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003863 boolean searchVisible = updateGlobalSearchIcon();
3864 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003865 if (mSearchDropTargetBar != null) {
3866 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3867 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003868 }
3869
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003870 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003871 * Add the icons for all apps.
3872 *
3873 * Implementation of the method from LauncherModel.Callbacks.
3874 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003875 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003876 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3877 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3878 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3879 getHotseat().addAllAppsFolder(mIconCache, apps,
3880 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3881 }
3882 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003883 }
Winson Chungc58497e2013-09-03 17:48:37 -07003884 } else {
3885 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3886 mAppsCustomizeContent != null) {
3887 mAppsCustomizeContent.setApps(apps);
3888 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003889 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003890 }
3891
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003892 @Override
3893 public boolean shouldShowApp(ResolveInfo app) {
3894 return true;
3895 }
3896
Joe Onorato9c1289c2009-08-17 11:03:03 -04003897 /**
3898 * A package was updated.
3899 *
3900 * Implementation of the method from LauncherModel.Callbacks.
3901 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003902 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003903 Runnable r = new Runnable() {
3904 public void run() {
3905 bindAppsUpdated(apps);
3906 }
3907 };
3908 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003909 return;
3910 }
3911
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003912 if (mWorkspace != null) {
3913 mWorkspace.updateShortcuts(apps);
3914 }
Winson Chungc58497e2013-09-03 17:48:37 -07003915
3916 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3917 mAppsCustomizeContent != null) {
3918 mAppsCustomizeContent.updateApps(apps);
3919 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003920 }
3921
3922 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003923 * A package was uninstalled. We take both the super set of packageNames
3924 * in addition to specific applications to remove, the reason being that
3925 * this can be called when a package is updated as well. In that scenario,
3926 * we only remove specific components from the workspace, where as
3927 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003928 *
3929 * Implementation of the method from LauncherModel.Callbacks.
3930 */
Winson Chung83892cc2013-05-01 16:53:33 -07003931 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003932 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003933 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003934 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003935 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003936 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003937 }
Winson Chungd64d1762013-08-20 14:37:16 -07003938 };
3939 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003940 return;
3941 }
3942
Winson Chung64359a52013-07-08 17:17:08 -07003943 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003944 mWorkspace.removeItemsByPackageName(packageNames);
3945 } else {
3946 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003947 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003948
Winson Chunga1820962011-10-03 16:31:06 -07003949 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003950 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003951
3952 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3953 mAppsCustomizeContent != null) {
3954 mAppsCustomizeContent.removeApps(appInfos);
3955 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003956 }
Joe Onoratobe386092009-11-17 17:32:16 -08003957
3958 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003959 * A number of packages were updated.
3960 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003961 private ArrayList<Object> mWidgetsAndShortcuts;
3962 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003963 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003964 bindPackagesUpdated(mWidgetsAndShortcuts);
3965 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003966 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003967 };
3968
3969 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3970 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3971 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003972 return;
3973 }
3974
Winson Chung64359a52013-07-08 17:17:08 -07003975 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003976 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3977 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003978 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003979 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003980 }
3981
Winson Chung400438b2011-01-16 17:53:48 -08003982 private int mapConfigurationOriActivityInfoOri(int configOri) {
3983 final Display d = getWindowManager().getDefaultDisplay();
3984 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3985 switch (d.getRotation()) {
3986 case Surface.ROTATION_0:
3987 case Surface.ROTATION_180:
3988 // We are currently in the same basic orientation as the natural orientation
3989 naturalOri = configOri;
3990 break;
3991 case Surface.ROTATION_90:
3992 case Surface.ROTATION_270:
3993 // We are currently in the other basic orientation to the natural orientation
3994 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3995 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3996 break;
3997 }
3998
3999 int[] oriMap = {
4000 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4001 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4002 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4003 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4004 };
4005 // Since the map starts at portrait, we need to offset if this device's natural orientation
4006 // is landscape.
4007 int indexOffset = 0;
4008 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4009 indexOffset = 1;
4010 }
4011 return oriMap[(d.getRotation() + indexOffset) % 4];
4012 }
Adam Cohen446e9402011-09-15 18:21:21 -07004013
Winson Chung4b919f82012-05-01 10:44:08 -07004014 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004015 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004016 getResources().getBoolean(R.bool.allow_rotation);
4017 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004018 }
Winson Chung4b919f82012-05-01 10:44:08 -07004019 public void lockScreenOrientation() {
4020 if (isRotationEnabled()) {
4021 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4022 .getConfiguration().orientation));
4023 }
4024 }
4025 public void unlockScreenOrientation(boolean immediate) {
4026 if (isRotationEnabled()) {
4027 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004028 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004029 } else {
4030 mHandler.postDelayed(new Runnable() {
4031 public void run() {
4032 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4033 }
4034 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004035 }
Winson Chung4b919f82012-05-01 10:44:08 -07004036 }
Winson Chung400438b2011-01-16 17:53:48 -08004037 }
4038
Winson Chung82f55532011-08-09 14:14:23 -07004039 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004040 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004041 if (DISABLE_CLINGS) {
4042 return false;
4043 }
4044
Brett Chabot2a9e2282011-08-23 15:03:13 -07004045 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004046 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004047
Michael Jurkae233a8b2013-03-19 13:49:20 +01004048 // Restricted secondary users (child mode) will potentially have very few apps
4049 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004050// boolean supportsLimitedUsers =
4051// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4052// Account[] accounts = AccountManager.get(this).getAccounts();
4053// if (supportsLimitedUsers && accounts.length == 0) {
4054// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4055// Bundle restrictions = um.getUserRestrictions();
4056// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4057// return false;
4058// }
4059// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004060 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004061 }
Michael Jurka22143132012-10-04 17:42:38 +02004062
Winson Chungaf40f202013-09-18 18:26:31 -07004063 private Cling initCling(int clingId, int[] positionData, boolean animate,
4064 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004065 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004066 if (cling != null) {
4067 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004068 cling.show(animate, SHOW_CLING_DURATION);
4069
4070 if (dimNavBarVisibilty) {
4071 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4072 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004073 }
4074 }
4075 return cling;
4076 }
Michael Jurka22143132012-10-04 17:42:38 +02004077
Winson Chungaf40f202013-09-18 18:26:31 -07004078 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4079 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004080 // To catch cases where siblings of top-level views are made invisible, just check whether
4081 // the cling is directly set to GONE before dismissing it.
4082 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004083 final Runnable cleanUpClingCb = new Runnable() {
4084 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004085 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004086 /*
Winson Chung46353de2012-02-16 14:05:10 -08004087 // We should update the shared preferences on a background thread
4088 new Thread("dismissClingThread") {
4089 public void run() {
4090 SharedPreferences.Editor editor = mSharedPrefs.edit();
4091 editor.putBoolean(flag, true);
4092 editor.commit();
4093 }
4094 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004095 */
4096 if (postAnimationCb != null) {
4097 postAnimationCb.run();
4098 }
4099 }
4100 };
4101 if (duration <= 0) {
4102 cleanUpClingCb.run();
4103 } else {
4104 cling.hide(duration, cleanUpClingCb);
4105 }
Michael Jurka22143132012-10-04 17:42:38 +02004106 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004107
4108 if (restoreNavBarVisibilty) {
4109 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4110 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4111 }
Winson Chung82f55532011-08-09 14:14:23 -07004112 }
4113 }
Michael Jurka22143132012-10-04 17:42:38 +02004114
Winson Chung9d9d74f2011-09-19 11:49:12 -07004115 private void removeCling(int id) {
4116 final View cling = findViewById(id);
4117 if (cling != null) {
4118 final ViewGroup parent = (ViewGroup) cling.getParent();
4119 parent.post(new Runnable() {
4120 @Override
4121 public void run() {
4122 parent.removeView(cling);
4123 }
4124 });
Michael Jurka22143132012-10-04 17:42:38 +02004125 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004126 }
4127 }
Michael Jurka974c3862012-05-22 22:00:31 -07004128
4129 private boolean skipCustomClingIfNoAccounts() {
4130 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4131 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4132 if (customCling) {
4133 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004134 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004135 Account[] accounts = am.getAccountsByType("com.google");
4136 return accounts.length == 0;
4137 }
4138 return false;
4139 }
4140
Winson Chungaf40f202013-09-18 18:26:31 -07004141 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004142 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004143 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004144 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004145 // If we're not using the default workspace layout, replace workspace cling
4146 // with a custom workspace cling (usually specified in an overlay)
4147 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004148 if (!DISABLE_CUSTOM_CLINGS) {
4149 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4150 getResources().getBoolean(R.bool.config_useCustomClings)) {
4151 // Use a custom cling
4152 View cling = findViewById(R.id.workspace_cling);
4153 ViewGroup clingParent = (ViewGroup) cling.getParent();
4154 int clingIndex = clingParent.indexOfChild(cling);
4155 clingParent.removeViewAt(clingIndex);
4156 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4157 clingParent.addView(customCling, clingIndex);
4158 customCling.setId(R.id.workspace_cling);
4159 }
4160 }
4161 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4162 if (cling != null) {
4163 String sbHintStr = getFirstRunClingSearchBarHint();
4164 String ccHintStr = getFirstRunCustomContentHint();
4165 if (!sbHintStr.isEmpty()) {
4166 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4167 sbHint.setText(sbHintStr);
4168 sbHint.setVisibility(View.VISIBLE);
4169 }
4170 if (!ccHintStr.isEmpty()) {
4171 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4172 ccHint.setText(ccHintStr);
4173 ccHint.setVisibility(View.VISIBLE);
4174 }
Michael Jurka45355c42012-10-08 13:21:35 +02004175 }
Winson Chungaf40f202013-09-18 18:26:31 -07004176 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004177 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004178 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004179 }
4180 }
Winson Chungaf40f202013-09-18 18:26:31 -07004181
Winson Chunge6eabff2013-09-24 11:01:23 -07004182 protected String getFirstRunClingSearchBarHint() {
4183 return "";
4184 }
4185 protected String getFirstRunCustomContentHint() {
4186 return "";
4187 }
4188
Winson Chungaf40f202013-09-18 18:26:31 -07004189 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004190 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004191 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004192 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4193 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004194 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004195 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004196 }
4197 }
4198 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004199 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004200 if (isClingsEnabled() &&
4201 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004202 Cling cling = initCling(R.id.folder_cling, null, true, true);
4203 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004204 } else {
4205 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004206 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004207 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004208 }
Michael Jurka104c4562013-07-08 18:03:46 -07004209 protected SharedPreferences getSharedPrefs() {
4210 return mSharedPrefs;
4211 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004212 public boolean isFolderClingVisible() {
4213 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004214 if (cling != null) {
4215 return cling.getVisibility() == View.VISIBLE;
4216 }
4217 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004218 }
Winson Chungaf40f202013-09-18 18:26:31 -07004219 public void dismissFirstRunCling(View v) {
4220 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4221 Runnable cb = new Runnable() {
4222 public void run() {
4223 // Show the workspace cling next
4224 showFirstRunWorkspaceCling();
4225 }
4226 };
4227 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4228 DISMISS_CLING_DURATION, false);
4229 }
Winson Chung82f55532011-08-09 14:14:23 -07004230 public void dismissWorkspaceCling(View v) {
4231 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004232 Runnable cb = null;
4233 if (v == null) {
4234 cb = new Runnable() {
4235 public void run() {
4236 mWorkspace.enterOverviewMode();
4237 }
4238 };
4239 }
4240 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4241 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004242 }
4243 public void dismissFolderCling(View v) {
4244 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004245 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4246 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004247 }
4248
Winson Chung80baf5a2010-08-09 16:03:15 -07004249 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004250 * Prints out out state for debugging.
4251 */
4252 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004253 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004254 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004255 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4256 Log.d(TAG, "mRestoring=" + mRestoring);
4257 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4258 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004259 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004260 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004261
Winson Chung785d2eb2011-04-14 16:08:02 -07004262 if (mAppsCustomizeContent != null) {
4263 mAppsCustomizeContent.dumpState();
4264 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004265 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004266 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004267
4268 @Override
4269 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4270 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004271 synchronized (sDumpLogs) {
4272 writer.println(" ");
4273 writer.println("Debug logs: ");
4274 for (int i = 0; i < sDumpLogs.size(); i++) {
4275 writer.println(" " + sDumpLogs.get(i));
4276 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004277 }
4278 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004279
4280 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004281 if (DEBUG_DUMP_LOG) {
4282 synchronized (sDumpLogs) {
4283 Log.d(TAG, "");
4284 Log.d(TAG, "*********************");
4285 Log.d(TAG, "Launcher debug logs: ");
4286 for (int i = 0; i < sDumpLogs.size(); i++) {
4287 Log.d(TAG, " " + sDumpLogs.get(i));
4288 }
4289 Log.d(TAG, "*********************");
4290 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004291 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004292 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004293 }
4294
4295 public static void addDumpLog(String tag, String log, boolean debugLog) {
4296 if (debugLog) {
4297 Log.d(tag, log);
4298 }
Winson Chungede41292013-09-19 16:27:36 -07004299 if (DEBUG_DUMP_LOG) {
4300 sDateStamp.setTime(System.currentTimeMillis());
4301 synchronized (sDumpLogs) {
4302 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004303 }
Winson Chungede41292013-09-19 16:27:36 -07004304 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004305 }
4306
Winson Chungede41292013-09-19 16:27:36 -07004307 public void dumpLogsToLocalData() {
4308 if (DEBUG_DUMP_LOG) {
4309 new Thread("DumpLogsToLocalData") {
4310 @Override
4311 public void run() {
4312 boolean success = false;
4313 sDateStamp.setTime(sRunStart);
4314 String FILENAME = sDateStamp.getMonth() + "-"
4315 + sDateStamp.getDay() + "_"
4316 + sDateStamp.getHours() + "-"
4317 + sDateStamp.getMinutes() + "_"
4318 + sDateStamp.getSeconds() + ".txt";
4319
4320 FileOutputStream fos = null;
4321 File outFile = null;
4322 try {
4323 outFile = new File(getFilesDir(), FILENAME);
4324 outFile.createNewFile();
4325 fos = new FileOutputStream(outFile);
4326 } catch (Exception e) {
4327 e.printStackTrace();
4328 }
4329 if (fos != null) {
4330 PrintWriter writer = new PrintWriter(fos);
4331
4332 writer.println(" ");
4333 writer.println("Debug logs: ");
4334 synchronized (sDumpLogs) {
4335 for (int i = 0; i < sDumpLogs.size(); i++) {
4336 writer.println(" " + sDumpLogs.get(i));
4337 }
4338 }
4339 writer.close();
4340 }
4341 try {
4342 if (fos != null) {
4343 fos.close();
4344 success = true;
4345 }
4346 } catch (IOException e) {
4347 e.printStackTrace();
4348 }
4349 }
4350 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004351 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004352 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004353}
Michael Jurka2763be32011-02-24 11:19:57 -08004354
Michael Jurkaabded662011-03-04 12:06:57 -08004355interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004356 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004357 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004358 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004359 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004360 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004361}