blob: 149a5230f04073666d94d7ed3adc7a4764ab64c9 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700212 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
213 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700214 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700215
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800216 private final BroadcastReceiver mCloseSystemDialogsReceiver
217 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800218 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 private LayoutInflater mInflater;
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700223 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800224 private DragLayer mDragLayer;
225 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700226 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700227
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700228 private AppWidgetManager mAppWidgetManager;
229 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700230
Michael Jurkac9d95c52011-08-29 14:03:34 -0700231 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700232 private AppWidgetProviderInfo mPendingAddWidgetInfo;
233
Michael Jurka0280c3b2010-09-17 15:00:07 -0700234 private int[] mTmpAddItemCellCoordinates = new int[2];
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private FolderInfo mFolderInfo;
237
Winson Chung3d503fb2011-07-13 17:25:49 -0700238 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700239 private View mOverviewPanel;
240
Michael Jurka838a4ca2011-02-07 13:33:06 -0800241 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700242
Winson Chungc51db6a2011-10-05 11:44:49 -0700243 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700244 private AppsCustomizeTabHost mAppsCustomizeTabHost;
245 private AppsCustomizePagedView mAppsCustomizeContent;
246 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100247 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700250 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
251 // scroll issues (because the workspace may not have been measured yet) and extra work.
252 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
253 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
255 private SpannableStringBuilder mDefaultKeySsb = null;
256
Joe Onorato9c1289c2009-08-17 11:03:03 -0400257 private boolean mWorkspaceLoading = true;
258
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800259 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 private boolean mRestoring;
261 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700262 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
Michael Jurka1e2f4652013-07-08 18:03:46 -0700264 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700265 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
266
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // Keep track of whether the user has left launcher
268 private static boolean sPausedFromUserAction = false;
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private Bundle mSavedInstanceState;
271
Joe Onorato9c1289c2009-08-17 11:03:03 -0400272 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800273 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800274 private boolean mUserPresent = true;
275 private boolean mVisible = false;
276 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700277 private static final boolean DISABLE_CLINGS = true;
Winson Chunge6eabff2013-09-24 11:01:23 -0700278 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static LocaleConfiguration sLocaleConfiguration = null;
281
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700282 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700284 private Intent mAppMarketIntent = null;
285
Adam Cohended9f8d2010-11-03 13:25:16 -0700286 // Related to the auto-advancing of widgets
287 private final int ADVANCE_MSG = 1;
288 private final int mAdvanceInterval = 20000;
289 private final int mAdvanceStagger = 250;
290 private long mAutoAdvanceSentTime;
291 private long mAutoAdvanceTimeLeft = -1;
292 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
293 new HashMap<View, AppWidgetProviderInfo>();
294
Winson Chung400438b2011-01-16 17:53:48 -0800295 // Determines how long to wait after a rotation before restoring the screen orientation to
296 // match the sensor state.
297 private final int mRestoreScreenOrientationDelay = 500;
298
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700300 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
302 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303
Craig Mautner360310b2012-10-26 15:13:08 -0700304 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700305
Adam Cohen1462de32012-07-24 22:34:36 -0700306 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
307
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700308 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700309 static Date sDateStamp = new Date();
310 static DateFormat sDateFormat =
311 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
312 static long sRunStart = System.currentTimeMillis();
313 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700314
Winson Chung46353de2012-02-16 14:05:10 -0800315 // We only want to get the SharedPreferences once since it does an FS stat each time we get
316 // it from the context.
317 private SharedPreferences mSharedPrefs;
318
Adam Cohene25af792013-06-06 23:08:25 -0700319 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
320
Winson Chungf0c6ae02012-03-21 16:10:31 -0700321 // Holds the page that we need to animate to, and the icon views that we need to animate up
322 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700323 private ImageView mFolderIconImageView;
324 private Bitmap mFolderIconBitmap;
325 private Canvas mFolderIconCanvas;
326 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700327
Michael Jurkaddd62e92011-02-16 17:49:14 -0800328 private BubbleTextView mWaitingForResume;
329
Michael Jurka22143132012-10-04 17:42:38 +0200330 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
331 = new HideFromAccessibilityHelper();
332
Michael Jurkac1f5d262011-09-30 19:32:27 -0700333 private Runnable mBuildLayersRunnable = new Runnable() {
334 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700335 if (mWorkspace != null) {
336 mWorkspace.buildPageHardwareLayers();
337 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700338 }
339 };
340
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800341 private static ArrayList<PendingAddArguments> sPendingAddList
342 = new ArrayList<PendingAddArguments>();
343
Michael Jurka0a457bf2012-11-19 14:05:05 -0800344 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
345
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800346 private static class PendingAddArguments {
347 int requestCode;
348 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700349 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700350 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800351 int cellX;
352 int cellY;
353 }
354
Daniel Sandlerff02d492013-08-05 02:12:05 -0400355 private Stats mStats;
356
Michael Jurka0a457bf2012-11-19 14:05:05 -0800357 private static boolean isPropertyEnabled(String propertyName) {
358 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700359 }
360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 @Override
362 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700363 if (DEBUG_STRICT_MODE) {
364 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
365 .detectDiskReads()
366 .detectDiskWrites()
367 .detectNetwork() // or .detectAll() for all detectable problems
368 .penaltyLog()
369 .build());
370 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
371 .detectLeakedSqlLiteObjects()
372 .detectLeakedClosableObjects()
373 .penaltyLog()
374 .penaltyDeath()
375 .build());
376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400379
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400381 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700382
383 // Determine the dynamic grid properties
384 Point smallestSize = new Point();
385 Point largestSize = new Point();
386 Point realSize = new Point();
387 Display display = getWindowManager().getDefaultDisplay();
388 display.getCurrentSizeRange(smallestSize, largestSize);
389 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700390 DisplayMetrics dm = new DisplayMetrics();
391 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700392 // Lazy-initialize the dynamic grid
393 DeviceProfile grid = app.initDynamicGrid(this,
394 Math.min(smallestSize.x, smallestSize.y),
395 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700396 realSize.x, realSize.y,
397 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700398
399 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400400 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700401 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800402 mModel = app.setLauncher(this);
403 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400404 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700406
Daniel Sandlerff02d492013-08-05 02:12:05 -0400407 mStats = new Stats(this);
408
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700409 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
411 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700412
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700413 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
414 // this also ensures that any synchronous binding below doesn't re-trigger another
415 // LauncherModel load.
416 mPaused = false;
417
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200419 android.os.Debug.startMethodTracing(
420 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 }
422
423 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 setContentView(R.layout.launcher);
425 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100426 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800428 registerContentObservers();
429
Joe Onorato7c312c12009-08-13 21:36:53 -0700430 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700431
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 mSavedState = savedInstanceState;
433 restoreState(mSavedState);
434
Winson Chunga12a2502010-12-20 14:41:35 -0800435 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700436 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200437 mAppsCustomizeContent.onPackagesUpdated(
438 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700439 }
Winson Chunga12a2502010-12-20 14:41:35 -0800440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 if (PROFILE_STARTUP) {
442 android.os.Debug.stopMethodTracing();
443 }
444
445 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700446 if (sPausedFromUserAction) {
447 // If the user leaves launcher, then we should just load items asynchronously when
448 // they return.
449 mModel.startLoader(true, -1);
450 } else {
451 // We only load the page synchronously if the user rotates (or triggers a
452 // configuration change) while launcher is in the foreground
453 mModel.startLoader(true, mWorkspace.getCurrentPage());
454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 // For handling default keys
458 mDefaultKeySsb = new SpannableStringBuilder();
459 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800460
461 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
462 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800463
Adam Cohenf9426d52012-06-04 17:26:21 -0700464 updateGlobalIcons();
465
466 // On large interfaces, we want the screen to auto-rotate based on the current orientation
467 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700468
469 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700470 }
471
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 protected void onUserLeaveHint() {
473 super.onUserLeaveHint();
474 sPausedFromUserAction = true;
475 }
476
Winson Chung98ca0f72013-07-29 12:58:51 -0700477 /** To be overriden by subclasses to hint to Launcher that we have custom content */
478 protected boolean hasCustomContentToLeft() {
479 return false;
480 }
481
Dave Hawkeya8881582013-09-17 15:55:33 -0600482 /**
483 * To be overridden by subclasses to create the custom content and call
484 * {@link #addToCustomContentPage}. This will only be invoked if
485 * {@link #hasCustomContentToLeft()} is {@code true}.
486 */
487 protected void addCustomContentToLeft() {
488 }
489
490 /**
491 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
492 * ensure the custom content page is added or removed if necessary.
493 */
494 protected void invalidateHasCustomContentToLeft() {
495 if (mWorkspace.getScreenOrder().isEmpty()) {
496 // Not bound yet, wait for bindScreens to be called.
497 return;
498 }
499
500 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
501 // Create the custom content page and call the subclass to populate it.
502 mWorkspace.createCustomContentPage();
503 addCustomContentToLeft();
504 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
505 mWorkspace.removeCustomContentPage();
506 }
507 }
508
Adam Cohenf9426d52012-06-04 17:26:21 -0700509 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700510 boolean searchVisible = false;
511 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800512 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700513 int coi = getCurrentOrientationIndexForGlobalIcons();
514 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
515 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700516 updateAppMarketIcon();
517 searchVisible = updateGlobalSearchIcon();
518 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700519 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700520 if (sGlobalSearchIcon[coi] != null) {
521 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700523 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700524 if (sVoiceSearchIcon[coi] != null) {
525 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700526 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700527 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700528 if (sAppMarketIcon[coi] != null) {
529 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800530 }
Winson Chungadf0c182012-08-23 14:59:07 -0700531 if (mSearchDropTargetBar != null) {
532 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
533 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800534 }
Romain Guycbb89e42009-06-08 15:52:54 -0700535
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800536 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700537 if (sLocaleConfiguration == null) {
538 new AsyncTask<Void, Void, LocaleConfiguration>() {
539 @Override
540 protected LocaleConfiguration doInBackground(Void... unused) {
541 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
542 readConfiguration(Launcher.this, localeConfiguration);
543 return localeConfiguration;
544 }
545
546 @Override
547 protected void onPostExecute(LocaleConfiguration result) {
548 sLocaleConfiguration = result;
549 checkForLocaleChange(); // recursive, but now with a locale configuration
550 }
551 }.execute();
552 return;
553 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700554
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 final Configuration configuration = getResources().getConfiguration();
556
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700557 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final String locale = configuration.locale.toString();
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final int mcc = configuration.mcc;
562
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700563 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final int mnc = configuration.mnc;
565
Romain Guy84f296c2009-11-04 15:00:44 -0800566 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567
Romain Guy84f296c2009-11-04 15:00:44 -0800568 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700569 sLocaleConfiguration.locale = locale;
570 sLocaleConfiguration.mcc = mcc;
571 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700572
Joe Onorato0589f0f2010-02-08 13:44:00 -0800573 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574
575 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
576 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700577 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 public void run() {
579 writeConfiguration(Launcher.this, localeConfiguration);
580 }
581 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700582 }
583 }
584
585 private static class LocaleConfiguration {
586 public String locale;
587 public int mcc = -1;
588 public int mnc = -1;
589 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700590
Romain Guy98d01652009-06-30 16:21:04 -0700591 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
592 DataInputStream in = null;
593 try {
594 in = new DataInputStream(context.openFileInput(PREFERENCES));
595 configuration.locale = in.readUTF();
596 configuration.mcc = in.readInt();
597 configuration.mnc = in.readInt();
598 } catch (FileNotFoundException e) {
599 // Ignore
600 } catch (IOException e) {
601 // Ignore
602 } finally {
603 if (in != null) {
604 try {
605 in.close();
606 } catch (IOException e) {
607 // Ignore
608 }
609 }
610 }
611 }
612
613 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
614 DataOutputStream out = null;
615 try {
616 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
617 out.writeUTF(configuration.locale);
618 out.writeInt(configuration.mcc);
619 out.writeInt(configuration.mnc);
620 out.flush();
621 } catch (FileNotFoundException e) {
622 // Ignore
623 } catch (IOException e) {
624 //noinspection ResultOfMethodCallIgnored
625 context.getFileStreamPath(PREFERENCES).delete();
626 } finally {
627 if (out != null) {
628 try {
629 out.close();
630 } catch (IOException e) {
631 // Ignore
632 }
633 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800634 }
635 }
636
Anton Hanssona2f665f2013-09-26 12:18:32 +0100637 public Stats getStats() {
638 return mStats;
639 }
640
Bjorn Bringertc459e522013-06-07 19:36:01 +0100641 public LayoutInflater getInflater() {
642 return mInflater;
643 }
644
Adam Cohen716b51e2011-06-30 12:09:54 -0700645 public DragLayer getDragLayer() {
646 return mDragLayer;
647 }
648
Winson Chung36a62fe2012-05-06 18:04:42 -0700649 boolean isDraggingEnabled() {
650 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
651 // that is subsequently removed from the workspace in startBinding().
652 return !mModel.isLoadingWorkspace();
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 static int getScreen() {
656 synchronized (sLock) {
657 return sScreen;
658 }
659 }
660
661 static void setScreen(int screen) {
662 synchronized (sLock) {
663 sScreen = screen;
664 }
665 }
666
Winson Chung557d6ed2011-07-08 15:34:52 -0700667 /**
668 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
669 * a configuration step, this allows the proper animations to run after other transitions.
670 */
671 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700672 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800673 switch (args.requestCode) {
674 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700675 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700676 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800677 break;
678 case REQUEST_PICK_SHORTCUT:
679 processShortcut(args.intent);
680 break;
681 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700682 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700683 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700684 result = true;
685 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 case REQUEST_CREATE_APPWIDGET:
687 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700688 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 result = true;
690 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 }
Michael Jurka27614d22012-04-02 06:40:22 -0700692 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
693 // if you turned the screen off and then back while in All Apps, Launcher would not
694 // return to the workspace. Clearing mAddInfo.container here fixes this issue
695 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700696 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800697 }
698
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 protected void onActivityResult(
701 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700702 // Reset the startActivity waiting flag
703 mWaitingForResult = false;
704
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 if (requestCode == REQUEST_BIND_APPWIDGET) {
706 int appWidgetId = data != null ?
707 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
708 if (resultCode == RESULT_CANCELED) {
709 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
710 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700711 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 }
713 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200714 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
715 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
716 mWorkspace.exitOverviewMode(false);
717 }
718 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700719 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200720
Winson Chung557d6ed2011-07-08 15:34:52 -0700721 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800722 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
723 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700724
Adam Cohened66b2b2012-01-23 17:28:51 -0800725 // We have special handling for widgets
726 if (isWidgetDrop) {
727 int appWidgetId = data != null ?
728 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700729 if (appWidgetId < 0) {
730 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
731 "widget configuration activity.");
732 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
733 } else {
734 completeTwoStageWidgetDrop(resultCode, appWidgetId);
735 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800736 return;
737 }
738
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 // The pattern used here is that a user PICKs a specific application,
740 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700741
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800742 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
743 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700744 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 final PendingAddArguments args = new PendingAddArguments();
746 args.requestCode = requestCode;
747 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700748 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700749 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700750 args.cellX = mPendingAddInfo.cellX;
751 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 if (isWorkspaceLocked()) {
753 sPendingAddList.add(args);
754 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700755 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800758 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700759 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800760 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
761 null);
762 }
763
764 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700765 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700766 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 Runnable onCompleteRunnable = null;
768 int animationType = 0;
769
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700770 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 if (resultCode == RESULT_OK) {
772 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
773 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700774 mPendingAddWidgetInfo);
775 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 onCompleteRunnable = new Runnable() {
777 @Override
778 public void run() {
779 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700780 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800781 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
782 null);
783 }
784 };
785 } else if (resultCode == RESULT_CANCELED) {
786 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
787 onCompleteRunnable = new Runnable() {
788 @Override
789 public void run() {
790 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
791 null);
792 }
793 };
794 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700795 if (mDragLayer.getAnimatedView() != null) {
796 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
797 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
798 animationType, boundWidget, true);
799 } else {
800 // The animated view may be null in the case of a rotation during widget configuration
801 onCompleteRunnable.run();
802 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800803 }
804
805 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700806 protected void onStop() {
807 super.onStop();
808 FirstFrameAnimatorHelper.setIsVisible(false);
809 }
810
811 @Override
812 protected void onStart() {
813 super.onStart();
814 FirstFrameAnimatorHelper.setIsVisible(true);
815 }
816
817 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200819 long startTime = 0;
820 if (DEBUG_RESUME_TIME) {
821 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400822 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200823 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700825
Winson Chung4a2afa32012-07-19 14:53:05 -0700826 // Restore the previous launcher state
827 if (mOnResumeState == State.WORKSPACE) {
828 showWorkspace(false);
829 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700830 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700831 }
832 mOnResumeState = State.NONE;
833
Craig Mautner360310b2012-10-26 15:13:08 -0700834 // Background was set to gradient in onPause(), restore to black if in all apps.
835 setWorkspaceBackground(mState == State.WORKSPACE);
836
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800837 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700838 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700839 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400840 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700841 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400842 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700843 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700845 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200846 // We might have postponed some bind calls until onResume (see waitUntilResume) --
847 // execute them here
848 long startTimeCallbacks = 0;
849 if (DEBUG_RESUME_TIME) {
850 startTimeCallbacks = System.currentTimeMillis();
851 }
852
853 if (mAppsCustomizeContent != null) {
854 mAppsCustomizeContent.setBulkBind(true);
855 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700856 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
857 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200858 }
859 if (mAppsCustomizeContent != null) {
860 mAppsCustomizeContent.setBulkBind(false);
861 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700862 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200863 if (DEBUG_RESUME_TIME) {
864 Log.d(TAG, "Time spent processing callbacks in onResume: " +
865 (System.currentTimeMillis() - startTimeCallbacks));
866 }
Michael Jurka447bf842013-05-15 14:52:15 +0200867 }
Michael Jurka54554252013-08-01 12:52:23 +0200868 if (mOnResumeCallbacks.size() > 0) {
869 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
870 mOnResumeCallbacks.get(i).run();
871 }
872 mOnResumeCallbacks.clear();
873 }
Winson Chunge4e50662012-01-23 14:45:13 -0800874
875 // Reset the pressed state of icons that were locked in the press state while activities
876 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800877 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800878 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800879 mWaitingForResume.setStayPressed(false);
880 }
Winson Chunge4e50662012-01-23 14:45:13 -0800881 if (mAppsCustomizeContent != null) {
882 // Resets the previous all apps icon press state
883 mAppsCustomizeContent.resetDrawableState();
884 }
Winson Chung780fe592013-09-26 14:48:44 -0700885 // Reset AllApps to its initial state
886 if (mAppsCustomizeTabHost != null) {
887 mAppsCustomizeTabHost.reset();
888 }
Adam Cohen06dff352012-06-01 17:17:08 -0700889 // It is possible that widgets can receive updates while launcher is not in the foreground.
890 // Consequently, the widgets will be inflated in the orientation of the foreground activity
891 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
892 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700893 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700894
Winson Chung780fe592013-09-26 14:48:44 -0700895 // Process any items that were added while Launcher was away.
896 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
897
Adam Cohenf9426d52012-06-04 17:26:21 -0700898 // Again, as with the above scenario, it's possible that one or more of the global icons
899 // were updated in the wrong orientation.
900 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200901 if (DEBUG_RESUME_TIME) {
902 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
903 }
Adam Cohen06dff352012-06-01 17:17:08 -0700904 }
905
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700907 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700908 // Ensure that items added to Launcher are queued until Launcher returns
909 InstallShortcutReceiver.enableInstallQueue();
910
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700911 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700912 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800913 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700914 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700915 }
Romain Guycbb89e42009-06-08 15:52:54 -0700916
Adam Cohen66a01fd2013-06-11 12:48:00 -0700917 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600918 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
919 addCustomContentToLeft();
920 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700921 }
922
Adam Cohenbffe7452013-07-22 18:21:45 -0700923 QSBScroller mQsbScroller = new QSBScroller() {
924 int scrollY = 0;
925
926 @Override
927 public void setScrollY(int scroll) {
928 scrollY = scroll;
929
930 if (mWorkspace.isOnOrMovingToCustomContent()) {
931 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100932 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700933 }
934 }
935 };
936
937 public void resetQSBScroll() {
938 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100939 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700940 }
941
942 public interface CustomContentCallbacks {
943 // Custom content is completely shown
944 public void onShow();
945
946 // Custom content is completely hidden
947 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700948
949 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
950 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700951 }
952
Adam Cohen30bacb22013-08-29 14:25:25 -0700953 protected void startSettings() {
954 }
955
Adam Cohenbffe7452013-07-22 18:21:45 -0700956 public interface QSBScroller {
957 public void setScrollY(int scrollY);
958 }
959
Adam Cohen66a01fd2013-06-11 12:48:00 -0700960 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700961 public QSBScroller addToCustomContentPage(View customContent) {
962 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700963 }
964
Winson Chung98ca0f72013-07-29 12:58:51 -0700965 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700966 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700967 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700968 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700969 }
970
Adam Cohenedb40762013-07-18 16:45:45 -0700971 // The custom content needs to offset its content to account for the QSB
972 public int getTopOffsetForCustomContent() {
973 return mWorkspace.getPaddingTop();
974 }
975
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700976 @Override
977 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 // Flag the loader to stop early before switching
979 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700980 if (mAppsCustomizeContent != null) {
981 mAppsCustomizeContent.surrender();
982 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800983 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700984 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700985
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800986 // We can't hide the IME if it was forced open. So don't bother
987 /*
988 @Override
989 public void onWindowFocusChanged(boolean hasFocus) {
990 super.onWindowFocusChanged(hasFocus);
991
992 if (hasFocus) {
993 final InputMethodManager inputManager = (InputMethodManager)
994 getSystemService(Context.INPUT_METHOD_SERVICE);
995 WindowManager.LayoutParams lp = getWindow().getAttributes();
996 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
997 android.os.Handler()) {
998 protected void onReceiveResult(int resultCode, Bundle resultData) {
999 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1000 }
1001 });
1002 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1003 }
1004 }
1005 */
1006
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001007 private boolean acceptFilter() {
1008 final InputMethodManager inputManager = (InputMethodManager)
1009 getSystemService(Context.INPUT_METHOD_SERVICE);
1010 return !inputManager.isFullscreenMode();
1011 }
1012
1013 @Override
1014 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001015 final int uniChar = event.getUnicodeChar();
1016 final boolean handled = super.onKeyDown(keyCode, event);
1017 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1018 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1020 keyCode, event);
1021 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001022 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001023 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001024 // showSearchDialog()
1025 // If there are multiple keystrokes before the search dialog takes focus,
1026 // onSearchRequested() will be called for every keystroke,
1027 // but it is idempotent, so it's fine.
1028 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 }
1030 }
1031
Joe Onorato8a9625e2010-01-28 15:55:35 -08001032 // Eat the long press event so the keyboard doesn't come up.
1033 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1034 return true;
1035 }
1036
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 return handled;
1038 }
1039
Karl Rosaen138a0412009-04-23 19:00:21 -07001040 private String getTypedText() {
1041 return mDefaultKeySsb.toString();
1042 }
1043
1044 private void clearTypedText() {
1045 mDefaultKeySsb.clear();
1046 mDefaultKeySsb.clearSpans();
1047 Selection.setSelection(mDefaultKeySsb, 0);
1048 }
1049
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001051 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1052 * State
1053 */
1054 private static State intToState(int stateOrdinal) {
1055 State state = State.WORKSPACE;
1056 final State[] stateValues = State.values();
1057 for (int i = 0; i < stateValues.length; i++) {
1058 if (stateValues[i].ordinal() == stateOrdinal) {
1059 state = stateValues[i];
1060 break;
1061 }
1062 }
1063 return state;
1064 }
1065
1066 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001067 * Restores the previous state, if it exists.
1068 *
1069 * @param savedState The previous state.
1070 */
1071 private void restoreState(Bundle savedState) {
1072 if (savedState == null) {
1073 return;
1074 }
1075
Michael Jurka883f55b2010-10-21 15:47:14 -07001076 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001077 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001078 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001079 }
1080
Winson Chungf0c6ae02012-03-21 16:10:31 -07001081 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001083 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001084 }
1085
Winson Chung3d503fb2011-07-13 17:25:49 -07001086 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001087 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001088
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1090 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001091 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001092 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1093 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001094 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1095 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1096 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001097 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 mRestoring = true;
1099 }
1100
1101 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1102 if (renameFolder) {
1103 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001104 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 mRestoring = true;
1106 }
Winson Chunga12a2502010-12-20 14:41:35 -08001107
Winson Chung785d2eb2011-04-14 16:08:02 -07001108 // Restore the AppsCustomize tab
1109 if (mAppsCustomizeTabHost != null) {
1110 String curTab = savedState.getString("apps_customize_currentTab");
1111 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001112 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001113 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001114 mAppsCustomizeContent.loadAssociatedPages(
1115 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 }
1117
Winson Chung5afbf7b2011-07-25 11:53:08 -07001118 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1119 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001120 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 }
1122
1123 /**
1124 * Finds all the views we need and configure them properly.
1125 */
1126 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001127 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001128
Craig Mautner360310b2012-10-26 15:13:08 -07001129 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001130 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1131 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001132
John Spurlock77e1f472013-09-11 10:09:51 -04001133 mLauncherView.setSystemUiVisibility(
1134 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001135 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001136
Winson Chung4c98d922011-05-31 16:50:48 -07001137 // Setup the drag layer
1138 mDragLayer.setup(this, dragController);
1139
Winson Chung3d503fb2011-07-13 17:25:49 -07001140 // Setup the hotseat
1141 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1142 if (mHotseat != null) {
1143 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001144 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001145 }
1146
Adam Cohenf358a4b2013-07-23 16:47:31 -07001147 mOverviewPanel = findViewById(R.id.overview_panel);
1148 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1149 @Override
1150 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001151 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001152 }
1153 });
1154 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1155 @Override
1156 public void onClick(View arg0) {
1157 startWallpaper();
1158 }
1159 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001160 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1161 @Override
1162 public void onClick(View arg0) {
1163 startSettings();
1164 }
1165 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001166 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001167
Winson Chung4c98d922011-05-31 16:50:48 -07001168 // Setup the workspace
1169 mWorkspace.setHapticFeedbackEnabled(false);
1170 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001171 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001172 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001173
Winson Chungf0ea4d32011-06-06 14:27:16 -07001174 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001175 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001176
Winson Chungf0ea4d32011-06-06 14:27:16 -07001177 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001178 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001179 mAppsCustomizeContent = (AppsCustomizePagedView)
1180 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1181 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001182
Winson Chung3d503fb2011-07-13 17:25:49 -07001183 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001184 dragController.setDragScoller(mWorkspace);
1185 dragController.setScrollView(mDragLayer);
1186 dragController.setMoveTarget(mWorkspace);
1187 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001188 if (mSearchDropTargetBar != null) {
1189 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001190 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001191
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001192 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001193 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001194 mWeightWatcher = new WeightWatcher(this);
1195 mWeightWatcher.setAlpha(0.5f);
1196 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001197 new FrameLayout.LayoutParams(
1198 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001199 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001200 Gravity.BOTTOM)
1201 );
Adam Cohen39a06042013-07-19 14:30:12 -07001202
1203 boolean show = shouldShowWeightWatcher();
1204 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001205 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001206 }
1207
1208 /**
1209 * Creates a view representing a shortcut.
1210 *
1211 * @param info The data structure describing the shortcut.
1212 *
1213 * @return A View inflated from R.layout.application.
1214 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001215 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001217 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 }
1219
1220 /**
1221 * Creates a view representing a shortcut inflated from the specified resource.
1222 *
1223 * @param layoutResId The id of the XML layout used to create the shortcut.
1224 * @param parent The group the shortcut belongs to.
1225 * @param info The data structure describing the shortcut.
1226 *
1227 * @return A View inflated from layoutResId.
1228 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001229 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001230 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1231 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 return favorite;
1234 }
1235
1236 /**
1237 * Add an application shortcut to the workspace.
1238 *
1239 * @param data The intent describing the application.
1240 * @param cellInfo The position on screen where to create the shortcut.
1241 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001242 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001243 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001244 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001245
Adam Cohenfbba09b2011-07-18 21:43:05 -07001246 // First we check if we already know the exact location where we want to add this item.
1247 if (cellX >= 0 && cellY >= 0) {
1248 cellXY[0] = cellX;
1249 cellXY[1] = cellY;
1250 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001251 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001252 return;
1253 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001255 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001256
Romain Guy73b979d2009-06-09 12:57:21 -07001257 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001258 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001260 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001261 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001262 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001263 } else {
1264 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 }
1266 }
Romain Guycbb89e42009-06-08 15:52:54 -07001267
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 /**
1269 * Add a shortcut to the workspace.
1270 *
1271 * @param data The intent describing the shortcut.
1272 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001275 int cellY) {
1276 int[] cellXY = mTmpAddItemCellCoordinates;
1277 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001278 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001279
Michael Jurkad3ef3062010-11-23 16:23:58 -08001280 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001281
Adam Cohen558baaf2011-08-15 15:22:57 -07001282 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001283 if (info == null) {
1284 return;
1285 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001286 final View view = createShortcut(info);
1287
Adam Cohenfbba09b2011-07-18 21:43:05 -07001288 // First we check if we already know the exact location where we want to add this item.
1289 if (cellX >= 0 && cellY >= 0) {
1290 cellXY[0] = cellX;
1291 cellXY[1] = cellY;
1292 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001293
1294 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001295 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001296 true, null,null)) {
1297 return;
1298 }
1299 DragObject dragObject = new DragObject();
1300 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001301 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1302 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001303 return;
1304 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001305 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001306 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001307 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001308 foundCellSpan = (result != null);
1309 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001310 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001311 }
1312
1313 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001314 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001315 return;
1316 }
1317
Adam Cohendcd297f2013-06-18 13:13:40 -07001318 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319
1320 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001321 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001322 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 }
1324 }
1325
Adam Cohen2f093b62012-04-30 18:59:53 -07001326 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1327 int minHeight) {
1328 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001329 // We want to account for the extra amount of padding that we are adding to the widget
1330 // to ensure that it gets the full amount of space that it has requested
1331 int requiredWidth = minWidth + padding.left + padding.right;
1332 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001333 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1337 return getSpanForWidget(context, info.provider, 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, AppWidgetProviderInfo info) {
1341 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001342 }
1343
Adam Cohen2f093b62012-04-30 18:59:53 -07001344 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1345 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001346 }
1347
Adam Cohen2f093b62012-04-30 18:59:53 -07001348 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1349 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001350 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001351 }
1352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001354 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001356 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001359 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001360 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1361 if (appWidgetInfo == null) {
1362 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1363 }
Romain Guycbb89e42009-06-08 15:52:54 -07001364
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001365 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001366 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001367
Adam Cohen2f093b62012-04-30 18:59:53 -07001368 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1369 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001370
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001372 // We have saved the position to which the widget was dragged-- this really only matters
1373 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 int[] cellXY = mTmpAddItemCellCoordinates;
1375 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001376 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001377 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1379 cellXY[0] = mPendingAddInfo.cellX;
1380 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001381 spanXY[0] = mPendingAddInfo.spanX;
1382 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001383 foundCellSpan = true;
1384 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001385 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001386 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001387 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1388 spanXY[1], cellXY, finalSpan);
1389 spanXY[0] = finalSpan[0];
1390 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001391 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001392 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001393 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001394 }
1395
Michael Jurka0280c3b2010-09-17 15:00:07 -07001396 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001397 if (appWidgetId != -1) {
1398 // Deleting an app widget ID is a void call but writes to disk before returning
1399 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001400 new Thread("deleteAppWidgetId") {
1401 public void run() {
1402 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1403 }
1404 }.start();
1405 }
Winson Chung93eef082012-03-23 15:59:27 -07001406 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001407 return;
1408 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001410 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001411 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1412 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001413 launcherInfo.spanX = spanXY[0];
1414 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001415 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1416 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001417
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001419 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420
1421 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001422 if (hostView == null) {
1423 // Perform actual inflation because we're live
1424 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1425 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1426 } else {
1427 // The AppWidgetHostView has already been inflated and instantiated
1428 launcherInfo.hostView = hostView;
1429 }
Romain Guycbb89e42009-06-08 15:52:54 -07001430
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001432 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001433 launcherInfo.notifyWidgetSizeChanged(this);
1434
Adam Cohendcd297f2013-06-18 13:13:40 -07001435 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001436 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001437
1438 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001440 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441 }
Romain Guycbb89e42009-06-08 15:52:54 -07001442
Adam Cohended9f8d2010-11-03 13:25:16 -07001443 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1444 @Override
1445 public void onReceive(Context context, Intent intent) {
1446 final String action = intent.getAction();
1447 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1448 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001449 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001450 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001451
Winson Chungc100e8e2011-08-09 16:02:43 -07001452 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001453 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001454 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001455 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001456 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001457 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1458 mUserPresent = true;
1459 updateRunning();
1460 }
1461 }
1462 };
1463
1464 @Override
1465 public void onAttachedToWindow() {
1466 super.onAttachedToWindow();
1467
1468 // Listen for broadcasts related to user-presence
1469 final IntentFilter filter = new IntentFilter();
1470 filter.addAction(Intent.ACTION_SCREEN_OFF);
1471 filter.addAction(Intent.ACTION_USER_PRESENT);
1472 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001473 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001474 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001475 mVisible = true;
1476 }
1477
1478 @Override
1479 public void onDetachedFromWindow() {
1480 super.onDetachedFromWindow();
1481 mVisible = false;
1482
Adam Cohend113e0c2010-11-11 10:48:05 -08001483 if (mAttached) {
1484 unregisterReceiver(mReceiver);
1485 mAttached = false;
1486 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001487 updateRunning();
1488 }
1489
1490 public void onWindowVisibilityChanged(int visibility) {
1491 mVisible = visibility == View.VISIBLE;
1492 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001493 // The following code used to be in onResume, but it turns out onResume is called when
1494 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1495 // is a more appropriate event to handle
1496 if (mVisible) {
1497 mAppsCustomizeTabHost.onWindowVisible();
1498 if (!mWorkspaceLoading) {
1499 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001500 // We want to let Launcher draw itself at least once before we force it to build
1501 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001502 // apps is nice and speedy.
1503 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001504 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001506 if (mStarted) return;
1507 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001508 // We delay the layer building a bit in order to give
1509 // other message processing a time to run. In particular
1510 // this avoids a delay in hiding the IME if it was
1511 // currently shown, because doing that may involve
1512 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001513 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001514 final ViewTreeObserver.OnDrawListener listener = this;
1515 mWorkspace.post(new Runnable() {
1516 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001517 if (mWorkspace != null &&
1518 mWorkspace.getViewTreeObserver() != null) {
1519 mWorkspace.getViewTreeObserver().
1520 removeOnDrawListener(listener);
1521 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001522 }
1523 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001524 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001525 }
1526 });
1527 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001528 // When Launcher comes back to foreground, a different Activity might be responsible for
1529 // the app market intent, so refresh the icon
1530 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001531 clearTypedText();
1532 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001533 }
1534
1535 private void sendAdvanceMessage(long delay) {
1536 mHandler.removeMessages(ADVANCE_MSG);
1537 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1538 mHandler.sendMessageDelayed(msg, delay);
1539 mAutoAdvanceSentTime = System.currentTimeMillis();
1540 }
1541
1542 private void updateRunning() {
1543 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1544 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1545 mAutoAdvanceRunning = autoAdvanceRunning;
1546 if (autoAdvanceRunning) {
1547 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1548 sendAdvanceMessage(delay);
1549 } else {
1550 if (!mWidgetsToAdvance.isEmpty()) {
1551 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1552 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1553 }
1554 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001555 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 }
1557 }
1558 }
1559
1560 private final Handler mHandler = new Handler() {
1561 @Override
1562 public void handleMessage(Message msg) {
1563 if (msg.what == ADVANCE_MSG) {
1564 int i = 0;
1565 for (View key: mWidgetsToAdvance.keySet()) {
1566 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1567 final int delay = mAdvanceStagger * i;
1568 if (v instanceof Advanceable) {
1569 postDelayed(new Runnable() {
1570 public void run() {
1571 ((Advanceable) v).advance();
1572 }
1573 }, delay);
1574 }
1575 i++;
1576 }
1577 sendAdvanceMessage(mAdvanceInterval);
1578 }
1579 }
1580 };
1581
1582 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001583 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1585 if (v instanceof Advanceable) {
1586 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001587 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001588 updateRunning();
1589 }
1590 }
1591
1592 void removeWidgetToAutoAdvance(View hostView) {
1593 if (mWidgetsToAdvance.containsKey(hostView)) {
1594 mWidgetsToAdvance.remove(hostView);
1595 updateRunning();
1596 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001597 }
1598
Joe Onorato9c1289c2009-08-17 11:03:03 -04001599 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001601 launcherInfo.hostView = null;
1602 }
1603
Winson Chung93eef082012-03-23 15:59:27 -07001604 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1605 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1606 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 }
1608
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001609 public LauncherAppWidgetHost getAppWidgetHost() {
1610 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 }
Romain Guycbb89e42009-06-08 15:52:54 -07001612
Winson Chunga9abd0e2010-10-27 17:18:37 -07001613 public LauncherModel getModel() {
1614 return mModel;
1615 }
1616
Bjorn Bringertc459e522013-06-07 19:36:01 +01001617 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001618 getWindow().closeAllPanels();
1619
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001620 // Whatever we were doing is hereby canceled.
1621 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001622 }
1623
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 @Override
1625 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001626 long startTime = 0;
1627 if (DEBUG_RESUME_TIME) {
1628 startTime = System.currentTimeMillis();
1629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001630 super.onNewIntent(intent);
1631
1632 // Close the menu
1633 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001634 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001635 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001636
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 final boolean alreadyOnHome =
1638 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001639 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001640
Jamie Genniscb222e82012-10-23 15:44:26 -07001641 Runnable processIntent = new Runnable() {
1642 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001643 if (mWorkspace == null) {
1644 // Can be cases where mWorkspace is null, this prevents a NPE
1645 return;
1646 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001647 Folder openFolder = mWorkspace.getOpenFolder();
1648 // In all these cases, only animate if we're already on home
1649 mWorkspace.exitWidgetResizeMode();
1650 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1651 openFolder == null) {
1652 mWorkspace.moveToDefaultScreen(true);
1653 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001654
Jamie Genniscb222e82012-10-23 15:44:26 -07001655 closeFolder();
1656 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001657
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 // If we are already on home, then just animate back to the workspace,
1659 // otherwise, just wait until onResume to set the state back to Workspace
1660 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001661 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001662 } else {
1663 mOnResumeState = State.WORKSPACE;
1664 }
1665
1666 final View v = getWindow().peekDecorView();
1667 if (v != null && v.getWindowToken() != null) {
1668 InputMethodManager imm = (InputMethodManager)getSystemService(
1669 INPUT_METHOD_SERVICE);
1670 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1671 }
1672
Winson Chung7819a562013-09-19 15:55:45 -07001673 // Reset the apps customize page
1674 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001675 mAppsCustomizeTabHost.reset();
1676 }
1677 }
1678 };
1679
1680 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1681 // Delay processing of the intent to allow the status bar animation to finish
1682 // first in order to avoid janky animations.
1683 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001684 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001685 // Process the intent immediately.
1686 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001687 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001688
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
Michael Jurka447bf842013-05-15 14:52:15 +02001690 if (DEBUG_RESUME_TIME) {
1691 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 }
1694
Adam Cohen040a5d22013-09-16 17:09:33 -07001695 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1696 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001697 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001698 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001699 }
1700 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001701 protected void showWorkspaceAndExitOverviewMode() {
1702 showWorkspaceAndExitOverviewMode(true);
1703 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001704
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001706 public void onRestoreInstanceState(Bundle state) {
1707 super.onRestoreInstanceState(state);
1708 for (int page: mSynchronouslyBoundPages) {
1709 mWorkspace.restoreInstanceStateForChild(page);
1710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
1712
1713 @Override
1714 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001715 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001716 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717
Michael Jurka883f55b2010-10-21 15:47:14 -07001718 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001719 // We close any open folder since it will not be re-opened, and we need to make sure
1720 // this state is reflected.
1721 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722
Adam Cohendcd297f2013-06-18 13:13:40 -07001723 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001724 mWaitingForResult) {
1725 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001726 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001727 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1728 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001729 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1730 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1731 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 }
1733
1734 if (mFolderInfo != null && mWaitingForResult) {
1735 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1736 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1737 }
Michael Jurka946ad472010-07-09 18:05:18 -07001738
Winson Chung785d2eb2011-04-14 16:08:02 -07001739 // Save the current AppsCustomize tab
1740 if (mAppsCustomizeTabHost != null) {
1741 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1742 if (currentTabTag != null) {
1743 outState.putString("apps_customize_currentTab", currentTabTag);
1744 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001745 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1746 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 }
1749
1750 @Override
1751 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001753
Winson Chunge7a03942011-08-05 15:05:12 -07001754 // Remove all pending runnables
1755 mHandler.removeMessages(ADVANCE_MSG);
1756 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001757 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001758
Winson Chungcd2b0142011-06-08 16:02:26 -07001759 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001760 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001761 mModel.stopLoader();
1762 app.setLauncher(null);
1763
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001765 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001767 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001769 mAppWidgetHost = null;
1770
1771 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772
1773 TextKeyListener.getInstance().release();
1774
Winson Chung81b52252012-08-27 15:34:29 -07001775 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1776 // to prevent leaking Launcher activities on orientation change.
1777 if (mModel != null) {
1778 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1779 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001780
1781 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001782 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001783
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001784 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001785 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1786 mWorkspace.removeAllViews();
1787 mWorkspace = null;
1788 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001789
Michael Jurka2ecf9952012-06-18 12:52:28 -07001790 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
1792
Adam Cohena9cf38f2011-05-02 15:36:58 -07001793 public DragController getDragController() {
1794 return mDragController;
1795 }
1796
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 @Override
1798 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001799 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 super.startActivityForResult(intent, requestCode);
1801 }
1802
Winson Chung70d72102011-08-12 11:24:35 -07001803 /**
1804 * Indicates that we want global search for this activity by setting the globalSearch
1805 * argument for {@link #startSearch} to true.
1806 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001808 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001810
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001811 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001812
Karl Rosaen138a0412009-04-23 19:00:21 -07001813 if (initialQuery == null) {
1814 // Use any text typed in the launcher as the initial query
1815 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 if (appSearchData == null) {
1818 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001819 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
Winson Chungadf0c182012-08-23 14:59:07 -07001821 Rect sourceBounds = new Rect();
1822 if (mSearchDropTargetBar != null) {
1823 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1824 }
Romain Guycbb89e42009-06-08 15:52:54 -07001825
Bjorn Bringertc459e522013-06-07 19:36:01 +01001826 startSearch(initialQuery, selectInitialQuery,
1827 appSearchData, sourceBounds);
1828 }
1829
1830 public void startSearch(String initialQuery,
1831 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001832 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001833 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001834 }
1835
1836 /**
1837 * Starts the global search activity. This code is a copied from SearchManager
1838 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001839 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001840 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001841 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001842 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1843 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1844 if (globalSearchActivity == null) {
1845 Log.w(TAG, "No global search activity found.");
1846 return;
1847 }
1848 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1849 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1850 intent.setComponent(globalSearchActivity);
1851 // Make sure that we have a Bundle to put source in
1852 if (appSearchData == null) {
1853 appSearchData = new Bundle();
1854 } else {
1855 appSearchData = new Bundle(appSearchData);
1856 }
1857 // Set source to package name of app that starts global search, if not set already.
1858 if (!appSearchData.containsKey("source")) {
1859 appSearchData.putString("source", getPackageName());
1860 }
1861 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1862 if (!TextUtils.isEmpty(initialQuery)) {
1863 intent.putExtra(SearchManager.QUERY, initialQuery);
1864 }
1865 if (selectInitialQuery) {
1866 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1867 }
1868 intent.setSourceBounds(sourceBounds);
1869 try {
1870 startActivity(intent);
1871 } catch (ActivityNotFoundException ex) {
1872 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1873 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 }
1875
Winson Chung70d72102011-08-12 11:24:35 -07001876 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001877 public boolean onPrepareOptionsMenu(Menu menu) {
1878 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001879 if (!mWorkspace.isInOverviewMode()) {
1880 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001881 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001882 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001883 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001885 @Override
1886 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001887 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001888 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001889 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001890 }
1891
Joe Onorato9c1289c2009-08-17 11:03:03 -04001892 public boolean isWorkspaceLocked() {
1893 return mWorkspaceLoading || mWaitingForResult;
1894 }
1895
Michael Jurka0280c3b2010-09-17 15:00:07 -07001896 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001897 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001898 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001899 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1900 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001901 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001903 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001904
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001905 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1906 AppWidgetProviderInfo appWidgetInfo) {
1907 if (appWidgetInfo.configure != null) {
1908 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001909
Bjorn Bringert7984c942009-12-09 15:38:25 +00001910 // Launch over to configure widget, if needed
1911 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001912 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001913 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001914 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001916 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001917 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001918 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001919 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001920 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 }
1922 }
Romain Guycbb89e42009-06-08 15:52:54 -07001923
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001924 protected void moveToCustomContentScreen(boolean animate) {
1925 mWorkspace.moveToCustomContentScreen(animate);
1926 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001927 /**
1928 * Process a shortcut drop.
1929 *
1930 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001931 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001932 * @param cell The cell it should be added to, optional
1933 * @param position The location on the screen where it was dropped, optional
1934 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001935 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001936 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001937 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001938 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001939 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001940 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001941
1942 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001943 mPendingAddInfo.cellX = cell[0];
1944 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001945 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001946
1947 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1948 createShortcutIntent.setComponent(componentName);
1949 processShortcut(createShortcutIntent);
1950 }
1951
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 /**
1953 * Process a widget drop.
1954 *
1955 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957 * @param cell The cell it should be added to, optional
1958 * @param position The location on the screen where it was dropped, optional
1959 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001960 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001961 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001962 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001964 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001966 mPendingAddInfo.minSpanX = info.minSpanX;
1967 mPendingAddInfo.minSpanY = info.minSpanY;
1968
Adam Cohenfbba09b2011-07-18 21:43:05 -07001969 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001970 mPendingAddInfo.cellX = cell[0];
1971 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001972 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001973 if (span != null) {
1974 mPendingAddInfo.spanX = span[0];
1975 mPendingAddInfo.spanY = span[1];
1976 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001977
Adam Cohened66b2b2012-01-23 17:28:51 -08001978 AppWidgetHostView hostView = info.boundWidget;
1979 int appWidgetId;
1980 if (hostView != null) {
1981 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001982 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001983 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001984 // In this case, we either need to start an activity to get permission to bind
1985 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001986 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001987 Bundle options = info.bindOptions;
1988
1989 boolean success = false;
1990 if (options != null) {
1991 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1992 info.componentName, options);
1993 } else {
1994 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1995 info.componentName);
1996 }
1997 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001998 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001999 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002000 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002001 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2002 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2003 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002004 // TODO: we need to make sure that this accounts for the options bundle.
2005 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002006 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2007 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002008 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002009 }
2010
Joe Onoratodeb98af2010-02-19 14:59:39 -08002011 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002012 // Handle case where user selected "Applications"
2013 String applicationName = getResources().getString(R.string.group_applications);
2014 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 if (applicationName != null && applicationName.equals(shortcutName)) {
2017 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2018 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002019
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002020 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2021 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002022 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002023 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002024 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002025 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
Winson Chung24ab2f12010-09-16 14:10:47 -07002029 void processWallpaper(Intent intent) {
2030 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2031 }
2032
Adam Cohendcd297f2013-06-18 13:13:40 -07002033 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002034 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002035 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036 folderInfo.title = getText(R.string.folder_name);
2037
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002039 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002041 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002042
2043 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002044 FolderIcon newFolder =
2045 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002046 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002047 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002048 // Force measure the new folder icon
2049 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2050 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002051 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 }
Romain Guycbb89e42009-06-08 15:52:54 -07002053
Joe Onorato9c1289c2009-08-17 11:03:03 -04002054 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002055 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002056 }
2057
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002058 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002059 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002061 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002062 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 }
2064
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002065 protected ComponentName getWallpaperPickerComponent() {
2066 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2067 }
2068
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002069 /**
2070 * Registers various content observers. The current implementation registers
2071 * only a favorites observer to keep track of the favorites applications.
2072 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002073 private void registerContentObservers() {
2074 ContentResolver resolver = getContentResolver();
2075 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2076 true, mWidgetObserver);
2077 }
2078
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 @Override
2080 public boolean dispatchKeyEvent(KeyEvent event) {
2081 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2082 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002084 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002085 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002086 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002087 dumpState();
2088 return true;
2089 }
2090 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002091 }
2092 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2093 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002094 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 return true;
2096 }
2097 }
2098
2099 return super.dispatchKeyEvent(event);
2100 }
2101
Joe Onorato88ec0992009-11-19 13:16:06 -08002102 @Override
2103 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002104 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002105 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002106 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002107 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002108 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002109 Folder openFolder = mWorkspace.getOpenFolder();
2110 if (openFolder.isEditingName()) {
2111 openFolder.dismissEditingName();
2112 } else {
2113 closeFolder();
2114 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002115 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002116 mWorkspace.exitWidgetResizeMode();
2117
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002118 // Back button is a no-op here, but give at least some feedback for the button press
2119 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002120 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002121 }
2122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002124 * Re-listen when widgets are reset.
2125 */
2126 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002127 if (mAppWidgetHost != null) {
2128 mAppWidgetHost.startListening();
2129 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002130 }
2131
2132 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002133 * Launches the intent referred by the clicked shortcut.
2134 *
2135 * @param v The view representing the clicked shortcut.
2136 */
2137 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002138 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2139 // view has detached (it's possible for this to happen if the view is removed mid touch).
2140 if (v.getWindowToken() == null) {
2141 return;
2142 }
2143
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002144 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002145 return;
2146 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002147
Adam Cohen1697b792013-09-17 19:08:21 -07002148 if (v instanceof Workspace) {
2149 if (mWorkspace.isInOverviewMode()) {
2150 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002151 }
2152 return;
2153 }
2154
2155 if (v instanceof CellLayout) {
2156 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002157 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002158 }
2159 }
2160
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002162 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002164 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2165 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002166
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002167 // Check for special shortcuts
2168 if (intent.getComponent() != null) {
2169 final String shortcutClass = intent.getComponent().getClassName();
2170
2171 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002172 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002173 return;
2174 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2175 MemoryDumpActivity.startDump(this);
2176 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002177 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2178 toggleShowWeightWatcher();
2179 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002180 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002181 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002182
2183 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002184 int[] pos = new int[2];
2185 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002186 intent.setSourceBounds(new Rect(pos[0], pos[1],
2187 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002188
2189 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002190
Daniel Sandlerff02d492013-08-05 02:12:05 -04002191 mStats.recordLaunch(intent, shortcut);
2192
Michael Jurkaddd62e92011-02-16 17:49:14 -08002193 if (success && v instanceof BubbleTextView) {
2194 mWaitingForResume = (BubbleTextView) v;
2195 mWaitingForResume.setStayPressed(true);
2196 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002198 if (v instanceof FolderIcon) {
2199 FolderIcon fi = (FolderIcon) v;
2200 handleFolderClick(fi);
2201 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002202 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002203 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002204 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002205 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002206 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002207 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 }
2209 }
2210
Michael Jurka0e260592010-06-30 17:07:39 -07002211 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002212 return false;
2213 }
2214
Michael Jurkaaf442092010-06-10 17:01:57 -07002215 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002216 * Event handler for the search button
2217 *
2218 * @param v The view that was clicked.
2219 */
2220 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002221 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2222
Amith Yamasania135ba82011-08-09 17:42:01 -07002223 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002224 }
2225
2226 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002227 * Event handler for the voice button
2228 *
2229 * @param v The view that was clicked.
2230 */
2231 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002232 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002233
Bjorn Bringertc459e522013-06-07 19:36:01 +01002234 startVoice();
2235 }
2236
2237 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002238 try {
2239 final SearchManager searchManager =
2240 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2241 ComponentName activityName = searchManager.getGlobalSearchActivity();
2242 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002243 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002244 if (activityName != null) {
2245 intent.setPackage(activityName.getPackageName());
2246 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002247 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002248 } catch (ActivityNotFoundException e) {
2249 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002250 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002251 startActivitySafely(null, intent, "onClickVoiceButton");
2252 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002253 }
2254
2255 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002256 * Event handler for the "grid" button that appears on the home screen, which
2257 * enters all apps mode.
2258 *
2259 * @param v The view that was clicked.
2260 */
2261 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002262 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002263 }
2264
2265 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002266 // Provide the same haptic feedback that the system offers for virtual keys.
2267 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002268 }
2269
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002270 public void onClickAppMarketButton(View v) {
2271 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002272 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002273 } else {
2274 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002275 }
2276 }
2277
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002278 /**
2279 * Called when the user stops interacting with the launcher.
2280 * This implies that the user is now on the homescreen and is not doing housekeeping.
2281 */
2282 protected void onInteractionEnd() {}
2283
2284 /**
2285 * Called when the user starts interacting with the launcher.
2286 * The possible interactions are:
2287 * - open all apps
2288 * - reorder an app shortcut, or a widget
2289 * - open the overview mode.
2290 * This is a good time to stop doing things that only make sense
2291 * when the user is on the homescreen and not doing housekeeping.
2292 */
2293 protected void onInteractionBegin() {}
2294
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002295 void startApplicationDetailsActivity(ComponentName componentName) {
2296 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002297 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2298 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002299 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002300 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002301 }
2302
Michael Jurka1e2f4652013-07-08 18:03:46 -07002303 // returns true if the activity was started
2304 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002305 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002306 // System applications cannot be installed. For now, show a toast explaining that.
2307 // We may give them the option of disabling apps this way.
2308 int messageId = R.string.uninstall_system_app_text;
2309 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002310 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002311 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002312 String packageName = componentName.getPackageName();
2313 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002314 Intent intent = new Intent(
2315 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002316 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2317 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002318 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002319 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002320 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002321 }
2322
Michael Jurka86a720e2012-05-09 11:23:23 -07002323 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002324 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002325
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002327 // Only launch using the new animation if the shortcut has not opted out (this is a
2328 // private contract between launcher and may be ignored in the future).
2329 boolean useLaunchAnimation = (v != null) &&
2330 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2331 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002332 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2333 v.getMeasuredWidth(), v.getMeasuredHeight());
2334
2335 startActivity(intent, opts.toBundle());
2336 } else {
2337 startActivity(intent);
2338 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002339 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 } catch (SecurityException e) {
2341 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002342 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002344 "or use the exported attribute for this activity. "
2345 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002346 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002347 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002348 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002349
Michael Jurka86a720e2012-05-09 11:23:23 -07002350 boolean startActivitySafely(View v, Intent intent, Object tag) {
2351 boolean success = false;
2352 try {
2353 success = startActivity(v, intent, tag);
2354 } catch (ActivityNotFoundException e) {
2355 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2356 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2357 }
2358 return success;
2359 }
2360
Adam Cohena9cf38f2011-05-02 15:36:58 -07002361 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002362 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002363 Folder openFolder = mWorkspace.getFolderForTag(info);
2364
2365 // If the folder info reports that the associated folder is open, then verify that
2366 // it is actually opened. There have been a few instances where this gets out of sync.
2367 if (info.opened && openFolder == null) {
2368 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002369 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002370 info.opened = false;
2371 }
2372
Adam Cohenfb91f302012-06-11 15:45:18 -07002373 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 // Close any open folder
2375 closeFolder();
2376 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002377 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378 } else {
2379 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002380 int folderScreen;
2381 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002382 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 // .. and close it
2384 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002385 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 // Close any folder open on the current screen
2387 closeFolder();
2388 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002389 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 }
2391 }
2392 }
2393 }
2394
Adam Cohen268c4752012-06-06 17:47:33 -07002395 /**
2396 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2397 * in the DragLayer in the exact absolute location of the original FolderIcon.
2398 */
2399 private void copyFolderIconToImage(FolderIcon fi) {
2400 final int width = fi.getMeasuredWidth();
2401 final int height = fi.getMeasuredHeight();
2402
2403 // Lazy load ImageView, Bitmap and Canvas
2404 if (mFolderIconImageView == null) {
2405 mFolderIconImageView = new ImageView(this);
2406 }
2407 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2408 mFolderIconBitmap.getHeight() != height) {
2409 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2410 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2411 }
2412
2413 DragLayer.LayoutParams lp;
2414 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2415 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2416 } else {
2417 lp = new DragLayer.LayoutParams(width, height);
2418 }
2419
Adam Cohen307fe232012-08-16 17:55:58 -07002420 // The layout from which the folder is being opened may be scaled, adjust the starting
2421 // view size by this scale factor.
2422 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002423 lp.customPosition = true;
2424 lp.x = mRectForFolderAnimation.left;
2425 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002426 lp.width = (int) (scale * width);
2427 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002428
2429 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2430 fi.draw(mFolderIconCanvas);
2431 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002432 if (fi.getFolder() != null) {
2433 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2434 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002435 }
Adam Cohen268c4752012-06-06 17:47:33 -07002436 // Just in case this image view is still in the drag layer from a previous animation,
2437 // we remove it and re-add it.
2438 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2439 mDragLayer.removeView(mFolderIconImageView);
2440 }
2441 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002442 if (fi.getFolder() != null) {
2443 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002444 }
Adam Cohen268c4752012-06-06 17:47:33 -07002445 }
2446
Adam Cohen2801caf2011-05-13 20:57:39 -07002447 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002448 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002449 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2450 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2451 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2452
Adam Cohenc51934b2011-07-26 21:07:43 -07002453 FolderInfo info = (FolderInfo) fi.getTag();
2454 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2455 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002456 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2457 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002458 }
2459
Adam Cohen268c4752012-06-06 17:47:33 -07002460 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2461 copyFolderIconToImage(fi);
2462 fi.setVisibility(View.INVISIBLE);
2463
Michael Jurka2ecf9952012-06-18 12:52:28 -07002464 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002465 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002466 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2467 oa.start();
2468 }
2469
Adam Cohen268c4752012-06-06 17:47:33 -07002470 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002471 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002472 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2473 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2474 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2475
Adam Cohen268c4752012-06-06 17:47:33 -07002476 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002477
Adam Cohen268c4752012-06-06 17:47:33 -07002478 // We remove and re-draw the FolderIcon in-case it has changed
2479 mDragLayer.removeView(mFolderIconImageView);
2480 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002481 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002482 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002483 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002484 oa.addListener(new AnimatorListenerAdapter() {
2485 @Override
2486 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002487 if (cl != null) {
2488 cl.clearFolderLeaveBehind();
2489 // Remove the ImageView copy of the FolderIcon and make the original visible.
2490 mDragLayer.removeView(mFolderIconImageView);
2491 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002492 }
2493 }
2494 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002495 oa.start();
2496 }
2497
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002498 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002499 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002500 * is animated relative to the specified View. If the View is null, no animation
2501 * is played.
2502 *
2503 * @param folderInfo The FolderInfo describing the folder to open.
2504 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002505 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002506 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002507 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002508
Adam Cohena9cf38f2011-05-02 15:36:58 -07002509 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002510
Adam Cohen4554ee12011-08-03 16:13:21 -07002511 // Just verify that the folder hasn't already been added to the DragLayer.
2512 // There was a one-off crash where the folder had a parent already.
2513 if (folder.getParent() == null) {
2514 mDragLayer.addView(folder);
2515 mDragController.addDropTarget((DropTarget) folder);
2516 } else {
2517 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2518 folder.getParent() + ").");
2519 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002520 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002521 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002522
2523 // Notify the accessibility manager that this folder "window" has appeared and occluded
2524 // the workspace items
2525 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2526 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002527 }
2528
2529 public void closeFolder() {
2530 Folder folder = mWorkspace.getOpenFolder();
2531 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002532 if (folder.isEditingName()) {
2533 folder.dismissEditingName();
2534 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002535 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002536
2537 // Dismiss the folder cling
2538 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002539 }
2540 }
2541
2542 void closeFolder(Folder folder) {
2543 folder.getInfo().opened = false;
2544
2545 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2546 if (parent != null) {
2547 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2548 shrinkAndFadeInFolderIcon(fi);
2549 }
2550 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002551
2552 // Notify the accessibility manager that this folder "window" has disappeard and no
2553 // longer occludeds the workspace items
2554 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555 }
2556
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002558 if (!isDraggingEnabled()) return false;
2559 if (isWorkspaceLocked()) return false;
2560 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002561
Adam Cohen1697b792013-09-17 19:08:21 -07002562 if (v instanceof Workspace) {
2563 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002564 if (mWorkspace.enterOverviewMode()) {
2565 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2566 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2567 return true;
2568 } else {
2569 return false;
2570 }
Adam Cohen1697b792013-09-17 19:08:21 -07002571 }
Adam Cohen1697b792013-09-17 19:08:21 -07002572 }
2573
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002574 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002575 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002576 }
2577
Michael Jurka0280c3b2010-09-17 15:00:07 -07002578 resetAddInfo();
2579 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002580 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002581 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002582 return true;
2583 }
2584
Winson Chung3d503fb2011-07-13 17:25:49 -07002585 // The hotseat touch handling does not go through Workspace, and we always allow long press
2586 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002587 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002588 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2589 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002590 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002591 // User long pressed on empty space
2592 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2593 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2594 // Disabling reordering until we sort out some issues.
2595 if (mWorkspace.isInOverviewMode()) {
2596 mWorkspace.startReordering(v);
2597 } else {
2598 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002599 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002600 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002601 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002602 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002603 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002604 }
2605 }
2606 }
2607 return true;
2608 }
2609
Winson Chung3d503fb2011-07-13 17:25:49 -07002610 boolean isHotseatLayout(View layout) {
2611 return mHotseat != null && layout != null &&
2612 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2613 }
2614 Hotseat getHotseat() {
2615 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002616 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002617 View getOverviewPanel() {
2618 return mOverviewPanel;
2619 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002620 SearchDropTargetBar getSearchBar() {
2621 return mSearchDropTargetBar;
2622 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002623
Winson Chung3d503fb2011-07-13 17:25:49 -07002624 /**
2625 * Returns the CellLayout of the specified container at the specified screen.
2626 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002627 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002628 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2629 if (mHotseat != null) {
2630 return mHotseat.getLayout();
2631 } else {
2632 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002633 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002634 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002635 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002636 }
2637 }
2638
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002639 Workspace getWorkspace() {
2640 return mWorkspace;
2641 }
2642
Daniel Sandler843e8602010-06-07 14:59:01 -04002643 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002644 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002645 }
2646
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002647 /**
2648 * Helper method for the cameraZoomIn/cameraZoomOut animations
2649 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002650 * @param scaleFactor The scale factor used for the zoom
2651 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002652 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002653 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002654 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002655 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002656
Craig Mautner360310b2012-10-26 15:13:08 -07002657 private void setWorkspaceBackground(boolean workspace) {
2658 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002659 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002660 }
2661
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002662 void updateWallpaperVisibility(boolean visible) {
2663 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2664 int curflags = getWindow().getAttributes().flags
2665 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2666 if (wpflags != curflags) {
2667 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2668 }
Craig Mautner360310b2012-10-26 15:13:08 -07002669 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002670 }
2671
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002672 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2673 if (v instanceof LauncherTransitionable) {
2674 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2675 }
2676 }
2677
Michael Jurkabed61d22012-02-14 22:51:29 -08002678 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2679 if (v instanceof LauncherTransitionable) {
2680 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2681 }
Winson Chung70442722012-02-10 15:43:22 -08002682
2683 // Update the workspace transition step as well
2684 dispatchOnLauncherTransitionStep(v, 0f);
2685 }
2686
2687 private void dispatchOnLauncherTransitionStep(View v, float t) {
2688 if (v instanceof LauncherTransitionable) {
2689 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2690 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002691 }
2692
2693 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2694 if (v instanceof LauncherTransitionable) {
2695 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2696 }
Winson Chung70442722012-02-10 15:43:22 -08002697
2698 // Update the workspace transition step as well
2699 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002700 }
2701
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002702 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002703 * Things to test when changing the following seven functions.
2704 * - Home from workspace
2705 * - from center screen
2706 * - from other screens
2707 * - Home from all apps
2708 * - from center screen
2709 * - from other screens
2710 * - Back from all apps
2711 * - from center screen
2712 * - from other screens
2713 * - Launch app from workspace and quit
2714 * - with back
2715 * - with home
2716 * - Launch app from all apps and quit
2717 * - with back
2718 * - with home
2719 * - Go to a screen that's not the default, then all
2720 * apps, and launch and app, and go back
2721 * - with back
2722 * -with home
2723 * - On workspace, long press power and go back
2724 * - with back
2725 * - with home
2726 * - On all apps, long press power and go back
2727 * - with back
2728 * - with home
2729 * - On workspace, power off
2730 * - On all apps, power off
2731 * - Launch an app and turn off the screen while in that app
2732 * - Go back with home key
2733 * - Go back with back key TODO: make this not go to workspace
2734 * - From all apps
2735 * - From workspace
2736 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2737 * - From all apps
2738 * - From the center workspace
2739 * - From another workspace
2740 */
2741
2742 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002743 * Zoom the camera out from the workspace to reveal 'toView'.
2744 * Assumes that the view to show is anchored at either the very top or very bottom
2745 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002746 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002747 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002748 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2749 showAppsCustomizeHelper(animated, springLoaded, contentType);
2750 }
2751 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2752 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002753 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002754 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002755 mStateAnimation.cancel();
2756 mStateAnimation = null;
2757 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002758 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002759
Winson Chungf0ea4d32011-06-06 14:27:16 -07002760 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2761 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2762 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002763 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002764 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002765 final int startDelay =
2766 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002767
Michael Jurkab3e22d92011-10-31 15:58:33 -07002768 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002769
Michael Jurkad74c9842011-07-10 12:44:21 -07002770 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002771 Animator workspaceAnim =
2772 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002773 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2774 // Set the content type for the all apps space
2775 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2776 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002777
2778 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002779 toView.setScaleX(scale);
2780 toView.setScaleY(scale);
2781 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2782 scaleAnim.
2783 scaleX(1f).scaleY(1f).
2784 setDuration(duration).
2785 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002786
Winson Chungf0ea4d32011-06-06 14:27:16 -07002787 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002788 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002789 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002790 .ofFloat(toView, "alpha", 0f, 1f)
2791 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002792 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002793 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2794 @Override
2795 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002796 if (animation == null) {
2797 throw new RuntimeException("animation is null");
2798 }
Winson Chung70442722012-02-10 15:43:22 -08002799 float t = (Float) animation.getAnimatedValue();
2800 dispatchOnLauncherTransitionStep(fromView, t);
2801 dispatchOnLauncherTransitionStep(toView, t);
2802 }
2803 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002804
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002805 // toView should appear right at the end of the workspace shrink
2806 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002807 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002808 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002809 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002810
2811 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002812 boolean animationCancelled = false;
2813
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002814 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002815 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002816 // Prepare the position
2817 toView.setTranslationX(0.0f);
2818 toView.setTranslationY(0.0f);
2819 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002820 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002821 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002822 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002823 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002824 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2825 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002826
Winson Chungc7d2b602012-05-16 17:02:20 -07002827 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002828 if (mSearchDropTargetBar != null) {
2829 mSearchDropTargetBar.hideSearchBar(false);
2830 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002831 }
2832
Adam Cohencff6af82011-09-13 14:51:53 -07002833 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002834 public void onAnimationCancel(Animator animation) {
2835 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002836 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002837 });
2838
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002839 if (workspaceAnim != null) {
2840 mStateAnimation.play(workspaceAnim);
2841 }
Michael Jurka1899a362011-11-03 13:50:45 -07002842
2843 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002844
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002845 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2846 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002847
2848 // If any of the objects being animated haven't been measured/laid out
2849 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002850 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851 (mWorkspace.getMeasuredWidth() == 0) ||
2852 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002854 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002856 final AnimatorSet stateAnimation = mStateAnimation;
2857 final Runnable startAnimRunnable = new Runnable() {
2858 public void run() {
2859 // Check that mStateAnimation hasn't changed while
2860 // we waited for a layout/draw pass
2861 if (mStateAnimation != stateAnimation)
2862 return;
2863 setPivotsForZoom(toView, scale);
2864 dispatchOnLauncherTransitionStart(fromView, animated, false);
2865 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002866 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002867 }
2868 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002869 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002870 final ViewTreeObserver observer = toView.getViewTreeObserver();
2871 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2872 public void onGlobalLayout() {
2873 startAnimRunnable.run();
2874 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2875 }
2876 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002877 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002878 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002879 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002880 } else {
2881 toView.setTranslationX(0.0f);
2882 toView.setTranslationY(0.0f);
2883 toView.setScaleX(1.0f);
2884 toView.setScaleY(1.0f);
2885 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002886 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002887
Daniel Sandlere4f98912013-06-25 15:13:26 -04002888 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002889 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002890 if (mSearchDropTargetBar != null) {
2891 mSearchDropTargetBar.hideSearchBar(false);
2892 }
Michael Jurkaabded662011-03-04 12:06:57 -08002893 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002894 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002895 dispatchOnLauncherTransitionStart(fromView, animated, false);
2896 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002897 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002898 dispatchOnLauncherTransitionStart(toView, animated, false);
2899 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002900 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002901 }
2902
2903 /**
2904 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002905 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002906 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002907 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002908 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2909 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002910
Michael Jurkab3e22d92011-10-31 15:58:33 -07002911 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002912 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002913 mStateAnimation.cancel();
2914 mStateAnimation = null;
2915 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002916 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002917
Winson Chungf0ea4d32011-06-06 14:27:16 -07002918 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002919 final int fadeOutDuration =
2920 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002921 final float scaleFactor = (float)
2922 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2923 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002924 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002925 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002926 if (toState == State.WORKSPACE) {
2927 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2928 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002929 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002930 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2931 workspaceAnim = mWorkspace.getChangeStateAnimation(
2932 Workspace.State.SPRING_LOADED, animated);
2933 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002934
Michael Jurkab3e22d92011-10-31 15:58:33 -07002935 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002936 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002937 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002938 final LauncherViewPropertyAnimator scaleAnim =
2939 new LauncherViewPropertyAnimator(fromView);
2940 scaleAnim.
2941 scaleX(scaleFactor).scaleY(scaleFactor).
2942 setDuration(duration).
2943 setInterpolator(new Workspace.ZoomInInterpolator());
2944
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002945 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002946 .ofFloat(fromView, "alpha", 1f, 0f)
2947 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002948 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002949 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2950 @Override
2951 public void onAnimationUpdate(ValueAnimator animation) {
2952 float t = 1f - (Float) animation.getAnimatedValue();
2953 dispatchOnLauncherTransitionStep(fromView, t);
2954 dispatchOnLauncherTransitionStep(toView, t);
2955 }
2956 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002957
Michael Jurka2ecf9952012-06-18 12:52:28 -07002958 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002959
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002960 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2961 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002962 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002963
2964 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002965 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002966 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002967 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002968 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2969 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002970 if (onCompleteRunnable != null) {
2971 onCompleteRunnable.run();
2972 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002973 mAppsCustomizeContent.updateCurrentPageScroll();
2974 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002975 }
2976 });
2977
Winson Chungf0ea4d32011-06-06 14:27:16 -07002978 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002979 if (workspaceAnim != null) {
2980 mStateAnimation.play(workspaceAnim);
2981 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002982 dispatchOnLauncherTransitionStart(fromView, animated, true);
2983 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002984 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002985 } else {
2986 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002987 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002988 dispatchOnLauncherTransitionStart(fromView, animated, true);
2989 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002990 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002991 dispatchOnLauncherTransitionStart(toView, animated, true);
2992 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002993 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002994 }
2995
Michael Jurkae326f182011-11-21 14:05:46 -08002996 @Override
2997 public void onTrimMemory(int level) {
2998 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002999 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003000 mAppsCustomizeTabHost.onTrimMemory();
3001 }
3002 }
3003
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003004 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003005 showWorkspace(animated, null);
3006 }
3007
3008 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003009 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003010 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003011 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003012 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003013
Winson Chungc7d2b602012-05-16 17:02:20 -07003014 // Show the search bar (only animate if we were showing the drop target bar in spring
3015 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003016 if (mSearchDropTargetBar != null) {
3017 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3018 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003019
Michael Jurkab3e22d92011-10-31 15:58:33 -07003020 // Set focus to the AppsCustomize button
3021 if (mAllAppsButton != null) {
3022 mAllAppsButton.requestFocus();
3023 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003024 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003025
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003026 // Change the state *after* we've called all the transition code
3027 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003028
Winson Chung5fb63472011-02-02 17:03:37 -08003029 // Resume the auto-advance of widgets
3030 mUserPresent = true;
3031 updateRunning();
3032
alanv1d4fde62012-10-17 13:15:47 -07003033 // Send an accessibility event to announce the context change
3034 getWindow().getDecorView()
3035 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003036
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003037 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003038 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003039 }
3040
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003041 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003042 }
3043
Winson Chungc58497e2013-09-03 17:48:37 -07003044 void showAllApps(boolean animated,
3045 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003046 if (mState != State.WORKSPACE) return;
3047
Winson Chungc58497e2013-09-03 17:48:37 -07003048 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003049 mAppsCustomizeTabHost.requestFocus();
3050
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051 // Change the state *after* we've called all the transition code
3052 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003053 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003054
3055 // Pause the auto-advance of widgets until we are out of AllApps
3056 mUserPresent = false;
3057 updateRunning();
3058 closeFolder();
3059
3060 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003061 getWindow().getDecorView()
3062 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003063 }
3064
Adam Cohen7777d962011-08-18 18:58:38 -07003065 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003066 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003067 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003068 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003069 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003070 }
Adam Cohen7777d962011-08-18 18:58:38 -07003071
Adam Cohened66b2b2012-01-23 17:28:51 -08003072 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3073 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003074 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3075
Winson Chunge7a03942011-08-05 15:05:12 -07003076 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003077 @Override
3078 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003079 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003080 // Before we show workspace, hide all apps again because
3081 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3082 // clean up our state transition functions
3083 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003084 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003085 } else {
3086 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003087 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003088 }
3089 }, (extendedDelay ?
3090 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3091 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3092 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003093
Michael Jurkad3ef3062010-11-23 16:23:58 -08003094 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003095 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003096 final boolean animated = true;
3097 final boolean springLoaded = true;
3098 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003099 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003100 }
3101 // Otherwise, we are not in spring loaded mode, so don't do anything.
3102 }
3103
Michael Jurkab3e22d92011-10-31 15:58:33 -07003104 void lockAllApps() {
3105 // TODO
3106 }
3107
3108 void unlockAllApps() {
3109 // TODO
3110 }
3111
Winson Chungf0ea4d32011-06-06 14:27:16 -07003112 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003113 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003114 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003115 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003116 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003117 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003118 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003119 int duration = 0;
3120 if (mSearchDropTargetBar != null) {
3121 duration = mSearchDropTargetBar.getTransitionInDuration();
3122 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003123 mHotseat.animate().alpha(1f).setDuration(duration);
3124 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003125 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003126 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003127 }
3128 }
3129 }
3130
3131 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003132 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003133 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003134 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003135 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003136 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003137 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003138 int duration = 0;
3139 if (mSearchDropTargetBar != null) {
3140 duration = mSearchDropTargetBar.getTransitionOutDuration();
3141 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003142 mHotseat.animate().alpha(0f).setDuration(duration);
3143 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003144 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003145 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003146 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003147 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003148 }
3149
Patrick Dubroy5f445422011-02-18 14:35:21 -08003150 /**
3151 * Add an item from all apps or customize onto the given workspace screen.
3152 * If layout is null, add to the current screen.
3153 */
3154 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003155 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003156 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003157 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003158 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003159
Winson Chungdff8ebb2011-09-08 17:25:31 -07003160 /** Maps the current orientation to an index for referencing orientation correct global icons */
3161 private int getCurrentOrientationIndexForGlobalIcons() {
3162 // default - 0, landscape - 1
3163 switch (getResources().getConfiguration().orientation) {
3164 case Configuration.ORIENTATION_LANDSCAPE:
3165 return 1;
3166 default:
3167 return 0;
3168 }
3169 }
3170
Michael Jurkaae65ee32012-04-30 11:45:54 -07003171 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003172 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003173 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003174 // Look for the toolbar icon specified in the activity meta-data
3175 Bundle metaData = packageManager.getActivityInfo(
3176 activityName, PackageManager.GET_META_DATA).metaData;
3177 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003178 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003179 if (iconResId != 0) {
3180 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003181 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003182 }
3183 }
3184 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003185 // This can happen if the activity defines an invalid drawable
3186 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3187 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003188 } catch (Resources.NotFoundException nfe) {
3189 // This can happen if the activity defines an invalid drawable
3190 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3191 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003192 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003193 return null;
3194 }
3195
3196 // if successful in getting icon, return it; otherwise, set button to use default drawable
3197 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003198 int buttonId, ComponentName activityName, int fallbackDrawableId,
3199 String toolbarResourceName) {
3200 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003201 Resources r = getResources();
3202 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3203 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003204
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003205 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003206 // If we were unable to find the icon via the meta-data, use a generic one
3207 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003208 toolbarIcon = r.getDrawable(fallbackDrawableId);
3209 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003210 if (button != null) {
3211 button.setCompoundDrawables(toolbarIcon, null, null, null);
3212 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003213 return null;
3214 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003215 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003216 if (button != null) {
3217 button.setCompoundDrawables(toolbarIcon, null, null, null);
3218 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003219 return toolbarIcon.getConstantState();
3220 }
3221 }
3222
3223 // if successful in getting icon, return it; otherwise, set button to use default drawable
3224 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003225 int buttonId, ComponentName activityName, int fallbackDrawableId,
3226 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003227 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003228 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003229
Michael Jurka19e0fc52011-07-22 18:00:21 -07003230 if (button != null) {
3231 // If we were unable to find the icon via the meta-data, use a
3232 // generic one
3233 if (toolbarIcon == null) {
3234 button.setImageResource(fallbackDrawableId);
3235 } else {
3236 button.setImageDrawable(toolbarIcon);
3237 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003238 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003239
3240 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3241
Michael Jurka0423dcf2010-10-05 14:56:18 -07003242 }
3243
Winson Chung1b884092012-06-08 17:13:02 -07003244 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003245 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003246 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003247 }
3248
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003249 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003250 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003251 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003252 }
3253
Winson Chungbb185bd2011-11-21 12:31:42 -08003254 private void invalidatePressedFocusedStates(View container, View button) {
3255 if (container instanceof HolographicLinearLayout) {
3256 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3257 layout.invalidatePressedFocusedStates();
3258 } else if (button instanceof HolographicImageView) {
3259 HolographicImageView view = (HolographicImageView) button;
3260 view.invalidatePressedFocusedStates();
3261 }
3262 }
3263
Cristina Stancu476493b2013-08-07 17:20:14 +01003264 public View getQsbBar() {
3265 if (mQsbBar == null) {
3266 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3267 }
3268 return mQsbBar;
3269 }
3270
3271 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003272 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003273 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003274 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003275 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003276
Winson Chung1cad91e2011-05-25 17:41:01 -07003277 final SearchManager searchManager =
3278 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3279 ComponentName activityName = searchManager.getGlobalSearchActivity();
3280 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003281 int coi = getCurrentOrientationIndexForGlobalIcons();
3282 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003283 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3284 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3285 if (sGlobalSearchIcon[coi] == null) {
3286 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3287 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3288 TOOLBAR_ICON_METADATA_NAME);
3289 }
3290
Winson Chungc51db6a2011-10-05 11:44:49 -07003291 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3292 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003293 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003294 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003295 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003296 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003297 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3298 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003299 if (searchButton != null) searchButton.setVisibility(View.GONE);
3300 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003301 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003302 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003303 }
3304 }
3305
Cristina Stancu476493b2013-08-07 17:20:14 +01003306 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003307 final View searchButtonContainer = findViewById(R.id.search_button_container);
3308 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003309 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003310 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003311 }
3312
Cristina Stancu476493b2013-08-07 17:20:14 +01003313 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003314 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003315 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003316
Winson Chungc51db6a2011-10-05 11:44:49 -07003317 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003318 final SearchManager searchManager =
3319 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3320 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3321
3322 ComponentName activityName = null;
3323 if (globalSearchActivity != null) {
3324 // Check if the global search activity handles voice search
3325 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3326 intent.setPackage(globalSearchActivity.getPackageName());
3327 activityName = intent.resolveActivity(getPackageManager());
3328 }
3329
3330 if (activityName == null) {
3331 // Fallback: check if an activity other than the global search activity
3332 // resolves this
3333 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3334 activityName = intent.resolveActivity(getPackageManager());
3335 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003336 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003337 int coi = getCurrentOrientationIndexForGlobalIcons();
3338 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003339 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3340 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3341 if (sVoiceSearchIcon[coi] == null) {
3342 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3343 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3344 TOOLBAR_ICON_METADATA_NAME);
3345 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003346 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003347 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003348 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003349 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003350 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003351 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003352 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003353 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003354 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003355 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003356 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003357 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003358
Cristina Stancu476493b2013-08-07 17:20:14 +01003359 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003360 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3361 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003362 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003363 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003364 }
3365
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003366 public void setVoiceButtonProxyVisible(boolean visible) {
3367 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3368 if (voiceButtonProxy != null) {
3369 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3370 }
3371 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003372 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003373 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003374 */
3375 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003376 final View marketButton = findViewById(R.id.market_button);
3377 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3378 // Find the app market activity by resolving an intent.
3379 // (If multiple app markets are installed, it will return the ResolverActivity.)
3380 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003381 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003382 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003383 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003384 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003385 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3386 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003387 marketButton.setVisibility(View.VISIBLE);
3388 } else {
3389 // We should hide and disable the view so that we don't try and restore the visibility
3390 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3391 marketButton.setVisibility(View.GONE);
3392 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003393 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003394 }
3395
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003396 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003397 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3398 Resources r = getResources();
3399 Drawable marketIconDrawable = d.newDrawable(r);
3400 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3401 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3402 marketIconDrawable.setBounds(0, 0, w, h);
3403
3404 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003405 }
3406
Michael Jurkad7c28052012-04-27 15:43:36 -07003407 @Override
3408 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003409 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003410 final List<CharSequence> text = event.getText();
3411 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003412 // Populate event with a fake title based on the current state.
3413 if (mState == State.APPS_CUSTOMIZE) {
3414 text.add(getString(R.string.all_apps_button_label));
3415 } else {
3416 text.add(getString(R.string.all_apps_home_button_label));
3417 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003418 return result;
3419 }
3420
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003421 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003422 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003423 */
3424 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3425 @Override
3426 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003427 closeSystemDialogs();
3428 }
3429 }
3430
3431 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003432 * Receives notifications whenever the appwidgets are reset.
3433 */
3434 private class AppWidgetResetObserver extends ContentObserver {
3435 public AppWidgetResetObserver() {
3436 super(new Handler());
3437 }
3438
3439 @Override
3440 public void onChange(boolean selfChange) {
3441 onAppWidgetReset();
3442 }
3443 }
3444
3445 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003446 * If the activity is currently paused, signal that we need to run the passed Runnable
3447 * in onResume.
3448 *
3449 * This needs to be called from incoming places where resources might have been loaded
3450 * while we are paused. That is becaues the Configuration might be wrong
3451 * when we're not running, and if it comes back to what it was when we
3452 * were paused, we are not restarted.
3453 *
3454 * Implementation of the method from LauncherModel.Callbacks.
3455 *
3456 * @return true if we are currently paused. The caller might be able to
3457 * skip some work in that case since we will come back again.
3458 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003459 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003460 if (mPaused) {
3461 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003462 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003463 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003464 }
3465 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003466 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003467 return true;
3468 } else {
3469 return false;
3470 }
3471 }
3472
Michael Jurkac402cd92013-05-20 15:49:32 +02003473 private boolean waitUntilResume(Runnable run) {
3474 return waitUntilResume(run, false);
3475 }
3476
Michael Jurka1e2f4652013-07-08 18:03:46 -07003477 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003478 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003479 }
3480
Michael Jurka7607c2f2013-04-03 14:33:19 -07003481 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003482 * If the activity is currently paused, signal that we need to re-run the loader
3483 * in onResume.
3484 *
3485 * This needs to be called from incoming places where resources might have been loaded
3486 * while we are paused. That is becaues the Configuration might be wrong
3487 * when we're not running, and if it comes back to what it was when we
3488 * were paused, we are not restarted.
3489 *
3490 * Implementation of the method from LauncherModel.Callbacks.
3491 *
3492 * @return true if we are currently paused. The caller might be able to
3493 * skip some work in that case since we will come back again.
3494 */
3495 public boolean setLoadOnResume() {
3496 if (mPaused) {
3497 Log.i(TAG, "setLoadOnResume");
3498 mOnResumeNeedsLoad = true;
3499 return true;
3500 } else {
3501 return false;
3502 }
3503 }
3504
3505 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003506 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003507 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003508 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003509 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003510 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003511 } else {
3512 return SCREEN_COUNT / 2;
3513 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003514 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003515
Joe Onorato9c1289c2009-08-17 11:03:03 -04003516 /**
3517 * Refreshes the shortcuts shown on the workspace.
3518 *
3519 * Implementation of the method from LauncherModel.Callbacks.
3520 */
3521 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003522 // If we're starting binding all over again, clear any bind calls we'd postponed in
3523 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3524 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003525 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003526
Winson Chungd64d1762013-08-20 14:37:16 -07003527 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003528 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003529 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003530
Michael Jurka05bf644e2011-11-30 20:28:53 -08003531 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003532 if (mHotseat != null) {
3533 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003534 }
3535 }
3536
Adam Cohendcd297f2013-06-18 13:13:40 -07003537 @Override
3538 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003539 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003540
Adam Cohen5084cba2013-09-03 12:01:16 -07003541 // If there are no screens, we need to have an empty screen
3542 if (orderedScreenIds.size() == 0) {
3543 mWorkspace.addExtraEmptyScreen();
3544 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003545
3546 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003547 // setCurrentPage() so ensure that all pages are added before calling this).
3548 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003549 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3550 mWorkspace.createCustomContentPage();
3551 }
Winson Chung64359a52013-07-08 17:17:08 -07003552 }
3553
3554 @Override
3555 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003556 int count = orderedScreenIds.size();
3557 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003558 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003559 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003560 }
3561
Adam Cohen39a06042013-07-19 14:30:12 -07003562 private boolean shouldShowWeightWatcher() {
3563 String spKey = LauncherAppState.getSharedPreferencesKey();
3564 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003565 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003566
3567 return show;
3568 }
3569
Adam Cohen4caf2982013-08-20 18:54:31 -07003570 private boolean emailSent() {
3571 String spKey = LauncherAppState.getSharedPreferencesKey();
3572 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3573 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3574 return show;
3575 }
3576
3577 private void setEmailSent(boolean sent) {
3578 String spKey = LauncherAppState.getSharedPreferencesKey();
3579 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3580
3581 SharedPreferences.Editor editor = sp.edit();
3582 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3583 editor.commit();
3584 }
3585
Adam Cohen39a06042013-07-19 14:30:12 -07003586 private void toggleShowWeightWatcher() {
3587 String spKey = LauncherAppState.getSharedPreferencesKey();
3588 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3589 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3590
3591 show = !show;
3592
3593 SharedPreferences.Editor editor = sp.edit();
3594 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3595 editor.commit();
3596
3597 if (mWeightWatcher != null) {
3598 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3599 }
3600 }
3601
Winson Chungd64d1762013-08-20 14:37:16 -07003602 public void bindAppsAdded(final ArrayList<Long> newScreens,
3603 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003604 final ArrayList<ItemInfo> addAnimated,
3605 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003606 Runnable r = new Runnable() {
3607 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003608 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003609 }
3610 };
3611 if (waitUntilResume(r)) {
3612 return;
3613 }
3614
Winson Chungd64d1762013-08-20 14:37:16 -07003615 // Add the new screens
3616 bindAddScreens(newScreens);
3617
3618 // We add the items without animation on non-visible pages, and with
3619 // animations on the new page (which we will try and snap to).
3620 if (!addNotAnimated.isEmpty()) {
3621 bindItems(addNotAnimated, 0,
3622 addNotAnimated.size(), false);
3623 }
3624 if (!addAnimated.isEmpty()) {
3625 bindItems(addAnimated, 0,
3626 addAnimated.size(), true);
3627 }
Winson Chungc58497e2013-09-03 17:48:37 -07003628
3629 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3630 addedApps != null && mAppsCustomizeContent != null) {
3631 mAppsCustomizeContent.addApps(addedApps);
3632 }
Winson Chungd64d1762013-08-20 14:37:16 -07003633 }
3634
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003635 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003636 * Bind the items start-end from the list.
3637 *
3638 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003639 */
Winson Chung64359a52013-07-08 17:17:08 -07003640 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3641 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003642 Runnable r = new Runnable() {
3643 public void run() {
3644 bindItems(shortcuts, start, end, forceAnimateIcons);
3645 }
3646 };
3647 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003648 return;
3649 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003650
Winson Chungf0c6ae02012-03-21 16:10:31 -07003651 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003652 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3653 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003654 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003655 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003656 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003657 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003658 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003659
3660 // Short circuit if we are loading dock items for a configuration which has no dock
3661 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3662 mHotseat == null) {
3663 continue;
3664 }
3665
Joe Onorato9c1289c2009-08-17 11:03:03 -04003666 switch (item.itemType) {
3667 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3668 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003669 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003670 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003671
Winson Chung64359a52013-07-08 17:17:08 -07003672 /*
3673 * TODO: FIX collision case
3674 */
Winson Chungce376632013-07-11 16:12:41 -07003675 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3676 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3677 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3678 throw new RuntimeException("OCCUPIED");
3679 }
Winson Chung64359a52013-07-08 17:17:08 -07003680 }
3681
Adam Cohendcd297f2013-06-18 13:13:40 -07003682 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3683 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003684 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003685 // Animate all the applications up now
3686 shortcut.setAlpha(0f);
3687 shortcut.setScaleX(0f);
3688 shortcut.setScaleY(0f);
3689 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003690 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003691 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003692 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003693 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003694 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003695 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003696 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003697 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3698 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003699 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003700 default:
3701 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003703 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003704
Winson Chung997a9232013-07-24 15:33:46 -07003705 if (animateIcons) {
3706 // Animate to the correct page
3707 if (newShortcutsScreenId > -1) {
3708 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003709 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chung997a9232013-07-24 15:33:46 -07003710 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003711 // We post the animation slightly delayed to prevent slowdowns
3712 // when we are loading right after we return to launcher.
3713 mWorkspace.postDelayed(new Runnable() {
3714 public void run() {
3715 mWorkspace.snapToPage(newScreenIndex);
3716 mWorkspace.postDelayed(new Runnable() {
3717 public void run() {
3718 anim.playTogether(bounceAnims);
3719 anim.start();
3720 }
3721 }, NEW_APPS_ANIMATION_DELAY);
3722 }
3723 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003724 }
3725 }
Winson Chung64359a52013-07-08 17:17:08 -07003726 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003727 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003728 }
3729
Joe Onorato9c1289c2009-08-17 11:03:03 -04003730 /**
3731 * Implementation of the method from LauncherModel.Callbacks.
3732 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003733 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003734 Runnable r = new Runnable() {
3735 public void run() {
3736 bindFolders(folders);
3737 }
3738 };
3739 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003740 return;
3741 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003742 sFolders.clear();
3743 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003744 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003745
3746 /**
3747 * Add the views for a widget to the workspace.
3748 *
3749 * Implementation of the method from LauncherModel.Callbacks.
3750 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003751 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003752 Runnable r = new Runnable() {
3753 public void run() {
3754 bindAppWidget(item);
3755 }
3756 };
3757 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003758 return;
3759 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003760
Daniel Sandler843e8602010-06-07 14:59:01 -04003761 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3762 if (DEBUG_WIDGETS) {
3763 Log.d(TAG, "bindAppWidget: " + item);
3764 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003765 final Workspace workspace = mWorkspace;
3766
3767 final int appWidgetId = item.appWidgetId;
3768 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003769 if (DEBUG_WIDGETS) {
3770 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3771 }
3772
Joe Onorato9c1289c2009-08-17 11:03:03 -04003773 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3774
Joe Onorato9c1289c2009-08-17 11:03:03 -04003775 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003776 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777
Adam Cohendcd297f2013-06-18 13:13:40 -07003778 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003779 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003780 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3781
Joe Onorato9c1289c2009-08-17 11:03:03 -04003782 workspace.requestLayout();
3783
Daniel Sandler843e8602010-06-07 14:59:01 -04003784 if (DEBUG_WIDGETS) {
3785 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3786 + (SystemClock.uptimeMillis()-start) + "ms");
3787 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003788 }
3789
Adam Cohen1462de32012-07-24 22:34:36 -07003790 public void onPageBoundSynchronously(int page) {
3791 mSynchronouslyBoundPages.add(page);
3792 }
3793
Joe Onorato9c1289c2009-08-17 11:03:03 -04003794 /**
3795 * Callback saying that there aren't any more items to bind.
3796 *
3797 * Implementation of the method from LauncherModel.Callbacks.
3798 */
Adam Cohene25af792013-06-06 23:08:25 -07003799 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003800 Runnable r = new Runnable() {
3801 public void run() {
3802 finishBindingItems(upgradePath);
3803 }
3804 };
3805 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003806 return;
3807 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003808 if (mSavedState != null) {
3809 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003810 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003811 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812 mSavedState = null;
3813 }
3814
Adam Cohen1462de32012-07-24 22:34:36 -07003815 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003816
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003817 // If we received the result of any pending adds while the loader was running (e.g. the
3818 // widget configuration forced an orientation change), process them now.
3819 for (int i = 0; i < sPendingAddList.size(); i++) {
3820 completeAdd(sPendingAddList.get(i));
3821 }
3822 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003823
Winson Chungc51db6a2011-10-05 11:44:49 -07003824 // Update the market app icon as necessary (the other icons will be managed in response to
3825 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003826 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003827
Winson Chungf0c6ae02012-03-21 16:10:31 -07003828 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003829 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003830 mWorkspace.getUniqueComponents(true, null);
3831 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003832 }
Adam Cohen99894d92013-06-14 11:22:59 -07003833
Adam Cohen66a01fd2013-06-11 12:48:00 -07003834 mWorkspace.post(new Runnable() {
3835 @Override
3836 public void run() {
3837 onFinishBindingItems();
3838 }
3839 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003840 }
3841
Winson Chunga0b7e862013-09-05 16:03:15 -07003842 public boolean isAllAppsButtonRank(int rank) {
3843 if (mHotseat != null) {
3844 return mHotseat.isAllAppsButtonRank(rank);
3845 }
3846 return false;
3847 }
3848
Winson Chunga2413752012-04-03 14:22:34 -07003849 private boolean canRunNewAppsAnimation() {
3850 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3851 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3852 }
3853
Winson Chungc9168342013-06-26 14:54:55 -07003854 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3855 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3856 PropertyValuesHolder.ofFloat("alpha", 1f),
3857 PropertyValuesHolder.ofFloat("scaleX", 1f),
3858 PropertyValuesHolder.ofFloat("scaleY", 1f));
3859 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3860 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3861 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3862 return bounceAnim;
3863 }
3864
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003865 @Override
3866 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003867 boolean searchVisible = updateGlobalSearchIcon();
3868 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003869 if (mSearchDropTargetBar != null) {
3870 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3871 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003872 }
3873
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003874 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003875 * Add the icons for all apps.
3876 *
3877 * Implementation of the method from LauncherModel.Callbacks.
3878 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003879 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003880 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3881 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3882 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3883 getHotseat().addAllAppsFolder(mIconCache, apps,
3884 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3885 }
3886 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003887 }
Winson Chungc58497e2013-09-03 17:48:37 -07003888 } else {
3889 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3890 mAppsCustomizeContent != null) {
3891 mAppsCustomizeContent.setApps(apps);
3892 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003893 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003894 }
3895
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003896 @Override
3897 public boolean shouldShowApp(ResolveInfo app) {
3898 return true;
3899 }
3900
Joe Onorato9c1289c2009-08-17 11:03:03 -04003901 /**
3902 * A package was updated.
3903 *
3904 * Implementation of the method from LauncherModel.Callbacks.
3905 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003906 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003907 Runnable r = new Runnable() {
3908 public void run() {
3909 bindAppsUpdated(apps);
3910 }
3911 };
3912 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003913 return;
3914 }
3915
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003916 if (mWorkspace != null) {
3917 mWorkspace.updateShortcuts(apps);
3918 }
Winson Chungc58497e2013-09-03 17:48:37 -07003919
3920 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3921 mAppsCustomizeContent != null) {
3922 mAppsCustomizeContent.updateApps(apps);
3923 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003924 }
3925
3926 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003927 * A package was uninstalled. We take both the super set of packageNames
3928 * in addition to specific applications to remove, the reason being that
3929 * this can be called when a package is updated as well. In that scenario,
3930 * we only remove specific components from the workspace, where as
3931 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003932 *
3933 * Implementation of the method from LauncherModel.Callbacks.
3934 */
Winson Chung83892cc2013-05-01 16:53:33 -07003935 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003936 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003937 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003938 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003939 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003940 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003941 }
Winson Chungd64d1762013-08-20 14:37:16 -07003942 };
3943 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003944 return;
3945 }
3946
Winson Chung64359a52013-07-08 17:17:08 -07003947 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003948 mWorkspace.removeItemsByPackageName(packageNames);
3949 } else {
3950 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003951 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003952
Winson Chunga1820962011-10-03 16:31:06 -07003953 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003954 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003955
3956 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3957 mAppsCustomizeContent != null) {
3958 mAppsCustomizeContent.removeApps(appInfos);
3959 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003960 }
Joe Onoratobe386092009-11-17 17:32:16 -08003961
3962 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003963 * A number of packages were updated.
3964 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003965 private ArrayList<Object> mWidgetsAndShortcuts;
3966 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003967 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003968 bindPackagesUpdated(mWidgetsAndShortcuts);
3969 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003970 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003971 };
3972
3973 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3974 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3975 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003976 return;
3977 }
3978
Winson Chung64359a52013-07-08 17:17:08 -07003979 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003980 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3981 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003982 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003983 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003984 }
3985
Winson Chung400438b2011-01-16 17:53:48 -08003986 private int mapConfigurationOriActivityInfoOri(int configOri) {
3987 final Display d = getWindowManager().getDefaultDisplay();
3988 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3989 switch (d.getRotation()) {
3990 case Surface.ROTATION_0:
3991 case Surface.ROTATION_180:
3992 // We are currently in the same basic orientation as the natural orientation
3993 naturalOri = configOri;
3994 break;
3995 case Surface.ROTATION_90:
3996 case Surface.ROTATION_270:
3997 // We are currently in the other basic orientation to the natural orientation
3998 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3999 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4000 break;
4001 }
4002
4003 int[] oriMap = {
4004 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4005 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4006 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4007 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4008 };
4009 // Since the map starts at portrait, we need to offset if this device's natural orientation
4010 // is landscape.
4011 int indexOffset = 0;
4012 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4013 indexOffset = 1;
4014 }
4015 return oriMap[(d.getRotation() + indexOffset) % 4];
4016 }
Adam Cohen446e9402011-09-15 18:21:21 -07004017
Winson Chung4b919f82012-05-01 10:44:08 -07004018 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004019 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004020 getResources().getBoolean(R.bool.allow_rotation);
4021 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004022 }
Winson Chung4b919f82012-05-01 10:44:08 -07004023 public void lockScreenOrientation() {
4024 if (isRotationEnabled()) {
4025 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4026 .getConfiguration().orientation));
4027 }
4028 }
4029 public void unlockScreenOrientation(boolean immediate) {
4030 if (isRotationEnabled()) {
4031 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004032 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004033 } else {
4034 mHandler.postDelayed(new Runnable() {
4035 public void run() {
4036 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4037 }
4038 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004039 }
Winson Chung4b919f82012-05-01 10:44:08 -07004040 }
Winson Chung400438b2011-01-16 17:53:48 -08004041 }
4042
Winson Chung82f55532011-08-09 14:14:23 -07004043 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004044 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004045 if (DISABLE_CLINGS) {
4046 return false;
4047 }
4048
Brett Chabot2a9e2282011-08-23 15:03:13 -07004049 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004050 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004051
Michael Jurkae233a8b2013-03-19 13:49:20 +01004052 // Restricted secondary users (child mode) will potentially have very few apps
4053 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004054// boolean supportsLimitedUsers =
4055// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4056// Account[] accounts = AccountManager.get(this).getAccounts();
4057// if (supportsLimitedUsers && accounts.length == 0) {
4058// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4059// Bundle restrictions = um.getUserRestrictions();
4060// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4061// return false;
4062// }
4063// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004064 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004065 }
Michael Jurka22143132012-10-04 17:42:38 +02004066
Winson Chungaf40f202013-09-18 18:26:31 -07004067 private Cling initCling(int clingId, int[] positionData, boolean animate,
4068 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004069 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004070 if (cling != null) {
4071 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004072 cling.show(animate, SHOW_CLING_DURATION);
4073
4074 if (dimNavBarVisibilty) {
4075 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4076 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004077 }
4078 }
4079 return cling;
4080 }
Michael Jurka22143132012-10-04 17:42:38 +02004081
Winson Chungaf40f202013-09-18 18:26:31 -07004082 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4083 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004084 // To catch cases where siblings of top-level views are made invisible, just check whether
4085 // the cling is directly set to GONE before dismissing it.
4086 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004087 final Runnable cleanUpClingCb = new Runnable() {
4088 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004089 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004090 /*
Winson Chung46353de2012-02-16 14:05:10 -08004091 // We should update the shared preferences on a background thread
4092 new Thread("dismissClingThread") {
4093 public void run() {
4094 SharedPreferences.Editor editor = mSharedPrefs.edit();
4095 editor.putBoolean(flag, true);
4096 editor.commit();
4097 }
4098 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004099 */
4100 if (postAnimationCb != null) {
4101 postAnimationCb.run();
4102 }
4103 }
4104 };
4105 if (duration <= 0) {
4106 cleanUpClingCb.run();
4107 } else {
4108 cling.hide(duration, cleanUpClingCb);
4109 }
Michael Jurka22143132012-10-04 17:42:38 +02004110 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004111
4112 if (restoreNavBarVisibilty) {
4113 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4114 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4115 }
Winson Chung82f55532011-08-09 14:14:23 -07004116 }
4117 }
Michael Jurka22143132012-10-04 17:42:38 +02004118
Winson Chung9d9d74f2011-09-19 11:49:12 -07004119 private void removeCling(int id) {
4120 final View cling = findViewById(id);
4121 if (cling != null) {
4122 final ViewGroup parent = (ViewGroup) cling.getParent();
4123 parent.post(new Runnable() {
4124 @Override
4125 public void run() {
4126 parent.removeView(cling);
4127 }
4128 });
Michael Jurka22143132012-10-04 17:42:38 +02004129 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004130 }
4131 }
Michael Jurka974c3862012-05-22 22:00:31 -07004132
4133 private boolean skipCustomClingIfNoAccounts() {
4134 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4135 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4136 if (customCling) {
4137 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004138 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004139 Account[] accounts = am.getAccountsByType("com.google");
4140 return accounts.length == 0;
4141 }
4142 return false;
4143 }
4144
Winson Chungaf40f202013-09-18 18:26:31 -07004145 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004146 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004147 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004148 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004149 // If we're not using the default workspace layout, replace workspace cling
4150 // with a custom workspace cling (usually specified in an overlay)
4151 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004152 if (!DISABLE_CUSTOM_CLINGS) {
4153 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4154 getResources().getBoolean(R.bool.config_useCustomClings)) {
4155 // Use a custom cling
4156 View cling = findViewById(R.id.workspace_cling);
4157 ViewGroup clingParent = (ViewGroup) cling.getParent();
4158 int clingIndex = clingParent.indexOfChild(cling);
4159 clingParent.removeViewAt(clingIndex);
4160 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4161 clingParent.addView(customCling, clingIndex);
4162 customCling.setId(R.id.workspace_cling);
4163 }
4164 }
4165 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4166 if (cling != null) {
4167 String sbHintStr = getFirstRunClingSearchBarHint();
4168 String ccHintStr = getFirstRunCustomContentHint();
4169 if (!sbHintStr.isEmpty()) {
4170 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4171 sbHint.setText(sbHintStr);
4172 sbHint.setVisibility(View.VISIBLE);
4173 }
4174 if (!ccHintStr.isEmpty()) {
4175 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4176 ccHint.setText(ccHintStr);
4177 ccHint.setVisibility(View.VISIBLE);
4178 }
Michael Jurka45355c42012-10-08 13:21:35 +02004179 }
Winson Chungaf40f202013-09-18 18:26:31 -07004180 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004181 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004182 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004183 }
4184 }
Winson Chungaf40f202013-09-18 18:26:31 -07004185
Winson Chunge6eabff2013-09-24 11:01:23 -07004186 protected String getFirstRunClingSearchBarHint() {
4187 return "";
4188 }
4189 protected String getFirstRunCustomContentHint() {
4190 return "";
4191 }
4192
Winson Chungaf40f202013-09-18 18:26:31 -07004193 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004194 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004195 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004196 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4197 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004198 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004199 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004200 }
4201 }
4202 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004203 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004204 if (isClingsEnabled() &&
4205 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004206 Cling cling = initCling(R.id.folder_cling, null, true, true);
4207 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004208 } else {
4209 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004210 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004211 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004212 }
Michael Jurka104c4562013-07-08 18:03:46 -07004213 protected SharedPreferences getSharedPrefs() {
4214 return mSharedPrefs;
4215 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004216 public boolean isFolderClingVisible() {
4217 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004218 if (cling != null) {
4219 return cling.getVisibility() == View.VISIBLE;
4220 }
4221 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004222 }
Winson Chungaf40f202013-09-18 18:26:31 -07004223 public void dismissFirstRunCling(View v) {
4224 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4225 Runnable cb = new Runnable() {
4226 public void run() {
4227 // Show the workspace cling next
4228 showFirstRunWorkspaceCling();
4229 }
4230 };
4231 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4232 DISMISS_CLING_DURATION, false);
4233 }
Winson Chung82f55532011-08-09 14:14:23 -07004234 public void dismissWorkspaceCling(View v) {
4235 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004236 Runnable cb = null;
4237 if (v == null) {
4238 cb = new Runnable() {
4239 public void run() {
4240 mWorkspace.enterOverviewMode();
4241 }
4242 };
4243 }
4244 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4245 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004246 }
4247 public void dismissFolderCling(View v) {
4248 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004249 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4250 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004251 }
4252
Winson Chung80baf5a2010-08-09 16:03:15 -07004253 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004254 * Prints out out state for debugging.
4255 */
4256 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004257 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004258 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004259 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4260 Log.d(TAG, "mRestoring=" + mRestoring);
4261 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4262 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004263 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004264 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004265
Winson Chung785d2eb2011-04-14 16:08:02 -07004266 if (mAppsCustomizeContent != null) {
4267 mAppsCustomizeContent.dumpState();
4268 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004269 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004270 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004271
4272 @Override
4273 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4274 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004275 synchronized (sDumpLogs) {
4276 writer.println(" ");
4277 writer.println("Debug logs: ");
4278 for (int i = 0; i < sDumpLogs.size(); i++) {
4279 writer.println(" " + sDumpLogs.get(i));
4280 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004281 }
4282 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004283
4284 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004285 if (DEBUG_DUMP_LOG) {
4286 synchronized (sDumpLogs) {
4287 Log.d(TAG, "");
4288 Log.d(TAG, "*********************");
4289 Log.d(TAG, "Launcher debug logs: ");
4290 for (int i = 0; i < sDumpLogs.size(); i++) {
4291 Log.d(TAG, " " + sDumpLogs.get(i));
4292 }
4293 Log.d(TAG, "*********************");
4294 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004295 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004296 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004297 }
4298
4299 public static void addDumpLog(String tag, String log, boolean debugLog) {
4300 if (debugLog) {
4301 Log.d(tag, log);
4302 }
Winson Chungede41292013-09-19 16:27:36 -07004303 if (DEBUG_DUMP_LOG) {
4304 sDateStamp.setTime(System.currentTimeMillis());
4305 synchronized (sDumpLogs) {
4306 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004307 }
Winson Chungede41292013-09-19 16:27:36 -07004308 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004309 }
4310
Winson Chungede41292013-09-19 16:27:36 -07004311 public void dumpLogsToLocalData() {
4312 if (DEBUG_DUMP_LOG) {
4313 new Thread("DumpLogsToLocalData") {
4314 @Override
4315 public void run() {
4316 boolean success = false;
4317 sDateStamp.setTime(sRunStart);
4318 String FILENAME = sDateStamp.getMonth() + "-"
4319 + sDateStamp.getDay() + "_"
4320 + sDateStamp.getHours() + "-"
4321 + sDateStamp.getMinutes() + "_"
4322 + sDateStamp.getSeconds() + ".txt";
4323
4324 FileOutputStream fos = null;
4325 File outFile = null;
4326 try {
4327 outFile = new File(getFilesDir(), FILENAME);
4328 outFile.createNewFile();
4329 fos = new FileOutputStream(outFile);
4330 } catch (Exception e) {
4331 e.printStackTrace();
4332 }
4333 if (fos != null) {
4334 PrintWriter writer = new PrintWriter(fos);
4335
4336 writer.println(" ");
4337 writer.println("Debug logs: ");
4338 synchronized (sDumpLogs) {
4339 for (int i = 0; i < sDumpLogs.size(); i++) {
4340 writer.println(" " + sDumpLogs.get(i));
4341 }
4342 }
4343 writer.close();
4344 }
4345 try {
4346 if (fos != null) {
4347 fos.close();
4348 success = true;
4349 }
4350 } catch (IOException e) {
4351 e.printStackTrace();
4352 }
4353 }
4354 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004355 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004356 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004357}
Michael Jurka2763be32011-02-24 11:19:57 -08004358
Michael Jurkaabded662011-03-04 12:06:57 -08004359interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004360 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004361 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004362 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004363 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004364 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004365}