blob: 102f4c272ac2bd40ee4839776ad80d8d606a02b4 [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 Sandler6053b802013-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
Bjorn Bringertc459e522013-06-07 19:36:01 +0100637 public LayoutInflater getInflater() {
638 return mInflater;
639 }
640
Adam Cohen716b51e2011-06-30 12:09:54 -0700641 public DragLayer getDragLayer() {
642 return mDragLayer;
643 }
644
Winson Chung36a62fe2012-05-06 18:04:42 -0700645 boolean isDraggingEnabled() {
646 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
647 // that is subsequently removed from the workspace in startBinding().
648 return !mModel.isLoadingWorkspace();
649 }
650
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800651 static int getScreen() {
652 synchronized (sLock) {
653 return sScreen;
654 }
655 }
656
657 static void setScreen(int screen) {
658 synchronized (sLock) {
659 sScreen = screen;
660 }
661 }
662
Winson Chung557d6ed2011-07-08 15:34:52 -0700663 /**
664 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
665 * a configuration step, this allows the proper animations to run after other transitions.
666 */
667 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700668 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800669 switch (args.requestCode) {
670 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700671 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700672 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800673 break;
674 case REQUEST_PICK_SHORTCUT:
675 processShortcut(args.intent);
676 break;
677 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700678 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700679 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700680 result = true;
681 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800682 case REQUEST_CREATE_APPWIDGET:
683 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700684 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700685 result = true;
686 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800687 }
Michael Jurka27614d22012-04-02 06:40:22 -0700688 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
689 // if you turned the screen off and then back while in All Apps, Launcher would not
690 // return to the workspace. Clearing mAddInfo.container here fixes this issue
691 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700692 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800693 }
694
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700696 protected void onActivityResult(
697 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700698 // Reset the startActivity waiting flag
699 mWaitingForResult = false;
700
Michael Jurka8b805b12012-04-18 14:23:14 -0700701 if (requestCode == REQUEST_BIND_APPWIDGET) {
702 int appWidgetId = data != null ?
703 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
704 if (resultCode == RESULT_CANCELED) {
705 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
706 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700707 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700708 }
709 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200710 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
711 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
712 mWorkspace.exitOverviewMode(false);
713 }
714 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700715 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200716
Winson Chung557d6ed2011-07-08 15:34:52 -0700717 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800718 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
719 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700720
Adam Cohened66b2b2012-01-23 17:28:51 -0800721 // We have special handling for widgets
722 if (isWidgetDrop) {
723 int appWidgetId = data != null ?
724 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700725 if (appWidgetId < 0) {
726 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
727 "widget configuration activity.");
728 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
729 } else {
730 completeTwoStageWidgetDrop(resultCode, appWidgetId);
731 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800732 return;
733 }
734
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 // The pattern used here is that a user PICKs a specific application,
736 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700737
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800738 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
739 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700740 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800741 final PendingAddArguments args = new PendingAddArguments();
742 args.requestCode = requestCode;
743 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700744 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700745 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700746 args.cellX = mPendingAddInfo.cellX;
747 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 if (isWorkspaceLocked()) {
749 sPendingAddList.add(args);
750 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700751 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800754 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700755 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800756 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
757 null);
758 }
759
760 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700761 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700762 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 Runnable onCompleteRunnable = null;
764 int animationType = 0;
765
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700766 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 if (resultCode == RESULT_OK) {
768 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
769 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700770 mPendingAddWidgetInfo);
771 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800772 onCompleteRunnable = new Runnable() {
773 @Override
774 public void run() {
775 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700776 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800777 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
778 null);
779 }
780 };
781 } else if (resultCode == RESULT_CANCELED) {
782 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
783 onCompleteRunnable = new Runnable() {
784 @Override
785 public void run() {
786 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
787 null);
788 }
789 };
790 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700791 if (mDragLayer.getAnimatedView() != null) {
792 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
793 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
794 animationType, boundWidget, true);
795 } else {
796 // The animated view may be null in the case of a rotation during widget configuration
797 onCompleteRunnable.run();
798 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800799 }
800
801 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700802 protected void onStop() {
803 super.onStop();
804 FirstFrameAnimatorHelper.setIsVisible(false);
805 }
806
807 @Override
808 protected void onStart() {
809 super.onStart();
810 FirstFrameAnimatorHelper.setIsVisible(true);
811 }
812
813 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200815 long startTime = 0;
816 if (DEBUG_RESUME_TIME) {
817 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400818 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200819 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800820 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700821
Winson Chung4a2afa32012-07-19 14:53:05 -0700822 // Restore the previous launcher state
823 if (mOnResumeState == State.WORKSPACE) {
824 showWorkspace(false);
825 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700826 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700827 }
828 mOnResumeState = State.NONE;
829
Craig Mautner360310b2012-10-26 15:13:08 -0700830 // Background was set to gradient in onPause(), restore to black if in all apps.
831 setWorkspaceBackground(mState == State.WORKSPACE);
832
Winson Chungde0fb8f2012-05-08 14:37:08 -0700833 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700834 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700835
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800836 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700837 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700838 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400839 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700840 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400841 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700842 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700844 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200845 // We might have postponed some bind calls until onResume (see waitUntilResume) --
846 // execute them here
847 long startTimeCallbacks = 0;
848 if (DEBUG_RESUME_TIME) {
849 startTimeCallbacks = System.currentTimeMillis();
850 }
851
852 if (mAppsCustomizeContent != null) {
853 mAppsCustomizeContent.setBulkBind(true);
854 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700855 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
856 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200857 }
858 if (mAppsCustomizeContent != null) {
859 mAppsCustomizeContent.setBulkBind(false);
860 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700861 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200862 if (DEBUG_RESUME_TIME) {
863 Log.d(TAG, "Time spent processing callbacks in onResume: " +
864 (System.currentTimeMillis() - startTimeCallbacks));
865 }
Michael Jurka447bf842013-05-15 14:52:15 +0200866 }
Michael Jurka54554252013-08-01 12:52:23 +0200867 if (mOnResumeCallbacks.size() > 0) {
868 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
869 mOnResumeCallbacks.get(i).run();
870 }
871 mOnResumeCallbacks.clear();
872 }
Winson Chunge4e50662012-01-23 14:45:13 -0800873
874 // Reset the pressed state of icons that were locked in the press state while activities
875 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800876 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800877 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800878 mWaitingForResume.setStayPressed(false);
879 }
Winson Chunge4e50662012-01-23 14:45:13 -0800880 if (mAppsCustomizeContent != null) {
881 // Resets the previous all apps icon press state
882 mAppsCustomizeContent.resetDrawableState();
883 }
Adam Cohen06dff352012-06-01 17:17:08 -0700884 // It is possible that widgets can receive updates while launcher is not in the foreground.
885 // Consequently, the widgets will be inflated in the orientation of the foreground activity
886 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
887 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700888 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700889
890 // Again, as with the above scenario, it's possible that one or more of the global icons
891 // were updated in the wrong orientation.
892 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200893 if (DEBUG_RESUME_TIME) {
894 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
895 }
Adam Cohen06dff352012-06-01 17:17:08 -0700896 }
897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700899 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700900 // Ensure that items added to Launcher are queued until Launcher returns
901 InstallShortcutReceiver.enableInstallQueue();
902
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700903 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700904 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800905 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700906 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700907 }
Romain Guycbb89e42009-06-08 15:52:54 -0700908
Adam Cohen66a01fd2013-06-11 12:48:00 -0700909 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600910 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
911 addCustomContentToLeft();
912 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700913 }
914
Adam Cohenbffe7452013-07-22 18:21:45 -0700915 QSBScroller mQsbScroller = new QSBScroller() {
916 int scrollY = 0;
917
918 @Override
919 public void setScrollY(int scroll) {
920 scrollY = scroll;
921
922 if (mWorkspace.isOnOrMovingToCustomContent()) {
923 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100924 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700925 }
926 }
927 };
928
929 public void resetQSBScroll() {
930 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100931 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700932 }
933
934 public interface CustomContentCallbacks {
935 // Custom content is completely shown
936 public void onShow();
937
938 // Custom content is completely hidden
939 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700940
941 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
942 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700943 }
944
Adam Cohen30bacb22013-08-29 14:25:25 -0700945 protected void startSettings() {
946 }
947
Adam Cohenbffe7452013-07-22 18:21:45 -0700948 public interface QSBScroller {
949 public void setScrollY(int scrollY);
950 }
951
Adam Cohen66a01fd2013-06-11 12:48:00 -0700952 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700953 public QSBScroller addToCustomContentPage(View customContent) {
954 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700955 }
956
Winson Chung98ca0f72013-07-29 12:58:51 -0700957 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700958 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700959 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700960 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700961 }
962
Adam Cohenedb40762013-07-18 16:45:45 -0700963 // The custom content needs to offset its content to account for the QSB
964 public int getTopOffsetForCustomContent() {
965 return mWorkspace.getPaddingTop();
966 }
967
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700968 @Override
969 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400970 // Flag the loader to stop early before switching
971 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700972 if (mAppsCustomizeContent != null) {
973 mAppsCustomizeContent.surrender();
974 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800975 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700976 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700977
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800978 // We can't hide the IME if it was forced open. So don't bother
979 /*
980 @Override
981 public void onWindowFocusChanged(boolean hasFocus) {
982 super.onWindowFocusChanged(hasFocus);
983
984 if (hasFocus) {
985 final InputMethodManager inputManager = (InputMethodManager)
986 getSystemService(Context.INPUT_METHOD_SERVICE);
987 WindowManager.LayoutParams lp = getWindow().getAttributes();
988 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
989 android.os.Handler()) {
990 protected void onReceiveResult(int resultCode, Bundle resultData) {
991 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
992 }
993 });
994 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
995 }
996 }
997 */
998
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800999 private boolean acceptFilter() {
1000 final InputMethodManager inputManager = (InputMethodManager)
1001 getSystemService(Context.INPUT_METHOD_SERVICE);
1002 return !inputManager.isFullscreenMode();
1003 }
1004
1005 @Override
1006 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001007 final int uniChar = event.getUnicodeChar();
1008 final boolean handled = super.onKeyDown(keyCode, event);
1009 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1010 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1012 keyCode, event);
1013 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001014 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001015 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001016 // showSearchDialog()
1017 // If there are multiple keystrokes before the search dialog takes focus,
1018 // onSearchRequested() will be called for every keystroke,
1019 // but it is idempotent, so it's fine.
1020 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 }
1022 }
1023
Joe Onorato8a9625e2010-01-28 15:55:35 -08001024 // Eat the long press event so the keyboard doesn't come up.
1025 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1026 return true;
1027 }
1028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 return handled;
1030 }
1031
Karl Rosaen138a0412009-04-23 19:00:21 -07001032 private String getTypedText() {
1033 return mDefaultKeySsb.toString();
1034 }
1035
1036 private void clearTypedText() {
1037 mDefaultKeySsb.clear();
1038 mDefaultKeySsb.clearSpans();
1039 Selection.setSelection(mDefaultKeySsb, 0);
1040 }
1041
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001042 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001043 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1044 * State
1045 */
1046 private static State intToState(int stateOrdinal) {
1047 State state = State.WORKSPACE;
1048 final State[] stateValues = State.values();
1049 for (int i = 0; i < stateValues.length; i++) {
1050 if (stateValues[i].ordinal() == stateOrdinal) {
1051 state = stateValues[i];
1052 break;
1053 }
1054 }
1055 return state;
1056 }
1057
1058 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 * Restores the previous state, if it exists.
1060 *
1061 * @param savedState The previous state.
1062 */
1063 private void restoreState(Bundle savedState) {
1064 if (savedState == null) {
1065 return;
1066 }
1067
Michael Jurka883f55b2010-10-21 15:47:14 -07001068 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001069 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001070 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001071 }
1072
Winson Chungf0c6ae02012-03-21 16:10:31 -07001073 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001075 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 }
1077
Winson Chung3d503fb2011-07-13 17:25:49 -07001078 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001079 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001080
Winson Chung3d503fb2011-07-13 17:25:49 -07001081 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1082 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001083 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001084 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1085 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001086 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1087 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1088 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001089 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090 mRestoring = true;
1091 }
1092
1093 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1094 if (renameFolder) {
1095 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001096 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 mRestoring = true;
1098 }
Winson Chunga12a2502010-12-20 14:41:35 -08001099
Winson Chung785d2eb2011-04-14 16:08:02 -07001100 // Restore the AppsCustomize tab
1101 if (mAppsCustomizeTabHost != null) {
1102 String curTab = savedState.getString("apps_customize_currentTab");
1103 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001104 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001105 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001106 mAppsCustomizeContent.loadAssociatedPages(
1107 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001108 }
1109
Winson Chung5afbf7b2011-07-25 11:53:08 -07001110 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1111 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 }
1114
1115 /**
1116 * Finds all the views we need and configure them properly.
1117 */
1118 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001119 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001120
Craig Mautner360310b2012-10-26 15:13:08 -07001121 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001122 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1123 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001124
John Spurlock77e1f472013-09-11 10:09:51 -04001125 mLauncherView.setSystemUiVisibility(
1126 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001127 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128
Winson Chung4c98d922011-05-31 16:50:48 -07001129 // Setup the drag layer
1130 mDragLayer.setup(this, dragController);
1131
Winson Chung3d503fb2011-07-13 17:25:49 -07001132 // Setup the hotseat
1133 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1134 if (mHotseat != null) {
1135 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001136 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001137 }
1138
Adam Cohenf358a4b2013-07-23 16:47:31 -07001139 mOverviewPanel = findViewById(R.id.overview_panel);
1140 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1141 @Override
1142 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001143 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001144 }
1145 });
1146 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1147 @Override
1148 public void onClick(View arg0) {
1149 startWallpaper();
1150 }
1151 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001152 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1153 @Override
1154 public void onClick(View arg0) {
1155 startSettings();
1156 }
1157 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001158 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001159
Winson Chung4c98d922011-05-31 16:50:48 -07001160 // Setup the workspace
1161 mWorkspace.setHapticFeedbackEnabled(false);
1162 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001163 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001164 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001165
Winson Chungf0ea4d32011-06-06 14:27:16 -07001166 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001167 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001168
Winson Chungf0ea4d32011-06-06 14:27:16 -07001169 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001170 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001171 mAppsCustomizeContent = (AppsCustomizePagedView)
1172 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1173 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001174
Winson Chung3d503fb2011-07-13 17:25:49 -07001175 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001176 dragController.setDragScoller(mWorkspace);
1177 dragController.setScrollView(mDragLayer);
1178 dragController.setMoveTarget(mWorkspace);
1179 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001180 if (mSearchDropTargetBar != null) {
1181 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001182 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001183
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001184 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001185 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001186 mWeightWatcher = new WeightWatcher(this);
1187 mWeightWatcher.setAlpha(0.5f);
1188 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001189 new FrameLayout.LayoutParams(
1190 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001191 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001192 Gravity.BOTTOM)
1193 );
Adam Cohen39a06042013-07-19 14:30:12 -07001194
1195 boolean show = shouldShowWeightWatcher();
1196 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001197 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 }
1199
1200 /**
1201 * Creates a view representing a shortcut.
1202 *
1203 * @param info The data structure describing the shortcut.
1204 *
1205 * @return A View inflated from R.layout.application.
1206 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001207 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001209 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 }
1211
1212 /**
1213 * Creates a view representing a shortcut inflated from the specified resource.
1214 *
1215 * @param layoutResId The id of the XML layout used to create the shortcut.
1216 * @param parent The group the shortcut belongs to.
1217 * @param info The data structure describing the shortcut.
1218 *
1219 * @return A View inflated from layoutResId.
1220 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001221 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001222 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1223 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225 return favorite;
1226 }
1227
1228 /**
1229 * Add an application shortcut to the workspace.
1230 *
1231 * @param data The intent describing the application.
1232 * @param cellInfo The position on screen where to create the shortcut.
1233 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001234 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001235 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001236 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001237
Adam Cohenfbba09b2011-07-18 21:43:05 -07001238 // First we check if we already know the exact location where we want to add this item.
1239 if (cellX >= 0 && cellY >= 0) {
1240 cellXY[0] = cellX;
1241 cellXY[1] = cellY;
1242 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001243 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001244 return;
1245 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001246
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001247 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001248
Romain Guy73b979d2009-06-09 12:57:21 -07001249 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001250 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001252 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001253 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001254 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001255 } else {
1256 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 }
1258 }
Romain Guycbb89e42009-06-08 15:52:54 -07001259
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 /**
1261 * Add a shortcut to the workspace.
1262 *
1263 * @param data The intent describing the shortcut.
1264 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001266 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001267 int cellY) {
1268 int[] cellXY = mTmpAddItemCellCoordinates;
1269 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001270 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001271
Michael Jurkad3ef3062010-11-23 16:23:58 -08001272 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001273
Adam Cohen558baaf2011-08-15 15:22:57 -07001274 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001275 if (info == null) {
1276 return;
1277 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001278 final View view = createShortcut(info);
1279
Adam Cohenfbba09b2011-07-18 21:43:05 -07001280 // First we check if we already know the exact location where we want to add this item.
1281 if (cellX >= 0 && cellY >= 0) {
1282 cellXY[0] = cellX;
1283 cellXY[1] = cellY;
1284 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001285
1286 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001287 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001288 true, null,null)) {
1289 return;
1290 }
1291 DragObject dragObject = new DragObject();
1292 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001293 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1294 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001295 return;
1296 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001297 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001298 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001299 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001300 foundCellSpan = (result != null);
1301 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001302 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001303 }
1304
1305 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001306 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001307 return;
1308 }
1309
Adam Cohendcd297f2013-06-18 13:13:40 -07001310 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311
1312 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001313 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001314 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 }
1316 }
1317
Adam Cohen2f093b62012-04-30 18:59:53 -07001318 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1319 int minHeight) {
1320 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001321 // We want to account for the extra amount of padding that we are adding to the widget
1322 // to ensure that it gets the full amount of space that it has requested
1323 int requiredWidth = minWidth + padding.left + padding.right;
1324 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001325 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001326 }
1327
Adam Cohen2f093b62012-04-30 18:59:53 -07001328 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1329 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001330 }
1331
Adam Cohen2f093b62012-04-30 18:59:53 -07001332 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1333 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1337 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001338 }
1339
Adam Cohen2f093b62012-04-30 18:59:53 -07001340 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1341 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001342 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001343 }
1344
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001346 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001348 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001349 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001351 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001352 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1353 if (appWidgetInfo == null) {
1354 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1355 }
Romain Guycbb89e42009-06-08 15:52:54 -07001356
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001358 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001359
Adam Cohen2f093b62012-04-30 18:59:53 -07001360 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1361 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001362
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001364 // We have saved the position to which the widget was dragged-- this really only matters
1365 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001366 int[] cellXY = mTmpAddItemCellCoordinates;
1367 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001368 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001369 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1371 cellXY[0] = mPendingAddInfo.cellX;
1372 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001373 spanXY[0] = mPendingAddInfo.spanX;
1374 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001375 foundCellSpan = true;
1376 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001377 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001379 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1380 spanXY[1], cellXY, finalSpan);
1381 spanXY[0] = finalSpan[0];
1382 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001383 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001384 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001385 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001386 }
1387
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001389 if (appWidgetId != -1) {
1390 // Deleting an app widget ID is a void call but writes to disk before returning
1391 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001392 new Thread("deleteAppWidgetId") {
1393 public void run() {
1394 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1395 }
1396 }.start();
1397 }
Winson Chung93eef082012-03-23 15:59:27 -07001398 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001399 return;
1400 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001402 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001403 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1404 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001405 launcherInfo.spanX = spanXY[0];
1406 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001407 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1408 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001409
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001411 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412
1413 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001414 if (hostView == null) {
1415 // Perform actual inflation because we're live
1416 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1417 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1418 } else {
1419 // The AppWidgetHostView has already been inflated and instantiated
1420 launcherInfo.hostView = hostView;
1421 }
Romain Guycbb89e42009-06-08 15:52:54 -07001422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001424 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001425 launcherInfo.notifyWidgetSizeChanged(this);
1426
Adam Cohendcd297f2013-06-18 13:13:40 -07001427 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001428 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001429
1430 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001432 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 }
Romain Guycbb89e42009-06-08 15:52:54 -07001434
Adam Cohended9f8d2010-11-03 13:25:16 -07001435 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1436 @Override
1437 public void onReceive(Context context, Intent intent) {
1438 final String action = intent.getAction();
1439 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1440 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001441 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001442 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001443
Winson Chungc100e8e2011-08-09 16:02:43 -07001444 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001445 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001446 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001447 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001448 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001449 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1450 mUserPresent = true;
1451 updateRunning();
1452 }
1453 }
1454 };
1455
1456 @Override
1457 public void onAttachedToWindow() {
1458 super.onAttachedToWindow();
1459
1460 // Listen for broadcasts related to user-presence
1461 final IntentFilter filter = new IntentFilter();
1462 filter.addAction(Intent.ACTION_SCREEN_OFF);
1463 filter.addAction(Intent.ACTION_USER_PRESENT);
1464 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001465 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001466 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001467 mVisible = true;
1468 }
1469
1470 @Override
1471 public void onDetachedFromWindow() {
1472 super.onDetachedFromWindow();
1473 mVisible = false;
1474
Adam Cohend113e0c2010-11-11 10:48:05 -08001475 if (mAttached) {
1476 unregisterReceiver(mReceiver);
1477 mAttached = false;
1478 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001479 updateRunning();
1480 }
1481
1482 public void onWindowVisibilityChanged(int visibility) {
1483 mVisible = visibility == View.VISIBLE;
1484 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001485 // The following code used to be in onResume, but it turns out onResume is called when
1486 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1487 // is a more appropriate event to handle
1488 if (mVisible) {
1489 mAppsCustomizeTabHost.onWindowVisible();
1490 if (!mWorkspaceLoading) {
1491 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001492 // We want to let Launcher draw itself at least once before we force it to build
1493 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001494 // apps is nice and speedy.
1495 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001496 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001497 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001498 if (mStarted) return;
1499 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001500 // We delay the layer building a bit in order to give
1501 // other message processing a time to run. In particular
1502 // this avoids a delay in hiding the IME if it was
1503 // currently shown, because doing that may involve
1504 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001505 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001506 final ViewTreeObserver.OnDrawListener listener = this;
1507 mWorkspace.post(new Runnable() {
1508 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001509 if (mWorkspace != null &&
1510 mWorkspace.getViewTreeObserver() != null) {
1511 mWorkspace.getViewTreeObserver().
1512 removeOnDrawListener(listener);
1513 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001514 }
1515 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001516 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001517 }
1518 });
1519 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001520 // When Launcher comes back to foreground, a different Activity might be responsible for
1521 // the app market intent, so refresh the icon
1522 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001523 clearTypedText();
1524 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001525 }
1526
1527 private void sendAdvanceMessage(long delay) {
1528 mHandler.removeMessages(ADVANCE_MSG);
1529 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1530 mHandler.sendMessageDelayed(msg, delay);
1531 mAutoAdvanceSentTime = System.currentTimeMillis();
1532 }
1533
1534 private void updateRunning() {
1535 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1536 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1537 mAutoAdvanceRunning = autoAdvanceRunning;
1538 if (autoAdvanceRunning) {
1539 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1540 sendAdvanceMessage(delay);
1541 } else {
1542 if (!mWidgetsToAdvance.isEmpty()) {
1543 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1544 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1545 }
1546 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001547 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001548 }
1549 }
1550 }
1551
1552 private final Handler mHandler = new Handler() {
1553 @Override
1554 public void handleMessage(Message msg) {
1555 if (msg.what == ADVANCE_MSG) {
1556 int i = 0;
1557 for (View key: mWidgetsToAdvance.keySet()) {
1558 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1559 final int delay = mAdvanceStagger * i;
1560 if (v instanceof Advanceable) {
1561 postDelayed(new Runnable() {
1562 public void run() {
1563 ((Advanceable) v).advance();
1564 }
1565 }, delay);
1566 }
1567 i++;
1568 }
1569 sendAdvanceMessage(mAdvanceInterval);
1570 }
1571 }
1572 };
1573
1574 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001575 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001576 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1577 if (v instanceof Advanceable) {
1578 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001579 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001580 updateRunning();
1581 }
1582 }
1583
1584 void removeWidgetToAutoAdvance(View hostView) {
1585 if (mWidgetsToAdvance.containsKey(hostView)) {
1586 mWidgetsToAdvance.remove(hostView);
1587 updateRunning();
1588 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001589 }
1590
Joe Onorato9c1289c2009-08-17 11:03:03 -04001591 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001592 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001593 launcherInfo.hostView = null;
1594 }
1595
Winson Chung93eef082012-03-23 15:59:27 -07001596 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1597 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1598 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001599 }
1600
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001601 public LauncherAppWidgetHost getAppWidgetHost() {
1602 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 }
Romain Guycbb89e42009-06-08 15:52:54 -07001604
Winson Chunga9abd0e2010-10-27 17:18:37 -07001605 public LauncherModel getModel() {
1606 return mModel;
1607 }
1608
Bjorn Bringertc459e522013-06-07 19:36:01 +01001609 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001610 getWindow().closeAllPanels();
1611
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001612 // Whatever we were doing is hereby canceled.
1613 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001614 }
1615
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001616 @Override
1617 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001618 long startTime = 0;
1619 if (DEBUG_RESUME_TIME) {
1620 startTime = System.currentTimeMillis();
1621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001622 super.onNewIntent(intent);
1623
1624 // Close the menu
1625 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001626 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001627 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001628
Jamie Genniscb222e82012-10-23 15:44:26 -07001629 final boolean alreadyOnHome =
1630 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001631 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001632
Jamie Genniscb222e82012-10-23 15:44:26 -07001633 Runnable processIntent = new Runnable() {
1634 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001635 if (mWorkspace == null) {
1636 // Can be cases where mWorkspace is null, this prevents a NPE
1637 return;
1638 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001639 Folder openFolder = mWorkspace.getOpenFolder();
1640 // In all these cases, only animate if we're already on home
1641 mWorkspace.exitWidgetResizeMode();
1642 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1643 openFolder == null) {
1644 mWorkspace.moveToDefaultScreen(true);
1645 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001646
Jamie Genniscb222e82012-10-23 15:44:26 -07001647 closeFolder();
1648 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001649
Jamie Genniscb222e82012-10-23 15:44:26 -07001650 // If we are already on home, then just animate back to the workspace,
1651 // otherwise, just wait until onResume to set the state back to Workspace
1652 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001653 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001654 } else {
1655 mOnResumeState = State.WORKSPACE;
1656 }
1657
1658 final View v = getWindow().peekDecorView();
1659 if (v != null && v.getWindowToken() != null) {
1660 InputMethodManager imm = (InputMethodManager)getSystemService(
1661 INPUT_METHOD_SERVICE);
1662 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1663 }
1664
Winson Chung7819a562013-09-19 15:55:45 -07001665 // Reset the apps customize page
1666 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001667 mAppsCustomizeTabHost.reset();
1668 }
1669 }
1670 };
1671
1672 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1673 // Delay processing of the intent to allow the status bar animation to finish
1674 // first in order to avoid janky animations.
1675 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001676 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001677 // Process the intent immediately.
1678 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001679 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001680
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 }
Michael Jurka447bf842013-05-15 14:52:15 +02001682 if (DEBUG_RESUME_TIME) {
1683 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1684 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685 }
1686
Adam Cohen040a5d22013-09-16 17:09:33 -07001687 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1688 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001689 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001690 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001691 }
1692 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001693 protected void showWorkspaceAndExitOverviewMode() {
1694 showWorkspaceAndExitOverviewMode(true);
1695 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001696
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001698 public void onRestoreInstanceState(Bundle state) {
1699 super.onRestoreInstanceState(state);
1700 for (int page: mSynchronouslyBoundPages) {
1701 mWorkspace.restoreInstanceStateForChild(page);
1702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703 }
1704
1705 @Override
1706 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001707 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001708 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709
Michael Jurka883f55b2010-10-21 15:47:14 -07001710 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001711 // We close any open folder since it will not be re-opened, and we need to make sure
1712 // this state is reflected.
1713 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714
Adam Cohendcd297f2013-06-18 13:13:40 -07001715 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001716 mWaitingForResult) {
1717 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001718 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001719 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1720 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001721 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1722 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1723 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 }
1725
1726 if (mFolderInfo != null && mWaitingForResult) {
1727 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1728 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1729 }
Michael Jurka946ad472010-07-09 18:05:18 -07001730
Winson Chung785d2eb2011-04-14 16:08:02 -07001731 // Save the current AppsCustomize tab
1732 if (mAppsCustomizeTabHost != null) {
1733 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1734 if (currentTabTag != null) {
1735 outState.putString("apps_customize_currentTab", currentTabTag);
1736 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001737 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1738 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001739 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 }
1741
1742 @Override
1743 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001745
Winson Chunge7a03942011-08-05 15:05:12 -07001746 // Remove all pending runnables
1747 mHandler.removeMessages(ADVANCE_MSG);
1748 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001749 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001750
Winson Chungcd2b0142011-06-08 16:02:26 -07001751 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001752 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001753 mModel.stopLoader();
1754 app.setLauncher(null);
1755
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001757 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001759 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001761 mAppWidgetHost = null;
1762
1763 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764
1765 TextKeyListener.getInstance().release();
1766
Winson Chung81b52252012-08-27 15:34:29 -07001767 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1768 // to prevent leaking Launcher activities on orientation change.
1769 if (mModel != null) {
1770 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1771 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001772
1773 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001774 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001775
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001776 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001777 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1778 mWorkspace.removeAllViews();
1779 mWorkspace = null;
1780 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001781
Michael Jurka2ecf9952012-06-18 12:52:28 -07001782 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 }
1784
Adam Cohena9cf38f2011-05-02 15:36:58 -07001785 public DragController getDragController() {
1786 return mDragController;
1787 }
1788
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 @Override
1790 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001791 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 super.startActivityForResult(intent, requestCode);
1793 }
1794
Winson Chung70d72102011-08-12 11:24:35 -07001795 /**
1796 * Indicates that we want global search for this activity by setting the globalSearch
1797 * argument for {@link #startSearch} to true.
1798 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001799 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001800 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001801 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001802
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001803 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001804
Karl Rosaen138a0412009-04-23 19:00:21 -07001805 if (initialQuery == null) {
1806 // Use any text typed in the launcher as the initial query
1807 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001808 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 if (appSearchData == null) {
1810 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001811 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 }
Winson Chungadf0c182012-08-23 14:59:07 -07001813 Rect sourceBounds = new Rect();
1814 if (mSearchDropTargetBar != null) {
1815 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1816 }
Romain Guycbb89e42009-06-08 15:52:54 -07001817
Bjorn Bringertc459e522013-06-07 19:36:01 +01001818 startSearch(initialQuery, selectInitialQuery,
1819 appSearchData, sourceBounds);
1820 }
1821
1822 public void startSearch(String initialQuery,
1823 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001824 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001825 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001826 }
1827
1828 /**
1829 * Starts the global search activity. This code is a copied from SearchManager
1830 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001831 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001832 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001833 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001834 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1835 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1836 if (globalSearchActivity == null) {
1837 Log.w(TAG, "No global search activity found.");
1838 return;
1839 }
1840 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1841 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1842 intent.setComponent(globalSearchActivity);
1843 // Make sure that we have a Bundle to put source in
1844 if (appSearchData == null) {
1845 appSearchData = new Bundle();
1846 } else {
1847 appSearchData = new Bundle(appSearchData);
1848 }
1849 // Set source to package name of app that starts global search, if not set already.
1850 if (!appSearchData.containsKey("source")) {
1851 appSearchData.putString("source", getPackageName());
1852 }
1853 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1854 if (!TextUtils.isEmpty(initialQuery)) {
1855 intent.putExtra(SearchManager.QUERY, initialQuery);
1856 }
1857 if (selectInitialQuery) {
1858 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1859 }
1860 intent.setSourceBounds(sourceBounds);
1861 try {
1862 startActivity(intent);
1863 } catch (ActivityNotFoundException ex) {
1864 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1865 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001866 }
1867
Winson Chung70d72102011-08-12 11:24:35 -07001868 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001869 public boolean onPrepareOptionsMenu(Menu menu) {
1870 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001871 if (!mWorkspace.isInOverviewMode()) {
1872 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001873 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001874 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001875 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001876
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001877 @Override
1878 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001879 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001880 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001881 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001882 }
1883
Joe Onorato9c1289c2009-08-17 11:03:03 -04001884 public boolean isWorkspaceLocked() {
1885 return mWorkspaceLoading || mWaitingForResult;
1886 }
1887
Michael Jurka0280c3b2010-09-17 15:00:07 -07001888 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001889 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001890 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001891 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1892 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001893 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001894 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001895 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001896
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001897 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1898 AppWidgetProviderInfo appWidgetInfo) {
1899 if (appWidgetInfo.configure != null) {
1900 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001901
Bjorn Bringert7984c942009-12-09 15:38:25 +00001902 // Launch over to configure widget, if needed
1903 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001904 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001905 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001906 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001908 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001909 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001910 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001911 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001912 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001913 }
1914 }
Romain Guycbb89e42009-06-08 15:52:54 -07001915
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001916 protected void moveToCustomContentScreen(boolean animate) {
1917 mWorkspace.moveToCustomContentScreen(animate);
1918 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001919 /**
1920 * Process a shortcut drop.
1921 *
1922 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001923 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001924 * @param cell The cell it should be added to, optional
1925 * @param position The location on the screen where it was dropped, optional
1926 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001927 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001928 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001929 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001930 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001931 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001932 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001933
1934 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001935 mPendingAddInfo.cellX = cell[0];
1936 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001937 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001938
1939 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1940 createShortcutIntent.setComponent(componentName);
1941 processShortcut(createShortcutIntent);
1942 }
1943
Adam Cohenfbba09b2011-07-18 21:43:05 -07001944 /**
1945 * Process a widget drop.
1946 *
1947 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001948 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001949 * @param cell The cell it should be added to, optional
1950 * @param position The location on the screen where it was dropped, optional
1951 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001952 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001953 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001954 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001955 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001957 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001958 mPendingAddInfo.minSpanX = info.minSpanX;
1959 mPendingAddInfo.minSpanY = info.minSpanY;
1960
Adam Cohenfbba09b2011-07-18 21:43:05 -07001961 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001962 mPendingAddInfo.cellX = cell[0];
1963 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001964 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001965 if (span != null) {
1966 mPendingAddInfo.spanX = span[0];
1967 mPendingAddInfo.spanY = span[1];
1968 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001969
Adam Cohened66b2b2012-01-23 17:28:51 -08001970 AppWidgetHostView hostView = info.boundWidget;
1971 int appWidgetId;
1972 if (hostView != null) {
1973 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001974 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001975 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001976 // In this case, we either need to start an activity to get permission to bind
1977 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001978 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001979 Bundle options = info.bindOptions;
1980
1981 boolean success = false;
1982 if (options != null) {
1983 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1984 info.componentName, options);
1985 } else {
1986 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1987 info.componentName);
1988 }
1989 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001990 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001991 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001992 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001993 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1994 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1995 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001996 // TODO: we need to make sure that this accounts for the options bundle.
1997 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001998 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1999 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002000 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002001 }
2002
Joe Onoratodeb98af2010-02-19 14:59:39 -08002003 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002004 // Handle case where user selected "Applications"
2005 String applicationName = getResources().getString(R.string.group_applications);
2006 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002007
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002008 if (applicationName != null && applicationName.equals(shortcutName)) {
2009 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2010 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002012 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2013 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002014 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002015 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002017 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002018 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 }
2020
Winson Chung24ab2f12010-09-16 14:10:47 -07002021 void processWallpaper(Intent intent) {
2022 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2023 }
2024
Adam Cohendcd297f2013-06-18 13:13:40 -07002025 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002026 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002027 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 folderInfo.title = getText(R.string.folder_name);
2029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002031 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002032 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002033 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034
2035 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002036 FolderIcon newFolder =
2037 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002038 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002039 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002040 // Force measure the new folder icon
2041 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2042 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002043 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 }
Romain Guycbb89e42009-06-08 15:52:54 -07002045
Joe Onorato9c1289c2009-08-17 11:03:03 -04002046 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002047 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002048 }
2049
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002050 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002051 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002053 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002054 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 }
2056
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002057 protected ComponentName getWallpaperPickerComponent() {
2058 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2059 }
2060
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002061 /**
2062 * Registers various content observers. The current implementation registers
2063 * only a favorites observer to keep track of the favorites applications.
2064 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002065 private void registerContentObservers() {
2066 ContentResolver resolver = getContentResolver();
2067 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2068 true, mWidgetObserver);
2069 }
2070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 @Override
2072 public boolean dispatchKeyEvent(KeyEvent event) {
2073 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2074 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002076 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002077 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002078 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002079 dumpState();
2080 return true;
2081 }
2082 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002083 }
2084 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2085 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002086 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 return true;
2088 }
2089 }
2090
2091 return super.dispatchKeyEvent(event);
2092 }
2093
Joe Onorato88ec0992009-11-19 13:16:06 -08002094 @Override
2095 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002096 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002097 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002098 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002099 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002100 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002101 Folder openFolder = mWorkspace.getOpenFolder();
2102 if (openFolder.isEditingName()) {
2103 openFolder.dismissEditingName();
2104 } else {
2105 closeFolder();
2106 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002107 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002108 mWorkspace.exitWidgetResizeMode();
2109
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002110 // Back button is a no-op here, but give at least some feedback for the button press
2111 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002112 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002113 }
2114
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002115 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002116 * Re-listen when widgets are reset.
2117 */
2118 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002119 if (mAppWidgetHost != null) {
2120 mAppWidgetHost.startListening();
2121 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002122 }
2123
2124 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002125 * Launches the intent referred by the clicked shortcut.
2126 *
2127 * @param v The view representing the clicked shortcut.
2128 */
2129 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002130 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2131 // view has detached (it's possible for this to happen if the view is removed mid touch).
2132 if (v.getWindowToken() == null) {
2133 return;
2134 }
2135
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002136 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002137 return;
2138 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002139
Adam Cohen1697b792013-09-17 19:08:21 -07002140 if (v instanceof Workspace) {
2141 if (mWorkspace.isInOverviewMode()) {
2142 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002143 }
2144 return;
2145 }
2146
2147 if (v instanceof CellLayout) {
2148 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002149 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002150 }
2151 }
2152
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002154 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002155 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002156 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2157 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002158
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002159 // Check for special shortcuts
2160 if (intent.getComponent() != null) {
2161 final String shortcutClass = intent.getComponent().getClassName();
2162
2163 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002164 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002165 return;
2166 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2167 MemoryDumpActivity.startDump(this);
2168 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002169 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2170 toggleShowWeightWatcher();
2171 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002172 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002173 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002174
2175 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002176 int[] pos = new int[2];
2177 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002178 intent.setSourceBounds(new Rect(pos[0], pos[1],
2179 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002180
2181 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002182
Daniel Sandlerff02d492013-08-05 02:12:05 -04002183 mStats.recordLaunch(intent, shortcut);
2184
Michael Jurkaddd62e92011-02-16 17:49:14 -08002185 if (success && v instanceof BubbleTextView) {
2186 mWaitingForResume = (BubbleTextView) v;
2187 mWaitingForResume.setStayPressed(true);
2188 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002190 if (v instanceof FolderIcon) {
2191 FolderIcon fi = (FolderIcon) v;
2192 handleFolderClick(fi);
2193 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002194 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002195 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002196 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002197 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002198 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002199 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002200 }
2201 }
2202
Michael Jurka0e260592010-06-30 17:07:39 -07002203 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002204 return false;
2205 }
2206
Michael Jurkaaf442092010-06-10 17:01:57 -07002207 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002208 * Event handler for the search button
2209 *
2210 * @param v The view that was clicked.
2211 */
2212 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002213 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2214
Amith Yamasania135ba82011-08-09 17:42:01 -07002215 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002216 }
2217
2218 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002219 * Event handler for the voice button
2220 *
2221 * @param v The view that was clicked.
2222 */
2223 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002224 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002225
Bjorn Bringertc459e522013-06-07 19:36:01 +01002226 startVoice();
2227 }
2228
2229 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002230 try {
2231 final SearchManager searchManager =
2232 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2233 ComponentName activityName = searchManager.getGlobalSearchActivity();
2234 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002235 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002236 if (activityName != null) {
2237 intent.setPackage(activityName.getPackageName());
2238 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002239 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002240 } catch (ActivityNotFoundException e) {
2241 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002242 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002243 startActivitySafely(null, intent, "onClickVoiceButton");
2244 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002245 }
2246
2247 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002248 * Event handler for the "grid" button that appears on the home screen, which
2249 * enters all apps mode.
2250 *
2251 * @param v The view that was clicked.
2252 */
2253 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002254 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002255 }
2256
2257 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002258 // Provide the same haptic feedback that the system offers for virtual keys.
2259 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002260 }
2261
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002262 public void onClickAppMarketButton(View v) {
2263 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002264 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002265 } else {
2266 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002267 }
2268 }
2269
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002270 /**
2271 * Called when the user stops interacting with the launcher.
2272 * This implies that the user is now on the homescreen and is not doing housekeeping.
2273 */
2274 protected void onInteractionEnd() {}
2275
2276 /**
2277 * Called when the user starts interacting with the launcher.
2278 * The possible interactions are:
2279 * - open all apps
2280 * - reorder an app shortcut, or a widget
2281 * - open the overview mode.
2282 * This is a good time to stop doing things that only make sense
2283 * when the user is on the homescreen and not doing housekeeping.
2284 */
2285 protected void onInteractionBegin() {}
2286
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002287 void startApplicationDetailsActivity(ComponentName componentName) {
2288 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002289 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2290 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002291 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002292 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002293 }
2294
Michael Jurka1e2f4652013-07-08 18:03:46 -07002295 // returns true if the activity was started
2296 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002297 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002298 // System applications cannot be installed. For now, show a toast explaining that.
2299 // We may give them the option of disabling apps this way.
2300 int messageId = R.string.uninstall_system_app_text;
2301 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002302 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002303 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002304 String packageName = componentName.getPackageName();
2305 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002306 Intent intent = new Intent(
2307 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002308 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2309 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002310 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002311 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002312 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002313 }
2314
Michael Jurka86a720e2012-05-09 11:23:23 -07002315 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002316 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002317
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002318 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002319 // Only launch using the new animation if the shortcut has not opted out (this is a
2320 // private contract between launcher and may be ignored in the future).
2321 boolean useLaunchAnimation = (v != null) &&
2322 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2323 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002324 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2325 v.getMeasuredWidth(), v.getMeasuredHeight());
2326
2327 startActivity(intent, opts.toBundle());
2328 } else {
2329 startActivity(intent);
2330 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002331 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002332 } catch (SecurityException e) {
2333 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002334 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002335 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002336 "or use the exported attribute for this activity. "
2337 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002339 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002341
Michael Jurka86a720e2012-05-09 11:23:23 -07002342 boolean startActivitySafely(View v, Intent intent, Object tag) {
2343 boolean success = false;
2344 try {
2345 success = startActivity(v, intent, tag);
2346 } catch (ActivityNotFoundException e) {
2347 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2348 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2349 }
2350 return success;
2351 }
2352
Adam Cohena9cf38f2011-05-02 15:36:58 -07002353 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002354 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002355 Folder openFolder = mWorkspace.getFolderForTag(info);
2356
2357 // If the folder info reports that the associated folder is open, then verify that
2358 // it is actually opened. There have been a few instances where this gets out of sync.
2359 if (info.opened && openFolder == null) {
2360 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002361 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002362 info.opened = false;
2363 }
2364
Adam Cohenfb91f302012-06-11 15:45:18 -07002365 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366 // Close any open folder
2367 closeFolder();
2368 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002369 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 } else {
2371 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372 int folderScreen;
2373 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002374 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 // .. and close it
2376 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002377 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378 // Close any folder open on the current screen
2379 closeFolder();
2380 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002381 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 }
2383 }
2384 }
2385 }
2386
Adam Cohen268c4752012-06-06 17:47:33 -07002387 /**
2388 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2389 * in the DragLayer in the exact absolute location of the original FolderIcon.
2390 */
2391 private void copyFolderIconToImage(FolderIcon fi) {
2392 final int width = fi.getMeasuredWidth();
2393 final int height = fi.getMeasuredHeight();
2394
2395 // Lazy load ImageView, Bitmap and Canvas
2396 if (mFolderIconImageView == null) {
2397 mFolderIconImageView = new ImageView(this);
2398 }
2399 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2400 mFolderIconBitmap.getHeight() != height) {
2401 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2402 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2403 }
2404
2405 DragLayer.LayoutParams lp;
2406 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2407 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2408 } else {
2409 lp = new DragLayer.LayoutParams(width, height);
2410 }
2411
Adam Cohen307fe232012-08-16 17:55:58 -07002412 // The layout from which the folder is being opened may be scaled, adjust the starting
2413 // view size by this scale factor.
2414 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002415 lp.customPosition = true;
2416 lp.x = mRectForFolderAnimation.left;
2417 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002418 lp.width = (int) (scale * width);
2419 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002420
2421 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2422 fi.draw(mFolderIconCanvas);
2423 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002424 if (fi.getFolder() != null) {
2425 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2426 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002427 }
Adam Cohen268c4752012-06-06 17:47:33 -07002428 // Just in case this image view is still in the drag layer from a previous animation,
2429 // we remove it and re-add it.
2430 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2431 mDragLayer.removeView(mFolderIconImageView);
2432 }
2433 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002434 if (fi.getFolder() != null) {
2435 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002436 }
Adam Cohen268c4752012-06-06 17:47:33 -07002437 }
2438
Adam Cohen2801caf2011-05-13 20:57:39 -07002439 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002440 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002441 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2442 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2443 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2444
Adam Cohenc51934b2011-07-26 21:07:43 -07002445 FolderInfo info = (FolderInfo) fi.getTag();
2446 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2447 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002448 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2449 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002450 }
2451
Adam Cohen268c4752012-06-06 17:47:33 -07002452 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2453 copyFolderIconToImage(fi);
2454 fi.setVisibility(View.INVISIBLE);
2455
Michael Jurka2ecf9952012-06-18 12:52:28 -07002456 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002457 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002458 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2459 oa.start();
2460 }
2461
Adam Cohen268c4752012-06-06 17:47:33 -07002462 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002463 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002464 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2465 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2466 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2467
Adam Cohen268c4752012-06-06 17:47:33 -07002468 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002469
Adam Cohen268c4752012-06-06 17:47:33 -07002470 // We remove and re-draw the FolderIcon in-case it has changed
2471 mDragLayer.removeView(mFolderIconImageView);
2472 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002473 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002474 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002475 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002476 oa.addListener(new AnimatorListenerAdapter() {
2477 @Override
2478 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002479 if (cl != null) {
2480 cl.clearFolderLeaveBehind();
2481 // Remove the ImageView copy of the FolderIcon and make the original visible.
2482 mDragLayer.removeView(mFolderIconImageView);
2483 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002484 }
2485 }
2486 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002487 oa.start();
2488 }
2489
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002490 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002491 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002492 * is animated relative to the specified View. If the View is null, no animation
2493 * is played.
2494 *
2495 * @param folderInfo The FolderInfo describing the folder to open.
2496 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002497 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002498 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002499 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002500
Adam Cohena9cf38f2011-05-02 15:36:58 -07002501 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502
Adam Cohen4554ee12011-08-03 16:13:21 -07002503 // Just verify that the folder hasn't already been added to the DragLayer.
2504 // There was a one-off crash where the folder had a parent already.
2505 if (folder.getParent() == null) {
2506 mDragLayer.addView(folder);
2507 mDragController.addDropTarget((DropTarget) folder);
2508 } else {
2509 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2510 folder.getParent() + ").");
2511 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002512 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002513 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002514
2515 // Notify the accessibility manager that this folder "window" has appeared and occluded
2516 // the workspace items
2517 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2518 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002519 }
2520
2521 public void closeFolder() {
2522 Folder folder = mWorkspace.getOpenFolder();
2523 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002524 if (folder.isEditingName()) {
2525 folder.dismissEditingName();
2526 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002527 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002528
2529 // Dismiss the folder cling
2530 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002531 }
2532 }
2533
2534 void closeFolder(Folder folder) {
2535 folder.getInfo().opened = false;
2536
2537 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2538 if (parent != null) {
2539 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2540 shrinkAndFadeInFolderIcon(fi);
2541 }
2542 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002543
2544 // Notify the accessibility manager that this folder "window" has disappeard and no
2545 // longer occludeds the workspace items
2546 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002547 }
2548
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002549 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002550 if (!isDraggingEnabled()) return false;
2551 if (isWorkspaceLocked()) return false;
2552 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002553
Adam Cohen1697b792013-09-17 19:08:21 -07002554 if (v instanceof Workspace) {
2555 if (!mWorkspace.isInOverviewMode()) {
2556 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2557 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2558 mWorkspace.enterOverviewMode();
2559 }
2560 return true;
2561 }
2562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002563 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002564 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002565 }
2566
Michael Jurka0280c3b2010-09-17 15:00:07 -07002567 resetAddInfo();
2568 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002570 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002571 return true;
2572 }
2573
Winson Chung3d503fb2011-07-13 17:25:49 -07002574 // The hotseat touch handling does not go through Workspace, and we always allow long press
2575 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002576 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002577 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2578 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002579 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002580 // User long pressed on empty space
2581 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2582 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2583 // Disabling reordering until we sort out some issues.
2584 if (mWorkspace.isInOverviewMode()) {
2585 mWorkspace.startReordering(v);
2586 } else {
2587 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002588 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002589 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002590 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002592 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 }
2594 }
2595 }
2596 return true;
2597 }
2598
Winson Chung3d503fb2011-07-13 17:25:49 -07002599 boolean isHotseatLayout(View layout) {
2600 return mHotseat != null && layout != null &&
2601 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2602 }
2603 Hotseat getHotseat() {
2604 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002605 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002606 View getOverviewPanel() {
2607 return mOverviewPanel;
2608 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002609 SearchDropTargetBar getSearchBar() {
2610 return mSearchDropTargetBar;
2611 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002612
Winson Chung3d503fb2011-07-13 17:25:49 -07002613 /**
2614 * Returns the CellLayout of the specified container at the specified screen.
2615 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002616 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002617 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2618 if (mHotseat != null) {
2619 return mHotseat.getLayout();
2620 } else {
2621 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002622 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002623 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002624 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002625 }
2626 }
2627
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002628 Workspace getWorkspace() {
2629 return mWorkspace;
2630 }
2631
Daniel Sandler843e8602010-06-07 14:59:01 -04002632 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002633 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002634 }
2635
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002636 /**
2637 * Helper method for the cameraZoomIn/cameraZoomOut animations
2638 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002639 * @param scaleFactor The scale factor used for the zoom
2640 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002641 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002642 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002643 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002645
Craig Mautner360310b2012-10-26 15:13:08 -07002646 private void setWorkspaceBackground(boolean workspace) {
2647 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002648 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002649 }
2650
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002651 void updateWallpaperVisibility(boolean visible) {
2652 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2653 int curflags = getWindow().getAttributes().flags
2654 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2655 if (wpflags != curflags) {
2656 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2657 }
Craig Mautner360310b2012-10-26 15:13:08 -07002658 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002659 }
2660
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002661 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2662 if (v instanceof LauncherTransitionable) {
2663 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2664 }
2665 }
2666
Michael Jurkabed61d22012-02-14 22:51:29 -08002667 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2668 if (v instanceof LauncherTransitionable) {
2669 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2670 }
Winson Chung70442722012-02-10 15:43:22 -08002671
2672 // Update the workspace transition step as well
2673 dispatchOnLauncherTransitionStep(v, 0f);
2674 }
2675
2676 private void dispatchOnLauncherTransitionStep(View v, float t) {
2677 if (v instanceof LauncherTransitionable) {
2678 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2679 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002680 }
2681
2682 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2683 if (v instanceof LauncherTransitionable) {
2684 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2685 }
Winson Chung70442722012-02-10 15:43:22 -08002686
2687 // Update the workspace transition step as well
2688 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002689 }
2690
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002691 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002692 * Things to test when changing the following seven functions.
2693 * - Home from workspace
2694 * - from center screen
2695 * - from other screens
2696 * - Home from all apps
2697 * - from center screen
2698 * - from other screens
2699 * - Back from all apps
2700 * - from center screen
2701 * - from other screens
2702 * - Launch app from workspace and quit
2703 * - with back
2704 * - with home
2705 * - Launch app from all apps and quit
2706 * - with back
2707 * - with home
2708 * - Go to a screen that's not the default, then all
2709 * apps, and launch and app, and go back
2710 * - with back
2711 * -with home
2712 * - On workspace, long press power and go back
2713 * - with back
2714 * - with home
2715 * - On all apps, long press power and go back
2716 * - with back
2717 * - with home
2718 * - On workspace, power off
2719 * - On all apps, power off
2720 * - Launch an app and turn off the screen while in that app
2721 * - Go back with home key
2722 * - Go back with back key TODO: make this not go to workspace
2723 * - From all apps
2724 * - From workspace
2725 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2726 * - From all apps
2727 * - From the center workspace
2728 * - From another workspace
2729 */
2730
2731 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002732 * Zoom the camera out from the workspace to reveal 'toView'.
2733 * Assumes that the view to show is anchored at either the very top or very bottom
2734 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002735 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002736 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002737 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2738 showAppsCustomizeHelper(animated, springLoaded, contentType);
2739 }
2740 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2741 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002742 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002743 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002744 mStateAnimation.cancel();
2745 mStateAnimation = null;
2746 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002747 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002748
Winson Chungf0ea4d32011-06-06 14:27:16 -07002749 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2750 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2751 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002752 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002753 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002754 final int startDelay =
2755 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002756
Michael Jurkab3e22d92011-10-31 15:58:33 -07002757 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002758
Michael Jurkad74c9842011-07-10 12:44:21 -07002759 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002760 Animator workspaceAnim =
2761 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002762 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2763 // Set the content type for the all apps space
2764 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2765 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002766
2767 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002768 toView.setScaleX(scale);
2769 toView.setScaleY(scale);
2770 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2771 scaleAnim.
2772 scaleX(1f).scaleY(1f).
2773 setDuration(duration).
2774 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002775
Winson Chungf0ea4d32011-06-06 14:27:16 -07002776 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002777 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002778 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002779 .ofFloat(toView, "alpha", 0f, 1f)
2780 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002781 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002782 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2783 @Override
2784 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002785 if (animation == null) {
2786 throw new RuntimeException("animation is null");
2787 }
Winson Chung70442722012-02-10 15:43:22 -08002788 float t = (Float) animation.getAnimatedValue();
2789 dispatchOnLauncherTransitionStep(fromView, t);
2790 dispatchOnLauncherTransitionStep(toView, t);
2791 }
2792 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002793
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002794 // toView should appear right at the end of the workspace shrink
2795 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002796 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002797 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002798 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002799
2800 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002801 boolean animationCancelled = false;
2802
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002803 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002804 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002805 // Prepare the position
2806 toView.setTranslationX(0.0f);
2807 toView.setTranslationY(0.0f);
2808 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002809 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002810 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002811 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002812 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002813 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2814 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002815
Winson Chungc7d2b602012-05-16 17:02:20 -07002816 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002817 if (mSearchDropTargetBar != null) {
2818 mSearchDropTargetBar.hideSearchBar(false);
2819 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002820 }
2821
Adam Cohencff6af82011-09-13 14:51:53 -07002822 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002823 public void onAnimationCancel(Animator animation) {
2824 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002825 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002826 });
2827
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002828 if (workspaceAnim != null) {
2829 mStateAnimation.play(workspaceAnim);
2830 }
Michael Jurka1899a362011-11-03 13:50:45 -07002831
2832 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002833
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002834 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2835 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002836
2837 // If any of the objects being animated haven't been measured/laid out
2838 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002839 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002840 (mWorkspace.getMeasuredWidth() == 0) ||
2841 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002842 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002843 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002844
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002845 final AnimatorSet stateAnimation = mStateAnimation;
2846 final Runnable startAnimRunnable = new Runnable() {
2847 public void run() {
2848 // Check that mStateAnimation hasn't changed while
2849 // we waited for a layout/draw pass
2850 if (mStateAnimation != stateAnimation)
2851 return;
2852 setPivotsForZoom(toView, scale);
2853 dispatchOnLauncherTransitionStart(fromView, animated, false);
2854 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002855 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002856 }
2857 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002858 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002859 final ViewTreeObserver observer = toView.getViewTreeObserver();
2860 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2861 public void onGlobalLayout() {
2862 startAnimRunnable.run();
2863 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2864 }
2865 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002866 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002867 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002868 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002869 } else {
2870 toView.setTranslationX(0.0f);
2871 toView.setTranslationY(0.0f);
2872 toView.setScaleX(1.0f);
2873 toView.setScaleY(1.0f);
2874 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002875 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002876
Daniel Sandlere4f98912013-06-25 15:13:26 -04002877 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002878 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002879 if (mSearchDropTargetBar != null) {
2880 mSearchDropTargetBar.hideSearchBar(false);
2881 }
Michael Jurkaabded662011-03-04 12:06:57 -08002882 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002883 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002884 dispatchOnLauncherTransitionStart(fromView, animated, false);
2885 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002886 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002887 dispatchOnLauncherTransitionStart(toView, animated, false);
2888 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002889 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002890 }
2891
2892 /**
2893 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002894 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002895 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002896 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002897 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2898 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002899
Michael Jurkab3e22d92011-10-31 15:58:33 -07002900 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002901 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002902 mStateAnimation.cancel();
2903 mStateAnimation = null;
2904 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002905 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002906
Winson Chungf0ea4d32011-06-06 14:27:16 -07002907 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002908 final int fadeOutDuration =
2909 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002910 final float scaleFactor = (float)
2911 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2912 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002913 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002914 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002915 if (toState == State.WORKSPACE) {
2916 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2917 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002918 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002919 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2920 workspaceAnim = mWorkspace.getChangeStateAnimation(
2921 Workspace.State.SPRING_LOADED, animated);
2922 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002923
Michael Jurkab3e22d92011-10-31 15:58:33 -07002924 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002925 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002926 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002927 final LauncherViewPropertyAnimator scaleAnim =
2928 new LauncherViewPropertyAnimator(fromView);
2929 scaleAnim.
2930 scaleX(scaleFactor).scaleY(scaleFactor).
2931 setDuration(duration).
2932 setInterpolator(new Workspace.ZoomInInterpolator());
2933
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002934 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002935 .ofFloat(fromView, "alpha", 1f, 0f)
2936 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002937 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002938 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2939 @Override
2940 public void onAnimationUpdate(ValueAnimator animation) {
2941 float t = 1f - (Float) animation.getAnimatedValue();
2942 dispatchOnLauncherTransitionStep(fromView, t);
2943 dispatchOnLauncherTransitionStep(toView, t);
2944 }
2945 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002946
Michael Jurka2ecf9952012-06-18 12:52:28 -07002947 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002948
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002949 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2950 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002951 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002952
2953 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002954 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002955 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002956 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002957 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2958 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002959 if (onCompleteRunnable != null) {
2960 onCompleteRunnable.run();
2961 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002962 mAppsCustomizeContent.updateCurrentPageScroll();
2963 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002964 }
2965 });
2966
Winson Chungf0ea4d32011-06-06 14:27:16 -07002967 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002968 if (workspaceAnim != null) {
2969 mStateAnimation.play(workspaceAnim);
2970 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002971 dispatchOnLauncherTransitionStart(fromView, animated, true);
2972 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002973 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002974 } else {
2975 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002976 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002977 dispatchOnLauncherTransitionStart(fromView, animated, true);
2978 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002979 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002980 dispatchOnLauncherTransitionStart(toView, animated, true);
2981 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002982 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002983 }
2984
Michael Jurkae326f182011-11-21 14:05:46 -08002985 @Override
2986 public void onTrimMemory(int level) {
2987 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002988 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002989 mAppsCustomizeTabHost.onTrimMemory();
2990 }
2991 }
2992
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002993 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002994 showWorkspace(animated, null);
2995 }
2996
2997 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002998 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07002999 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003000 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003001 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003002
Winson Chungc7d2b602012-05-16 17:02:20 -07003003 // Show the search bar (only animate if we were showing the drop target bar in spring
3004 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003005 if (mSearchDropTargetBar != null) {
3006 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3007 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003008
Michael Jurkab3e22d92011-10-31 15:58:33 -07003009 // Set focus to the AppsCustomize button
3010 if (mAllAppsButton != null) {
3011 mAllAppsButton.requestFocus();
3012 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003013 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003014
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003015 // Change the state *after* we've called all the transition code
3016 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003017
Winson Chung5fb63472011-02-02 17:03:37 -08003018 // Resume the auto-advance of widgets
3019 mUserPresent = true;
3020 updateRunning();
3021
alanv1d4fde62012-10-17 13:15:47 -07003022 // Send an accessibility event to announce the context change
3023 getWindow().getDecorView()
3024 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003025
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003026 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003027 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003028 }
3029
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003030 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003031 }
3032
Winson Chungc58497e2013-09-03 17:48:37 -07003033 void showAllApps(boolean animated,
3034 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003035 if (mState != State.WORKSPACE) return;
3036
Winson Chungc58497e2013-09-03 17:48:37 -07003037 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003038 mAppsCustomizeTabHost.requestFocus();
3039
Michael Jurkab3e22d92011-10-31 15:58:33 -07003040 // Change the state *after* we've called all the transition code
3041 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003042 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003043
3044 // Pause the auto-advance of widgets until we are out of AllApps
3045 mUserPresent = false;
3046 updateRunning();
3047 closeFolder();
3048
3049 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003050 getWindow().getDecorView()
3051 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003052 }
3053
Adam Cohen7777d962011-08-18 18:58:38 -07003054 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003055 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003056 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003057 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003058 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003059 }
Adam Cohen7777d962011-08-18 18:58:38 -07003060
Adam Cohened66b2b2012-01-23 17:28:51 -08003061 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3062 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003063 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3064
Winson Chunge7a03942011-08-05 15:05:12 -07003065 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003066 @Override
3067 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003068 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003069 // Before we show workspace, hide all apps again because
3070 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3071 // clean up our state transition functions
3072 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003073 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003074 } else {
3075 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003076 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003077 }
3078 }, (extendedDelay ?
3079 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3080 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3081 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003082
Michael Jurkad3ef3062010-11-23 16:23:58 -08003083 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003084 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 final boolean animated = true;
3086 final boolean springLoaded = true;
3087 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003088 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003089 }
3090 // Otherwise, we are not in spring loaded mode, so don't do anything.
3091 }
3092
Michael Jurkab3e22d92011-10-31 15:58:33 -07003093 void lockAllApps() {
3094 // TODO
3095 }
3096
3097 void unlockAllApps() {
3098 // TODO
3099 }
3100
Winson Chungf0ea4d32011-06-06 14:27:16 -07003101 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003102 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003103 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003104 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003105 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003106 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003107 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003108 int duration = 0;
3109 if (mSearchDropTargetBar != null) {
3110 duration = mSearchDropTargetBar.getTransitionInDuration();
3111 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003112 mHotseat.animate().alpha(1f).setDuration(duration);
3113 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003114 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003115 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003116 }
3117 }
3118 }
3119
3120 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003121 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003122 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003123 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003124 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003125 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003126 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003127 int duration = 0;
3128 if (mSearchDropTargetBar != null) {
3129 duration = mSearchDropTargetBar.getTransitionOutDuration();
3130 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003131 mHotseat.animate().alpha(0f).setDuration(duration);
3132 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003133 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003134 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003135 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003136 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003137 }
3138
Patrick Dubroy5f445422011-02-18 14:35:21 -08003139 /**
3140 * Add an item from all apps or customize onto the given workspace screen.
3141 * If layout is null, add to the current screen.
3142 */
3143 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003144 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003145 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003146 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003147 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003148
Winson Chungdff8ebb2011-09-08 17:25:31 -07003149 /** Maps the current orientation to an index for referencing orientation correct global icons */
3150 private int getCurrentOrientationIndexForGlobalIcons() {
3151 // default - 0, landscape - 1
3152 switch (getResources().getConfiguration().orientation) {
3153 case Configuration.ORIENTATION_LANDSCAPE:
3154 return 1;
3155 default:
3156 return 0;
3157 }
3158 }
3159
Michael Jurkaae65ee32012-04-30 11:45:54 -07003160 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003161 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003162 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003163 // Look for the toolbar icon specified in the activity meta-data
3164 Bundle metaData = packageManager.getActivityInfo(
3165 activityName, PackageManager.GET_META_DATA).metaData;
3166 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003167 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003168 if (iconResId != 0) {
3169 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003170 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003171 }
3172 }
3173 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003174 // This can happen if the activity defines an invalid drawable
3175 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3176 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003177 } catch (Resources.NotFoundException nfe) {
3178 // This can happen if the activity defines an invalid drawable
3179 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3180 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003181 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003182 return null;
3183 }
3184
3185 // if successful in getting icon, return it; otherwise, set button to use default drawable
3186 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003187 int buttonId, ComponentName activityName, int fallbackDrawableId,
3188 String toolbarResourceName) {
3189 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003190 Resources r = getResources();
3191 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3192 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003193
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003194 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003195 // If we were unable to find the icon via the meta-data, use a generic one
3196 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003197 toolbarIcon = r.getDrawable(fallbackDrawableId);
3198 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003199 if (button != null) {
3200 button.setCompoundDrawables(toolbarIcon, null, null, null);
3201 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003202 return null;
3203 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003204 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003205 if (button != null) {
3206 button.setCompoundDrawables(toolbarIcon, null, null, null);
3207 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003208 return toolbarIcon.getConstantState();
3209 }
3210 }
3211
3212 // if successful in getting icon, return it; otherwise, set button to use default drawable
3213 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003214 int buttonId, ComponentName activityName, int fallbackDrawableId,
3215 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003216 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003217 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003218
Michael Jurka19e0fc52011-07-22 18:00:21 -07003219 if (button != null) {
3220 // If we were unable to find the icon via the meta-data, use a
3221 // generic one
3222 if (toolbarIcon == null) {
3223 button.setImageResource(fallbackDrawableId);
3224 } else {
3225 button.setImageDrawable(toolbarIcon);
3226 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003227 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003228
3229 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3230
Michael Jurka0423dcf2010-10-05 14:56:18 -07003231 }
3232
Winson Chung1b884092012-06-08 17:13:02 -07003233 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003234 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003235 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003236 }
3237
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003238 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003239 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003240 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003241 }
3242
Winson Chungbb185bd2011-11-21 12:31:42 -08003243 private void invalidatePressedFocusedStates(View container, View button) {
3244 if (container instanceof HolographicLinearLayout) {
3245 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3246 layout.invalidatePressedFocusedStates();
3247 } else if (button instanceof HolographicImageView) {
3248 HolographicImageView view = (HolographicImageView) button;
3249 view.invalidatePressedFocusedStates();
3250 }
3251 }
3252
Cristina Stancu476493b2013-08-07 17:20:14 +01003253 public View getQsbBar() {
3254 if (mQsbBar == null) {
3255 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3256 }
3257 return mQsbBar;
3258 }
3259
3260 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003261 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003262 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003263 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003264 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003265
Winson Chung1cad91e2011-05-25 17:41:01 -07003266 final SearchManager searchManager =
3267 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3268 ComponentName activityName = searchManager.getGlobalSearchActivity();
3269 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003270 int coi = getCurrentOrientationIndexForGlobalIcons();
3271 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003272 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3273 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3274 if (sGlobalSearchIcon[coi] == null) {
3275 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3276 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3277 TOOLBAR_ICON_METADATA_NAME);
3278 }
3279
Winson Chungc51db6a2011-10-05 11:44:49 -07003280 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3281 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003282 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003283 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003284 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003285 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003286 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3287 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003288 if (searchButton != null) searchButton.setVisibility(View.GONE);
3289 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003290 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003291 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003292 }
3293 }
3294
Cristina Stancu476493b2013-08-07 17:20:14 +01003295 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003296 final View searchButtonContainer = findViewById(R.id.search_button_container);
3297 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003298 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003299 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003300 }
3301
Cristina Stancu476493b2013-08-07 17:20:14 +01003302 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003303 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003304 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003305
Winson Chungc51db6a2011-10-05 11:44:49 -07003306 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003307 final SearchManager searchManager =
3308 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3309 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3310
3311 ComponentName activityName = null;
3312 if (globalSearchActivity != null) {
3313 // Check if the global search activity handles voice search
3314 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3315 intent.setPackage(globalSearchActivity.getPackageName());
3316 activityName = intent.resolveActivity(getPackageManager());
3317 }
3318
3319 if (activityName == null) {
3320 // Fallback: check if an activity other than the global search activity
3321 // resolves this
3322 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3323 activityName = intent.resolveActivity(getPackageManager());
3324 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003325 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003326 int coi = getCurrentOrientationIndexForGlobalIcons();
3327 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003328 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3329 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3330 if (sVoiceSearchIcon[coi] == null) {
3331 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3332 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3333 TOOLBAR_ICON_METADATA_NAME);
3334 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003335 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003336 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003337 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003338 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003339 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003340 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003341 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003342 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003343 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003344 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003345 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003346 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003347
Cristina Stancu476493b2013-08-07 17:20:14 +01003348 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003349 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3350 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003351 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003352 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003353 }
3354
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003355 public void setVoiceButtonProxyVisible(boolean visible) {
3356 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3357 if (voiceButtonProxy != null) {
3358 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3359 }
3360 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003361 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003362 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003363 */
3364 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003365 final View marketButton = findViewById(R.id.market_button);
3366 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3367 // Find the app market activity by resolving an intent.
3368 // (If multiple app markets are installed, it will return the ResolverActivity.)
3369 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003370 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003371 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003372 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003373 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003374 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3375 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003376 marketButton.setVisibility(View.VISIBLE);
3377 } else {
3378 // We should hide and disable the view so that we don't try and restore the visibility
3379 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3380 marketButton.setVisibility(View.GONE);
3381 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003382 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003383 }
3384
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003385 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003386 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3387 Resources r = getResources();
3388 Drawable marketIconDrawable = d.newDrawable(r);
3389 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3390 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3391 marketIconDrawable.setBounds(0, 0, w, h);
3392
3393 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003394 }
3395
Michael Jurkad7c28052012-04-27 15:43:36 -07003396 @Override
3397 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003398 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003399 final List<CharSequence> text = event.getText();
3400 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003401 // Populate event with a fake title based on the current state.
3402 if (mState == State.APPS_CUSTOMIZE) {
3403 text.add(getString(R.string.all_apps_button_label));
3404 } else {
3405 text.add(getString(R.string.all_apps_home_button_label));
3406 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003407 return result;
3408 }
3409
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003410 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003411 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003412 */
3413 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3414 @Override
3415 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003416 closeSystemDialogs();
3417 }
3418 }
3419
3420 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003421 * Receives notifications whenever the appwidgets are reset.
3422 */
3423 private class AppWidgetResetObserver extends ContentObserver {
3424 public AppWidgetResetObserver() {
3425 super(new Handler());
3426 }
3427
3428 @Override
3429 public void onChange(boolean selfChange) {
3430 onAppWidgetReset();
3431 }
3432 }
3433
3434 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003435 * If the activity is currently paused, signal that we need to run the passed Runnable
3436 * in onResume.
3437 *
3438 * This needs to be called from incoming places where resources might have been loaded
3439 * while we are paused. That is becaues the Configuration might be wrong
3440 * when we're not running, and if it comes back to what it was when we
3441 * were paused, we are not restarted.
3442 *
3443 * Implementation of the method from LauncherModel.Callbacks.
3444 *
3445 * @return true if we are currently paused. The caller might be able to
3446 * skip some work in that case since we will come back again.
3447 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003448 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003449 if (mPaused) {
3450 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003451 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003452 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003453 }
3454 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003455 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003456 return true;
3457 } else {
3458 return false;
3459 }
3460 }
3461
Michael Jurkac402cd92013-05-20 15:49:32 +02003462 private boolean waitUntilResume(Runnable run) {
3463 return waitUntilResume(run, false);
3464 }
3465
Michael Jurka1e2f4652013-07-08 18:03:46 -07003466 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003467 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003468 }
3469
Michael Jurka7607c2f2013-04-03 14:33:19 -07003470 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003471 * If the activity is currently paused, signal that we need to re-run the loader
3472 * in onResume.
3473 *
3474 * This needs to be called from incoming places where resources might have been loaded
3475 * while we are paused. That is becaues the Configuration might be wrong
3476 * when we're not running, and if it comes back to what it was when we
3477 * were paused, we are not restarted.
3478 *
3479 * Implementation of the method from LauncherModel.Callbacks.
3480 *
3481 * @return true if we are currently paused. The caller might be able to
3482 * skip some work in that case since we will come back again.
3483 */
3484 public boolean setLoadOnResume() {
3485 if (mPaused) {
3486 Log.i(TAG, "setLoadOnResume");
3487 mOnResumeNeedsLoad = true;
3488 return true;
3489 } else {
3490 return false;
3491 }
3492 }
3493
3494 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003495 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003496 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003497 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003498 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003499 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003500 } else {
3501 return SCREEN_COUNT / 2;
3502 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003503 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003504
Joe Onorato9c1289c2009-08-17 11:03:03 -04003505 /**
3506 * Refreshes the shortcuts shown on the workspace.
3507 *
3508 * Implementation of the method from LauncherModel.Callbacks.
3509 */
3510 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003511 // If we're starting binding all over again, clear any bind calls we'd postponed in
3512 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3513 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003514 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003515
Winson Chungd64d1762013-08-20 14:37:16 -07003516 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003517 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003518 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003519
Michael Jurka05bf6442011-11-30 20:28:53 -08003520 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003521 if (mHotseat != null) {
3522 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003523 }
3524 }
3525
Adam Cohendcd297f2013-06-18 13:13:40 -07003526 @Override
3527 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003528 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003529
Adam Cohen5084cba2013-09-03 12:01:16 -07003530 // If there are no screens, we need to have an empty screen
3531 if (orderedScreenIds.size() == 0) {
3532 mWorkspace.addExtraEmptyScreen();
3533 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003534
3535 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003536 // setCurrentPage() so ensure that all pages are added before calling this).
3537 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003538 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3539 mWorkspace.createCustomContentPage();
3540 }
Winson Chung64359a52013-07-08 17:17:08 -07003541 }
3542
3543 @Override
3544 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003545 int count = orderedScreenIds.size();
3546 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003547 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003548 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003549 }
3550
Adam Cohen39a06042013-07-19 14:30:12 -07003551 private boolean shouldShowWeightWatcher() {
3552 String spKey = LauncherAppState.getSharedPreferencesKey();
3553 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003554 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003555
3556 return show;
3557 }
3558
Adam Cohen4caf2982013-08-20 18:54:31 -07003559 private boolean emailSent() {
3560 String spKey = LauncherAppState.getSharedPreferencesKey();
3561 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3562 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3563 return show;
3564 }
3565
3566 private void setEmailSent(boolean sent) {
3567 String spKey = LauncherAppState.getSharedPreferencesKey();
3568 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3569
3570 SharedPreferences.Editor editor = sp.edit();
3571 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3572 editor.commit();
3573 }
3574
Adam Cohen39a06042013-07-19 14:30:12 -07003575 private void toggleShowWeightWatcher() {
3576 String spKey = LauncherAppState.getSharedPreferencesKey();
3577 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3578 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3579
3580 show = !show;
3581
3582 SharedPreferences.Editor editor = sp.edit();
3583 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3584 editor.commit();
3585
3586 if (mWeightWatcher != null) {
3587 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3588 }
3589 }
3590
Winson Chungd64d1762013-08-20 14:37:16 -07003591 public void bindAppsAdded(final ArrayList<Long> newScreens,
3592 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003593 final ArrayList<ItemInfo> addAnimated,
3594 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003595 Runnable r = new Runnable() {
3596 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003597 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003598 }
3599 };
3600 if (waitUntilResume(r)) {
3601 return;
3602 }
3603
Winson Chungd64d1762013-08-20 14:37:16 -07003604 // Add the new screens
3605 bindAddScreens(newScreens);
3606
3607 // We add the items without animation on non-visible pages, and with
3608 // animations on the new page (which we will try and snap to).
3609 if (!addNotAnimated.isEmpty()) {
3610 bindItems(addNotAnimated, 0,
3611 addNotAnimated.size(), false);
3612 }
3613 if (!addAnimated.isEmpty()) {
3614 bindItems(addAnimated, 0,
3615 addAnimated.size(), true);
3616 }
Winson Chungc58497e2013-09-03 17:48:37 -07003617
3618 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3619 addedApps != null && mAppsCustomizeContent != null) {
3620 mAppsCustomizeContent.addApps(addedApps);
3621 }
Winson Chungd64d1762013-08-20 14:37:16 -07003622 }
3623
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003624 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003625 * Bind the items start-end from the list.
3626 *
3627 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003628 */
Winson Chung64359a52013-07-08 17:17:08 -07003629 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3630 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003631 Runnable r = new Runnable() {
3632 public void run() {
3633 bindItems(shortcuts, start, end, forceAnimateIcons);
3634 }
3635 };
3636 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003637 return;
3638 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003639
Winson Chungf0c6ae02012-03-21 16:10:31 -07003640 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003641 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3642 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003643 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003644 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003645 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003646 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003647 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003648
3649 // Short circuit if we are loading dock items for a configuration which has no dock
3650 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3651 mHotseat == null) {
3652 continue;
3653 }
3654
Joe Onorato9c1289c2009-08-17 11:03:03 -04003655 switch (item.itemType) {
3656 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3657 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003658 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003659 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003660
Winson Chung64359a52013-07-08 17:17:08 -07003661 /*
3662 * TODO: FIX collision case
3663 */
Winson Chungce376632013-07-11 16:12:41 -07003664 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3665 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3666 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3667 throw new RuntimeException("OCCUPIED");
3668 }
Winson Chung64359a52013-07-08 17:17:08 -07003669 }
3670
Adam Cohendcd297f2013-06-18 13:13:40 -07003671 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3672 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003673 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003674 // Animate all the applications up now
3675 shortcut.setAlpha(0f);
3676 shortcut.setScaleX(0f);
3677 shortcut.setScaleY(0f);
3678 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003679 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003680 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003681 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003682 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003683 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003684 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003685 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003686 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3687 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003688 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003689 default:
3690 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003691 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003692 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693
Winson Chung997a9232013-07-24 15:33:46 -07003694 if (animateIcons) {
3695 // Animate to the correct page
3696 if (newShortcutsScreenId > -1) {
3697 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003698 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003699 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003700 // We post the animation slightly delayed to prevent slowdowns
3701 // when we are loading right after we return to launcher.
3702 mWorkspace.postDelayed(new Runnable() {
3703 public void run() {
3704 mWorkspace.snapToPage(newScreenIndex);
3705 mWorkspace.postDelayed(new Runnable() {
3706 public void run() {
3707 anim.playTogether(bounceAnims);
3708 anim.start();
3709 }
3710 }, NEW_APPS_ANIMATION_DELAY);
3711 }
3712 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003713 }
3714 }
Winson Chung64359a52013-07-08 17:17:08 -07003715 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003716 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003717 }
3718
Joe Onorato9c1289c2009-08-17 11:03:03 -04003719 /**
3720 * Implementation of the method from LauncherModel.Callbacks.
3721 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003722 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003723 Runnable r = new Runnable() {
3724 public void run() {
3725 bindFolders(folders);
3726 }
3727 };
3728 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003729 return;
3730 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003731 sFolders.clear();
3732 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003733 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003734
3735 /**
3736 * Add the views for a widget to the workspace.
3737 *
3738 * Implementation of the method from LauncherModel.Callbacks.
3739 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003740 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003741 Runnable r = new Runnable() {
3742 public void run() {
3743 bindAppWidget(item);
3744 }
3745 };
3746 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003747 return;
3748 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003749
Daniel Sandler843e8602010-06-07 14:59:01 -04003750 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3751 if (DEBUG_WIDGETS) {
3752 Log.d(TAG, "bindAppWidget: " + item);
3753 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003754 final Workspace workspace = mWorkspace;
3755
3756 final int appWidgetId = item.appWidgetId;
3757 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003758 if (DEBUG_WIDGETS) {
3759 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3760 }
3761
Joe Onorato9c1289c2009-08-17 11:03:03 -04003762 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3763
Joe Onorato9c1289c2009-08-17 11:03:03 -04003764 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003765 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003766
Adam Cohendcd297f2013-06-18 13:13:40 -07003767 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003768 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003769 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3770
Joe Onorato9c1289c2009-08-17 11:03:03 -04003771 workspace.requestLayout();
3772
Daniel Sandler843e8602010-06-07 14:59:01 -04003773 if (DEBUG_WIDGETS) {
3774 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3775 + (SystemClock.uptimeMillis()-start) + "ms");
3776 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777 }
3778
Adam Cohen1462de32012-07-24 22:34:36 -07003779 public void onPageBoundSynchronously(int page) {
3780 mSynchronouslyBoundPages.add(page);
3781 }
3782
Joe Onorato9c1289c2009-08-17 11:03:03 -04003783 /**
3784 * Callback saying that there aren't any more items to bind.
3785 *
3786 * Implementation of the method from LauncherModel.Callbacks.
3787 */
Adam Cohene25af792013-06-06 23:08:25 -07003788 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003789 Runnable r = new Runnable() {
3790 public void run() {
3791 finishBindingItems(upgradePath);
3792 }
3793 };
3794 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003795 return;
3796 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 if (mSavedState != null) {
3798 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003799 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003800 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003801 mSavedState = null;
3802 }
3803
Adam Cohen1462de32012-07-24 22:34:36 -07003804 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003806 // If we received the result of any pending adds while the loader was running (e.g. the
3807 // widget configuration forced an orientation change), process them now.
3808 for (int i = 0; i < sPendingAddList.size(); i++) {
3809 completeAdd(sPendingAddList.get(i));
3810 }
3811 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812
Winson Chungc51db6a2011-10-05 11:44:49 -07003813 // Update the market app icon as necessary (the other icons will be managed in response to
3814 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003815 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003816
Winson Chungf0c6ae02012-03-21 16:10:31 -07003817 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003818 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003819 mWorkspace.getUniqueComponents(true, null);
3820 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003821 }
Adam Cohen99894d92013-06-14 11:22:59 -07003822
Adam Cohen66a01fd2013-06-11 12:48:00 -07003823 mWorkspace.post(new Runnable() {
3824 @Override
3825 public void run() {
3826 onFinishBindingItems();
3827 }
3828 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003829 }
3830
Winson Chunga0b7e862013-09-05 16:03:15 -07003831 public boolean isAllAppsButtonRank(int rank) {
3832 if (mHotseat != null) {
3833 return mHotseat.isAllAppsButtonRank(rank);
3834 }
3835 return false;
3836 }
3837
Winson Chunga2413752012-04-03 14:22:34 -07003838 private boolean canRunNewAppsAnimation() {
3839 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3840 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3841 }
3842
Winson Chungc9168342013-06-26 14:54:55 -07003843 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3844 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3845 PropertyValuesHolder.ofFloat("alpha", 1f),
3846 PropertyValuesHolder.ofFloat("scaleX", 1f),
3847 PropertyValuesHolder.ofFloat("scaleY", 1f));
3848 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3849 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3850 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3851 return bounceAnim;
3852 }
3853
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003854 @Override
3855 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003856 boolean searchVisible = updateGlobalSearchIcon();
3857 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003858 if (mSearchDropTargetBar != null) {
3859 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3860 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003861 }
3862
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003863 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003864 * Add the icons for all apps.
3865 *
3866 * Implementation of the method from LauncherModel.Callbacks.
3867 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003868 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003869 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3870 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3871 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3872 getHotseat().addAllAppsFolder(mIconCache, apps,
3873 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3874 }
3875 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003876 }
Winson Chungc58497e2013-09-03 17:48:37 -07003877 } else {
3878 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3879 mAppsCustomizeContent != null) {
3880 mAppsCustomizeContent.setApps(apps);
3881 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003882 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003883 }
3884
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003885 @Override
3886 public boolean shouldShowApp(ResolveInfo app) {
3887 return true;
3888 }
3889
Joe Onorato9c1289c2009-08-17 11:03:03 -04003890 /**
3891 * A package was updated.
3892 *
3893 * Implementation of the method from LauncherModel.Callbacks.
3894 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003895 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003896 Runnable r = new Runnable() {
3897 public void run() {
3898 bindAppsUpdated(apps);
3899 }
3900 };
3901 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003902 return;
3903 }
3904
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003905 if (mWorkspace != null) {
3906 mWorkspace.updateShortcuts(apps);
3907 }
Winson Chungc58497e2013-09-03 17:48:37 -07003908
3909 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3910 mAppsCustomizeContent != null) {
3911 mAppsCustomizeContent.updateApps(apps);
3912 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003913 }
3914
3915 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003916 * A package was uninstalled. We take both the super set of packageNames
3917 * in addition to specific applications to remove, the reason being that
3918 * this can be called when a package is updated as well. In that scenario,
3919 * we only remove specific components from the workspace, where as
3920 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003921 *
3922 * Implementation of the method from LauncherModel.Callbacks.
3923 */
Winson Chung83892cc2013-05-01 16:53:33 -07003924 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003925 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003926 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003927 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003928 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003929 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003930 }
Winson Chungd64d1762013-08-20 14:37:16 -07003931 };
3932 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003933 return;
3934 }
3935
Winson Chung64359a52013-07-08 17:17:08 -07003936 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003937 mWorkspace.removeItemsByPackageName(packageNames);
3938 } else {
3939 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003940 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003941
Winson Chunga1820962011-10-03 16:31:06 -07003942 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003943 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003944
3945 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3946 mAppsCustomizeContent != null) {
3947 mAppsCustomizeContent.removeApps(appInfos);
3948 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 }
Joe Onoratobe386092009-11-17 17:32:16 -08003950
3951 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003952 * A number of packages were updated.
3953 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003954 private ArrayList<Object> mWidgetsAndShortcuts;
3955 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003956 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003957 bindPackagesUpdated(mWidgetsAndShortcuts);
3958 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003959 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003960 };
3961
3962 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3963 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3964 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003965 return;
3966 }
3967
Winson Chung64359a52013-07-08 17:17:08 -07003968 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003969 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3970 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003971 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003972 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003973 }
3974
Winson Chung400438b2011-01-16 17:53:48 -08003975 private int mapConfigurationOriActivityInfoOri(int configOri) {
3976 final Display d = getWindowManager().getDefaultDisplay();
3977 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3978 switch (d.getRotation()) {
3979 case Surface.ROTATION_0:
3980 case Surface.ROTATION_180:
3981 // We are currently in the same basic orientation as the natural orientation
3982 naturalOri = configOri;
3983 break;
3984 case Surface.ROTATION_90:
3985 case Surface.ROTATION_270:
3986 // We are currently in the other basic orientation to the natural orientation
3987 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3988 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3989 break;
3990 }
3991
3992 int[] oriMap = {
3993 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3994 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3995 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3996 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3997 };
3998 // Since the map starts at portrait, we need to offset if this device's natural orientation
3999 // is landscape.
4000 int indexOffset = 0;
4001 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4002 indexOffset = 1;
4003 }
4004 return oriMap[(d.getRotation() + indexOffset) % 4];
4005 }
Adam Cohen446e9402011-09-15 18:21:21 -07004006
Winson Chung4b919f82012-05-01 10:44:08 -07004007 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004008 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004009 getResources().getBoolean(R.bool.allow_rotation);
4010 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004011 }
Winson Chung4b919f82012-05-01 10:44:08 -07004012 public void lockScreenOrientation() {
4013 if (isRotationEnabled()) {
4014 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4015 .getConfiguration().orientation));
4016 }
4017 }
4018 public void unlockScreenOrientation(boolean immediate) {
4019 if (isRotationEnabled()) {
4020 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004021 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004022 } else {
4023 mHandler.postDelayed(new Runnable() {
4024 public void run() {
4025 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4026 }
4027 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004028 }
Winson Chung4b919f82012-05-01 10:44:08 -07004029 }
Winson Chung400438b2011-01-16 17:53:48 -08004030 }
4031
Winson Chung82f55532011-08-09 14:14:23 -07004032 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004033 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004034 if (DISABLE_CLINGS) {
4035 return false;
4036 }
4037
Brett Chabot2a9e2282011-08-23 15:03:13 -07004038 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004039 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004040
Michael Jurkae233a8b2013-03-19 13:49:20 +01004041 // Restricted secondary users (child mode) will potentially have very few apps
4042 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004043// boolean supportsLimitedUsers =
4044// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4045// Account[] accounts = AccountManager.get(this).getAccounts();
4046// if (supportsLimitedUsers && accounts.length == 0) {
4047// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4048// Bundle restrictions = um.getUserRestrictions();
4049// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4050// return false;
4051// }
4052// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004053 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004054 }
Michael Jurka22143132012-10-04 17:42:38 +02004055
Winson Chungaf40f202013-09-18 18:26:31 -07004056 private Cling initCling(int clingId, int[] positionData, boolean animate,
4057 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004058 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004059 if (cling != null) {
4060 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004061 cling.show(animate, SHOW_CLING_DURATION);
4062
4063 if (dimNavBarVisibilty) {
4064 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4065 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004066 }
4067 }
4068 return cling;
4069 }
Michael Jurka22143132012-10-04 17:42:38 +02004070
Winson Chungaf40f202013-09-18 18:26:31 -07004071 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4072 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004073 // To catch cases where siblings of top-level views are made invisible, just check whether
4074 // the cling is directly set to GONE before dismissing it.
4075 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004076 final Runnable cleanUpClingCb = new Runnable() {
4077 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004078 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004079 /*
Winson Chung46353de2012-02-16 14:05:10 -08004080 // We should update the shared preferences on a background thread
4081 new Thread("dismissClingThread") {
4082 public void run() {
4083 SharedPreferences.Editor editor = mSharedPrefs.edit();
4084 editor.putBoolean(flag, true);
4085 editor.commit();
4086 }
4087 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004088 */
4089 if (postAnimationCb != null) {
4090 postAnimationCb.run();
4091 }
4092 }
4093 };
4094 if (duration <= 0) {
4095 cleanUpClingCb.run();
4096 } else {
4097 cling.hide(duration, cleanUpClingCb);
4098 }
Michael Jurka22143132012-10-04 17:42:38 +02004099 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004100
4101 if (restoreNavBarVisibilty) {
4102 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4103 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4104 }
Winson Chung82f55532011-08-09 14:14:23 -07004105 }
4106 }
Michael Jurka22143132012-10-04 17:42:38 +02004107
Winson Chung9d9d74f2011-09-19 11:49:12 -07004108 private void removeCling(int id) {
4109 final View cling = findViewById(id);
4110 if (cling != null) {
4111 final ViewGroup parent = (ViewGroup) cling.getParent();
4112 parent.post(new Runnable() {
4113 @Override
4114 public void run() {
4115 parent.removeView(cling);
4116 }
4117 });
Michael Jurka22143132012-10-04 17:42:38 +02004118 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004119 }
4120 }
Michael Jurka974c3862012-05-22 22:00:31 -07004121
4122 private boolean skipCustomClingIfNoAccounts() {
4123 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4124 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4125 if (customCling) {
4126 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004127 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004128 Account[] accounts = am.getAccountsByType("com.google");
4129 return accounts.length == 0;
4130 }
4131 return false;
4132 }
4133
Winson Chungaf40f202013-09-18 18:26:31 -07004134 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004135 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004136 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004137 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004138 // If we're not using the default workspace layout, replace workspace cling
4139 // with a custom workspace cling (usually specified in an overlay)
4140 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004141 if (!DISABLE_CUSTOM_CLINGS) {
4142 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4143 getResources().getBoolean(R.bool.config_useCustomClings)) {
4144 // Use a custom cling
4145 View cling = findViewById(R.id.workspace_cling);
4146 ViewGroup clingParent = (ViewGroup) cling.getParent();
4147 int clingIndex = clingParent.indexOfChild(cling);
4148 clingParent.removeViewAt(clingIndex);
4149 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4150 clingParent.addView(customCling, clingIndex);
4151 customCling.setId(R.id.workspace_cling);
4152 }
4153 }
4154 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4155 if (cling != null) {
4156 String sbHintStr = getFirstRunClingSearchBarHint();
4157 String ccHintStr = getFirstRunCustomContentHint();
4158 if (!sbHintStr.isEmpty()) {
4159 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4160 sbHint.setText(sbHintStr);
4161 sbHint.setVisibility(View.VISIBLE);
4162 }
4163 if (!ccHintStr.isEmpty()) {
4164 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4165 ccHint.setText(ccHintStr);
4166 ccHint.setVisibility(View.VISIBLE);
4167 }
Michael Jurka45355c42012-10-08 13:21:35 +02004168 }
Winson Chungaf40f202013-09-18 18:26:31 -07004169 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004170 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004171 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004172 }
4173 }
Winson Chungaf40f202013-09-18 18:26:31 -07004174
Winson Chunge6eabff2013-09-24 11:01:23 -07004175 protected String getFirstRunClingSearchBarHint() {
4176 return "";
4177 }
4178 protected String getFirstRunCustomContentHint() {
4179 return "";
4180 }
4181
Winson Chungaf40f202013-09-18 18:26:31 -07004182 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004183 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004184 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004185 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4186 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004187 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004188 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004189 }
4190 }
4191 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004192 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004193 if (isClingsEnabled() &&
4194 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004195 Cling cling = initCling(R.id.folder_cling, null, true, true);
4196 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004197 } else {
4198 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004199 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004200 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004201 }
Michael Jurka104c4562013-07-08 18:03:46 -07004202 protected SharedPreferences getSharedPrefs() {
4203 return mSharedPrefs;
4204 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004205 public boolean isFolderClingVisible() {
4206 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004207 if (cling != null) {
4208 return cling.getVisibility() == View.VISIBLE;
4209 }
4210 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004211 }
Winson Chungaf40f202013-09-18 18:26:31 -07004212 public void dismissFirstRunCling(View v) {
4213 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4214 Runnable cb = new Runnable() {
4215 public void run() {
4216 // Show the workspace cling next
4217 showFirstRunWorkspaceCling();
4218 }
4219 };
4220 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4221 DISMISS_CLING_DURATION, false);
4222 }
Winson Chung82f55532011-08-09 14:14:23 -07004223 public void dismissWorkspaceCling(View v) {
4224 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004225 Runnable cb = null;
4226 if (v == null) {
4227 cb = new Runnable() {
4228 public void run() {
4229 mWorkspace.enterOverviewMode();
4230 }
4231 };
4232 }
4233 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4234 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004235 }
4236 public void dismissFolderCling(View v) {
4237 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004238 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4239 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004240 }
4241
Winson Chung80baf5a2010-08-09 16:03:15 -07004242 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004243 * Prints out out state for debugging.
4244 */
4245 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004246 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004247 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004248 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4249 Log.d(TAG, "mRestoring=" + mRestoring);
4250 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4251 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004252 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004253 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004254
Winson Chung785d2eb2011-04-14 16:08:02 -07004255 if (mAppsCustomizeContent != null) {
4256 mAppsCustomizeContent.dumpState();
4257 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004258 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004259 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004260
4261 @Override
4262 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4263 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004264 synchronized (sDumpLogs) {
4265 writer.println(" ");
4266 writer.println("Debug logs: ");
4267 for (int i = 0; i < sDumpLogs.size(); i++) {
4268 writer.println(" " + sDumpLogs.get(i));
4269 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004270 }
4271 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004272
4273 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004274 if (DEBUG_DUMP_LOG) {
4275 synchronized (sDumpLogs) {
4276 Log.d(TAG, "");
4277 Log.d(TAG, "*********************");
4278 Log.d(TAG, "Launcher debug logs: ");
4279 for (int i = 0; i < sDumpLogs.size(); i++) {
4280 Log.d(TAG, " " + sDumpLogs.get(i));
4281 }
4282 Log.d(TAG, "*********************");
4283 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004284 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004285 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004286 }
4287
4288 public static void addDumpLog(String tag, String log, boolean debugLog) {
4289 if (debugLog) {
4290 Log.d(tag, log);
4291 }
Winson Chungede41292013-09-19 16:27:36 -07004292 if (DEBUG_DUMP_LOG) {
4293 sDateStamp.setTime(System.currentTimeMillis());
4294 synchronized (sDumpLogs) {
4295 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004296 }
Winson Chungede41292013-09-19 16:27:36 -07004297 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004298 }
4299
Winson Chungede41292013-09-19 16:27:36 -07004300 public void dumpLogsToLocalData() {
4301 if (DEBUG_DUMP_LOG) {
4302 new Thread("DumpLogsToLocalData") {
4303 @Override
4304 public void run() {
4305 boolean success = false;
4306 sDateStamp.setTime(sRunStart);
4307 String FILENAME = sDateStamp.getMonth() + "-"
4308 + sDateStamp.getDay() + "_"
4309 + sDateStamp.getHours() + "-"
4310 + sDateStamp.getMinutes() + "_"
4311 + sDateStamp.getSeconds() + ".txt";
4312
4313 FileOutputStream fos = null;
4314 File outFile = null;
4315 try {
4316 outFile = new File(getFilesDir(), FILENAME);
4317 outFile.createNewFile();
4318 fos = new FileOutputStream(outFile);
4319 } catch (Exception e) {
4320 e.printStackTrace();
4321 }
4322 if (fos != null) {
4323 PrintWriter writer = new PrintWriter(fos);
4324
4325 writer.println(" ");
4326 writer.println("Debug logs: ");
4327 synchronized (sDumpLogs) {
4328 for (int i = 0; i < sDumpLogs.size(); i++) {
4329 writer.println(" " + sDumpLogs.get(i));
4330 }
4331 }
4332 writer.close();
4333 }
4334 try {
4335 if (fos != null) {
4336 fos.close();
4337 success = true;
4338 }
4339 } catch (IOException e) {
4340 e.printStackTrace();
4341 }
4342 }
4343 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004344 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004345 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004346}
Michael Jurka2763be32011-02-24 11:19:57 -08004347
Michael Jurkaabded662011-03-04 12:06:57 -08004348interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004349 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004350 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004351 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004352 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004353 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004354}