blob: 89d4cb379f87db27162ef6f6ddfe689352fb1dc6 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700205 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700206 private static final int DISMISS_CLING_DURATION = 250;
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
212 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700213 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700214
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800215 private final BroadcastReceiver mCloseSystemDialogsReceiver
216 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800217 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private LayoutInflater mInflater;
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700222 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800223 private DragLayer mDragLayer;
224 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700225 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700227 private AppWidgetManager mAppWidgetManager;
228 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700229
Michael Jurkac9d95c52011-08-29 14:03:34 -0700230 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700231 private AppWidgetProviderInfo mPendingAddWidgetInfo;
232
Michael Jurka0280c3b2010-09-17 15:00:07 -0700233 private int[] mTmpAddItemCellCoordinates = new int[2];
234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private FolderInfo mFolderInfo;
236
Winson Chung3d503fb2011-07-13 17:25:49 -0700237 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700238 private View mOverviewPanel;
239
Michael Jurka838a4ca2011-02-07 13:33:06 -0800240 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700241
Winson Chungc51db6a2011-10-05 11:44:49 -0700242 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700243 private AppsCustomizeTabHost mAppsCustomizeTabHost;
244 private AppsCustomizePagedView mAppsCustomizeContent;
245 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100246 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700249 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
250 // scroll issues (because the workspace may not have been measured yet) and extra work.
251 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
252 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
254 private SpannableStringBuilder mDefaultKeySsb = null;
255
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256 private boolean mWorkspaceLoading = true;
257
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800258 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private boolean mRestoring;
260 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700261 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262
Michael Jurka1e2f4652013-07-08 18:03:46 -0700263 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700264 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
265
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // Keep track of whether the user has left launcher
267 private static boolean sPausedFromUserAction = false;
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private Bundle mSavedInstanceState;
270
Joe Onorato9c1289c2009-08-17 11:03:03 -0400271 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800272 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800273 private boolean mUserPresent = true;
274 private boolean mVisible = false;
275 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700276 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static LocaleConfiguration sLocaleConfiguration = null;
279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700282 private Intent mAppMarketIntent = null;
283
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Craig Mautner360310b2012-10-26 15:13:08 -0700302 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700303
Adam Cohen1462de32012-07-24 22:34:36 -0700304 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
305
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700306 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700307 static Date sDateStamp = new Date();
308 static DateFormat sDateFormat =
309 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
310 static long sRunStart = System.currentTimeMillis();
311 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700312
Winson Chung46353de2012-02-16 14:05:10 -0800313 // We only want to get the SharedPreferences once since it does an FS stat each time we get
314 // it from the context.
315 private SharedPreferences mSharedPrefs;
316
Adam Cohene25af792013-06-06 23:08:25 -0700317 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
318
Winson Chungf0c6ae02012-03-21 16:10:31 -0700319 // Holds the page that we need to animate to, and the icon views that we need to animate up
320 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700321 private ImageView mFolderIconImageView;
322 private Bitmap mFolderIconBitmap;
323 private Canvas mFolderIconCanvas;
324 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700325
Michael Jurkaddd62e92011-02-16 17:49:14 -0800326 private BubbleTextView mWaitingForResume;
327
Michael Jurka22143132012-10-04 17:42:38 +0200328 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
329 = new HideFromAccessibilityHelper();
330
Michael Jurkac1f5d262011-09-30 19:32:27 -0700331 private Runnable mBuildLayersRunnable = new Runnable() {
332 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700333 if (mWorkspace != null) {
334 mWorkspace.buildPageHardwareLayers();
335 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 }
337 };
338
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800339 private static ArrayList<PendingAddArguments> sPendingAddList
340 = new ArrayList<PendingAddArguments>();
341
Michael Jurka0a457bf2012-11-19 14:05:05 -0800342 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static class PendingAddArguments {
345 int requestCode;
346 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700347 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700348 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 int cellX;
350 int cellY;
351 }
352
Daniel Sandlerff02d492013-08-05 02:12:05 -0400353 private Stats mStats;
354
Michael Jurka0a457bf2012-11-19 14:05:05 -0800355 private static boolean isPropertyEnabled(String propertyName) {
356 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700357 }
358
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 @Override
360 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700361 if (DEBUG_STRICT_MODE) {
362 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
363 .detectDiskReads()
364 .detectDiskWrites()
365 .detectNetwork() // or .detectAll() for all detectable problems
366 .penaltyLog()
367 .build());
368 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
369 .detectLeakedSqlLiteObjects()
370 .detectLeakedClosableObjects()
371 .penaltyLog()
372 .penaltyDeath()
373 .build());
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400377
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400378 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400379 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700380
381 // Determine the dynamic grid properties
382 Point smallestSize = new Point();
383 Point largestSize = new Point();
384 Point realSize = new Point();
385 Display display = getWindowManager().getDefaultDisplay();
386 display.getCurrentSizeRange(smallestSize, largestSize);
387 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700388 DisplayMetrics dm = new DisplayMetrics();
389 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700390 // Lazy-initialize the dynamic grid
391 DeviceProfile grid = app.initDynamicGrid(this,
392 Math.min(smallestSize.x, smallestSize.y),
393 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700394 realSize.x, realSize.y,
395 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700396
397 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400398 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700399 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800400 mModel = app.setLauncher(this);
401 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400402 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700404
Daniel Sandlerff02d492013-08-05 02:12:05 -0400405 mStats = new Stats(this);
406
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700407 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700408 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
409 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700410
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700411 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
412 // this also ensures that any synchronous binding below doesn't re-trigger another
413 // LauncherModel load.
414 mPaused = false;
415
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200417 android.os.Debug.startMethodTracing(
418 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 }
420
421 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 setContentView(R.layout.launcher);
423 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100424 grid.layout(this);
Winson Chung7d7541e2011-09-16 20:14:36 -0700425 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800427 registerContentObservers();
428
Joe Onorato7c312c12009-08-13 21:36:53 -0700429 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700430
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 mSavedState = savedInstanceState;
432 restoreState(mSavedState);
433
Winson Chunga12a2502010-12-20 14:41:35 -0800434 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700435 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200436 mAppsCustomizeContent.onPackagesUpdated(
437 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700438 }
Winson Chunga12a2502010-12-20 14:41:35 -0800439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
441 android.os.Debug.stopMethodTracing();
442 }
443
444 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700445 if (sPausedFromUserAction) {
446 // If the user leaves launcher, then we should just load items asynchronously when
447 // they return.
448 mModel.startLoader(true, -1);
449 } else {
450 // We only load the page synchronously if the user rotates (or triggers a
451 // configuration change) while launcher is in the foreground
452 mModel.startLoader(true, mWorkspace.getCurrentPage());
453 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 }
455
456 // For handling default keys
457 mDefaultKeySsb = new SpannableStringBuilder();
458 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800459
460 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
461 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800462
Adam Cohenf9426d52012-06-04 17:26:21 -0700463 updateGlobalIcons();
464
465 // On large interfaces, we want the screen to auto-rotate based on the current orientation
466 unlockScreenOrientation(true);
467 }
468
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 protected void onUserLeaveHint() {
470 super.onUserLeaveHint();
471 sPausedFromUserAction = true;
472 }
473
Winson Chung98ca0f72013-07-29 12:58:51 -0700474 /** To be overriden by subclasses to hint to Launcher that we have custom content */
475 protected boolean hasCustomContentToLeft() {
476 return false;
477 }
478
Dave Hawkeya8881582013-09-17 15:55:33 -0600479 /**
480 * To be overridden by subclasses to create the custom content and call
481 * {@link #addToCustomContentPage}. This will only be invoked if
482 * {@link #hasCustomContentToLeft()} is {@code true}.
483 */
484 protected void addCustomContentToLeft() {
485 }
486
487 /**
488 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
489 * ensure the custom content page is added or removed if necessary.
490 */
491 protected void invalidateHasCustomContentToLeft() {
492 if (mWorkspace.getScreenOrder().isEmpty()) {
493 // Not bound yet, wait for bindScreens to be called.
494 return;
495 }
496
497 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
498 // Create the custom content page and call the subclass to populate it.
499 mWorkspace.createCustomContentPage();
500 addCustomContentToLeft();
501 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
502 mWorkspace.removeCustomContentPage();
503 }
504 }
505
Adam Cohenf9426d52012-06-04 17:26:21 -0700506 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700507 boolean searchVisible = false;
508 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800509 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700510 int coi = getCurrentOrientationIndexForGlobalIcons();
511 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
512 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700513 updateAppMarketIcon();
514 searchVisible = updateGlobalSearchIcon();
515 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700516 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700517 if (sGlobalSearchIcon[coi] != null) {
518 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700519 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700520 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700521 if (sVoiceSearchIcon[coi] != null) {
522 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700523 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700524 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700525 if (sAppMarketIcon[coi] != null) {
526 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800527 }
Winson Chungadf0c182012-08-23 14:59:07 -0700528 if (mSearchDropTargetBar != null) {
529 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
530 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 }
Romain Guycbb89e42009-06-08 15:52:54 -0700532
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800533 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700534 if (sLocaleConfiguration == null) {
535 new AsyncTask<Void, Void, LocaleConfiguration>() {
536 @Override
537 protected LocaleConfiguration doInBackground(Void... unused) {
538 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
539 readConfiguration(Launcher.this, localeConfiguration);
540 return localeConfiguration;
541 }
542
543 @Override
544 protected void onPostExecute(LocaleConfiguration result) {
545 sLocaleConfiguration = result;
546 checkForLocaleChange(); // recursive, but now with a locale configuration
547 }
548 }.execute();
549 return;
550 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700551
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800552 final Configuration configuration = getResources().getConfiguration();
553
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700554 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 final String locale = configuration.locale.toString();
556
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700557 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final int mcc = configuration.mcc;
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final int mnc = configuration.mnc;
562
Romain Guy84f296c2009-11-04 15:00:44 -0800563 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564
Romain Guy84f296c2009-11-04 15:00:44 -0800565 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700566 sLocaleConfiguration.locale = locale;
567 sLocaleConfiguration.mcc = mcc;
568 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700569
Joe Onorato0589f0f2010-02-08 13:44:00 -0800570 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700571
572 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
573 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700574 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700575 public void run() {
576 writeConfiguration(Launcher.this, localeConfiguration);
577 }
578 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700579 }
580 }
581
582 private static class LocaleConfiguration {
583 public String locale;
584 public int mcc = -1;
585 public int mnc = -1;
586 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700587
Romain Guy98d01652009-06-30 16:21:04 -0700588 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
589 DataInputStream in = null;
590 try {
591 in = new DataInputStream(context.openFileInput(PREFERENCES));
592 configuration.locale = in.readUTF();
593 configuration.mcc = in.readInt();
594 configuration.mnc = in.readInt();
595 } catch (FileNotFoundException e) {
596 // Ignore
597 } catch (IOException e) {
598 // Ignore
599 } finally {
600 if (in != null) {
601 try {
602 in.close();
603 } catch (IOException e) {
604 // Ignore
605 }
606 }
607 }
608 }
609
610 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
611 DataOutputStream out = null;
612 try {
613 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
614 out.writeUTF(configuration.locale);
615 out.writeInt(configuration.mcc);
616 out.writeInt(configuration.mnc);
617 out.flush();
618 } catch (FileNotFoundException e) {
619 // Ignore
620 } catch (IOException e) {
621 //noinspection ResultOfMethodCallIgnored
622 context.getFileStreamPath(PREFERENCES).delete();
623 } finally {
624 if (out != null) {
625 try {
626 out.close();
627 } catch (IOException e) {
628 // Ignore
629 }
630 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800631 }
632 }
633
Bjorn Bringertc459e522013-06-07 19:36:01 +0100634 public LayoutInflater getInflater() {
635 return mInflater;
636 }
637
Adam Cohen716b51e2011-06-30 12:09:54 -0700638 public DragLayer getDragLayer() {
639 return mDragLayer;
640 }
641
Winson Chung36a62fe2012-05-06 18:04:42 -0700642 boolean isDraggingEnabled() {
643 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
644 // that is subsequently removed from the workspace in startBinding().
645 return !mModel.isLoadingWorkspace();
646 }
647
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 static int getScreen() {
649 synchronized (sLock) {
650 return sScreen;
651 }
652 }
653
654 static void setScreen(int screen) {
655 synchronized (sLock) {
656 sScreen = screen;
657 }
658 }
659
Winson Chung557d6ed2011-07-08 15:34:52 -0700660 /**
661 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
662 * a configuration step, this allows the proper animations to run after other transitions.
663 */
664 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700665 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800666 switch (args.requestCode) {
667 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700668 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700669 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800670 break;
671 case REQUEST_PICK_SHORTCUT:
672 processShortcut(args.intent);
673 break;
674 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700675 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700676 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700677 result = true;
678 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800679 case REQUEST_CREATE_APPWIDGET:
680 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700681 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700682 result = true;
683 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800684 }
Michael Jurka27614d22012-04-02 06:40:22 -0700685 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
686 // if you turned the screen off and then back while in All Apps, Launcher would not
687 // return to the workspace. Clearing mAddInfo.container here fixes this issue
688 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800690 }
691
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700693 protected void onActivityResult(
694 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700695 // Reset the startActivity waiting flag
696 mWaitingForResult = false;
697
Michael Jurka8b805b12012-04-18 14:23:14 -0700698 if (requestCode == REQUEST_BIND_APPWIDGET) {
699 int appWidgetId = data != null ?
700 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
701 if (resultCode == RESULT_CANCELED) {
702 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
703 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700704 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 }
706 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200707 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
708 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
709 mWorkspace.exitOverviewMode(false);
710 }
711 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200713
Winson Chung557d6ed2011-07-08 15:34:52 -0700714 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800715 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
716 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700717
Adam Cohened66b2b2012-01-23 17:28:51 -0800718 // We have special handling for widgets
719 if (isWidgetDrop) {
720 int appWidgetId = data != null ?
721 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700722 if (appWidgetId < 0) {
723 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
724 "widget configuration activity.");
725 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
726 } else {
727 completeTwoStageWidgetDrop(resultCode, appWidgetId);
728 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800729 return;
730 }
731
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 // The pattern used here is that a user PICKs a specific application,
733 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700734
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
736 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700737 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 final PendingAddArguments args = new PendingAddArguments();
739 args.requestCode = requestCode;
740 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700741 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700742 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700743 args.cellX = mPendingAddInfo.cellX;
744 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 if (isWorkspaceLocked()) {
746 sPendingAddList.add(args);
747 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700748 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800751 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700752 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800753 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
754 null);
755 }
756
757 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700758 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700759 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800760 Runnable onCompleteRunnable = null;
761 int animationType = 0;
762
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700763 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800764 if (resultCode == RESULT_OK) {
765 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
766 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700767 mPendingAddWidgetInfo);
768 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800769 onCompleteRunnable = new Runnable() {
770 @Override
771 public void run() {
772 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700773 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800774 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
775 null);
776 }
777 };
778 } else if (resultCode == RESULT_CANCELED) {
779 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
780 onCompleteRunnable = new Runnable() {
781 @Override
782 public void run() {
783 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
784 null);
785 }
786 };
787 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700788 if (mDragLayer.getAnimatedView() != null) {
789 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
790 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
791 animationType, boundWidget, true);
792 } else {
793 // The animated view may be null in the case of a rotation during widget configuration
794 onCompleteRunnable.run();
795 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 }
797
798 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700799 protected void onStop() {
800 super.onStop();
801 FirstFrameAnimatorHelper.setIsVisible(false);
802 }
803
804 @Override
805 protected void onStart() {
806 super.onStart();
807 FirstFrameAnimatorHelper.setIsVisible(true);
808 }
809
810 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200812 long startTime = 0;
813 if (DEBUG_RESUME_TIME) {
814 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400815 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700818
Winson Chung4a2afa32012-07-19 14:53:05 -0700819 // Restore the previous launcher state
820 if (mOnResumeState == State.WORKSPACE) {
821 showWorkspace(false);
822 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700823 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700824 }
825 mOnResumeState = State.NONE;
826
Craig Mautner360310b2012-10-26 15:13:08 -0700827 // Background was set to gradient in onPause(), restore to black if in all apps.
828 setWorkspaceBackground(mState == State.WORKSPACE);
829
Winson Chungde0fb8f2012-05-08 14:37:08 -0700830 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700831 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700832
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800833 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700834 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700835 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400836 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700837 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400838 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700839 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700841 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200842 // We might have postponed some bind calls until onResume (see waitUntilResume) --
843 // execute them here
844 long startTimeCallbacks = 0;
845 if (DEBUG_RESUME_TIME) {
846 startTimeCallbacks = System.currentTimeMillis();
847 }
848
849 if (mAppsCustomizeContent != null) {
850 mAppsCustomizeContent.setBulkBind(true);
851 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700852 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
853 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200854 }
855 if (mAppsCustomizeContent != null) {
856 mAppsCustomizeContent.setBulkBind(false);
857 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700858 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200859 if (DEBUG_RESUME_TIME) {
860 Log.d(TAG, "Time spent processing callbacks in onResume: " +
861 (System.currentTimeMillis() - startTimeCallbacks));
862 }
Michael Jurka447bf842013-05-15 14:52:15 +0200863 }
Michael Jurka54554252013-08-01 12:52:23 +0200864 if (mOnResumeCallbacks.size() > 0) {
865 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
866 mOnResumeCallbacks.get(i).run();
867 }
868 mOnResumeCallbacks.clear();
869 }
Winson Chunge4e50662012-01-23 14:45:13 -0800870
871 // Reset the pressed state of icons that were locked in the press state while activities
872 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800873 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800874 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800875 mWaitingForResume.setStayPressed(false);
876 }
Winson Chunge4e50662012-01-23 14:45:13 -0800877 if (mAppsCustomizeContent != null) {
878 // Resets the previous all apps icon press state
879 mAppsCustomizeContent.resetDrawableState();
880 }
Adam Cohen06dff352012-06-01 17:17:08 -0700881 // It is possible that widgets can receive updates while launcher is not in the foreground.
882 // Consequently, the widgets will be inflated in the orientation of the foreground activity
883 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
884 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700885 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700886
887 // Again, as with the above scenario, it's possible that one or more of the global icons
888 // were updated in the wrong orientation.
889 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200890 if (DEBUG_RESUME_TIME) {
891 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
892 }
Adam Cohen06dff352012-06-01 17:17:08 -0700893 }
894
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800895 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700896 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700897 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
898 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
899 // when Launcher resumes and we are still in AllApps.
900 updateWallpaperVisibility(true);
901
Winson Chung997a9232013-07-24 15:33:46 -0700902 // Ensure that items added to Launcher are queued until Launcher returns
903 InstallShortcutReceiver.enableInstallQueue();
904
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700905 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700906 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800907 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700908 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700909 }
Romain Guycbb89e42009-06-08 15:52:54 -0700910
Adam Cohen66a01fd2013-06-11 12:48:00 -0700911 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600912 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
913 addCustomContentToLeft();
914 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700915 }
916
Adam Cohenbffe7452013-07-22 18:21:45 -0700917 QSBScroller mQsbScroller = new QSBScroller() {
918 int scrollY = 0;
919
920 @Override
921 public void setScrollY(int scroll) {
922 scrollY = scroll;
923
924 if (mWorkspace.isOnOrMovingToCustomContent()) {
925 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100926 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700927 }
928 }
929 };
930
931 public void resetQSBScroll() {
932 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100933 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700934 }
935
936 public interface CustomContentCallbacks {
937 // Custom content is completely shown
938 public void onShow();
939
940 // Custom content is completely hidden
941 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700942
943 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
944 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700945 }
946
Adam Cohen30bacb22013-08-29 14:25:25 -0700947 protected void startSettings() {
948 }
949
Adam Cohenbffe7452013-07-22 18:21:45 -0700950 public interface QSBScroller {
951 public void setScrollY(int scrollY);
952 }
953
Adam Cohen66a01fd2013-06-11 12:48:00 -0700954 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700955 public QSBScroller addToCustomContentPage(View customContent) {
956 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700957 }
958
Winson Chung98ca0f72013-07-29 12:58:51 -0700959 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700960 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700961 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700962 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700963 }
964
Adam Cohenedb40762013-07-18 16:45:45 -0700965 // The custom content needs to offset its content to account for the QSB
966 public int getTopOffsetForCustomContent() {
967 return mWorkspace.getPaddingTop();
968 }
969
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700970 @Override
971 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400972 // Flag the loader to stop early before switching
973 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700974 if (mAppsCustomizeContent != null) {
975 mAppsCustomizeContent.surrender();
976 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800977 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700978 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700979
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800980 // We can't hide the IME if it was forced open. So don't bother
981 /*
982 @Override
983 public void onWindowFocusChanged(boolean hasFocus) {
984 super.onWindowFocusChanged(hasFocus);
985
986 if (hasFocus) {
987 final InputMethodManager inputManager = (InputMethodManager)
988 getSystemService(Context.INPUT_METHOD_SERVICE);
989 WindowManager.LayoutParams lp = getWindow().getAttributes();
990 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
991 android.os.Handler()) {
992 protected void onReceiveResult(int resultCode, Bundle resultData) {
993 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
994 }
995 });
996 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
997 }
998 }
999 */
1000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 private boolean acceptFilter() {
1002 final InputMethodManager inputManager = (InputMethodManager)
1003 getSystemService(Context.INPUT_METHOD_SERVICE);
1004 return !inputManager.isFullscreenMode();
1005 }
1006
1007 @Override
1008 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001009 final int uniChar = event.getUnicodeChar();
1010 final boolean handled = super.onKeyDown(keyCode, event);
1011 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1012 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001013 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1014 keyCode, event);
1015 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001016 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001017 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001018 // showSearchDialog()
1019 // If there are multiple keystrokes before the search dialog takes focus,
1020 // onSearchRequested() will be called for every keystroke,
1021 // but it is idempotent, so it's fine.
1022 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 }
1024 }
1025
Joe Onorato8a9625e2010-01-28 15:55:35 -08001026 // Eat the long press event so the keyboard doesn't come up.
1027 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1028 return true;
1029 }
1030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 return handled;
1032 }
1033
Karl Rosaen138a0412009-04-23 19:00:21 -07001034 private String getTypedText() {
1035 return mDefaultKeySsb.toString();
1036 }
1037
1038 private void clearTypedText() {
1039 mDefaultKeySsb.clear();
1040 mDefaultKeySsb.clearSpans();
1041 Selection.setSelection(mDefaultKeySsb, 0);
1042 }
1043
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001045 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1046 * State
1047 */
1048 private static State intToState(int stateOrdinal) {
1049 State state = State.WORKSPACE;
1050 final State[] stateValues = State.values();
1051 for (int i = 0; i < stateValues.length; i++) {
1052 if (stateValues[i].ordinal() == stateOrdinal) {
1053 state = stateValues[i];
1054 break;
1055 }
1056 }
1057 return state;
1058 }
1059
1060 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 * Restores the previous state, if it exists.
1062 *
1063 * @param savedState The previous state.
1064 */
1065 private void restoreState(Bundle savedState) {
1066 if (savedState == null) {
1067 return;
1068 }
1069
Michael Jurka883f55b2010-10-21 15:47:14 -07001070 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001071 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001072 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001073 }
1074
Winson Chungf0c6ae02012-03-21 16:10:31 -07001075 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001077 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 }
1079
Winson Chung3d503fb2011-07-13 17:25:49 -07001080 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001081 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001082
Winson Chung3d503fb2011-07-13 17:25:49 -07001083 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1084 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001085 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001086 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1087 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001088 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1089 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1090 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001091 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001092 mRestoring = true;
1093 }
1094
1095 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1096 if (renameFolder) {
1097 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001098 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 mRestoring = true;
1100 }
Winson Chunga12a2502010-12-20 14:41:35 -08001101
Winson Chung785d2eb2011-04-14 16:08:02 -07001102 // Restore the AppsCustomize tab
1103 if (mAppsCustomizeTabHost != null) {
1104 String curTab = savedState.getString("apps_customize_currentTab");
1105 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001106 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001107 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001108 mAppsCustomizeContent.loadAssociatedPages(
1109 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001110 }
1111
Winson Chung5afbf7b2011-07-25 11:53:08 -07001112 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1113 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 }
1116
1117 /**
1118 * Finds all the views we need and configure them properly.
1119 */
1120 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001121 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001122
Craig Mautner360310b2012-10-26 15:13:08 -07001123 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001124 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1125 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001126
John Spurlock77e1f472013-09-11 10:09:51 -04001127 mLauncherView.setSystemUiVisibility(
1128 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001129 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130
Winson Chung4c98d922011-05-31 16:50:48 -07001131 // Setup the drag layer
1132 mDragLayer.setup(this, dragController);
1133
Winson Chung3d503fb2011-07-13 17:25:49 -07001134 // Setup the hotseat
1135 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1136 if (mHotseat != null) {
1137 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001138 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001139 }
1140
Adam Cohenf358a4b2013-07-23 16:47:31 -07001141 mOverviewPanel = findViewById(R.id.overview_panel);
1142 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1143 @Override
1144 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001145 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001146 }
1147 });
1148 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1149 @Override
1150 public void onClick(View arg0) {
1151 startWallpaper();
1152 }
1153 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001154 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1155 @Override
1156 public void onClick(View arg0) {
1157 startSettings();
1158 }
1159 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001160 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001161
Winson Chung4c98d922011-05-31 16:50:48 -07001162 // Setup the workspace
1163 mWorkspace.setHapticFeedbackEnabled(false);
1164 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001165 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001166 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001167
Winson Chungf0ea4d32011-06-06 14:27:16 -07001168 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001169 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001170
Winson Chungf0ea4d32011-06-06 14:27:16 -07001171 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001172 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001173 mAppsCustomizeContent = (AppsCustomizePagedView)
1174 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1175 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001176
Winson Chung3d503fb2011-07-13 17:25:49 -07001177 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001178 dragController.setDragScoller(mWorkspace);
1179 dragController.setScrollView(mDragLayer);
1180 dragController.setMoveTarget(mWorkspace);
1181 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001182 if (mSearchDropTargetBar != null) {
1183 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001184 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001185
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001186 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001187 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001188 mWeightWatcher = new WeightWatcher(this);
1189 mWeightWatcher.setAlpha(0.5f);
1190 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001191 new FrameLayout.LayoutParams(
1192 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001193 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001194 Gravity.BOTTOM)
1195 );
Adam Cohen39a06042013-07-19 14:30:12 -07001196
1197 boolean show = shouldShowWeightWatcher();
1198 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001199 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 }
1201
1202 /**
1203 * Creates a view representing a shortcut.
1204 *
1205 * @param info The data structure describing the shortcut.
1206 *
1207 * @return A View inflated from R.layout.application.
1208 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001209 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001211 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 }
1213
1214 /**
1215 * Creates a view representing a shortcut inflated from the specified resource.
1216 *
1217 * @param layoutResId The id of the XML layout used to create the shortcut.
1218 * @param parent The group the shortcut belongs to.
1219 * @param info The data structure describing the shortcut.
1220 *
1221 * @return A View inflated from layoutResId.
1222 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001223 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001224 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1225 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001227 return favorite;
1228 }
1229
1230 /**
1231 * Add an application shortcut to the workspace.
1232 *
1233 * @param data The intent describing the application.
1234 * @param cellInfo The position on screen where to create the shortcut.
1235 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001236 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001237 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001238 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001239
Adam Cohenfbba09b2011-07-18 21:43:05 -07001240 // First we check if we already know the exact location where we want to add this item.
1241 if (cellX >= 0 && cellY >= 0) {
1242 cellXY[0] = cellX;
1243 cellXY[1] = cellY;
1244 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001245 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001246 return;
1247 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001249 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001250
Romain Guy73b979d2009-06-09 12:57:21 -07001251 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001252 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001254 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001255 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001256 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001257 } else {
1258 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
1260 }
Romain Guycbb89e42009-06-08 15:52:54 -07001261
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 /**
1263 * Add a shortcut to the workspace.
1264 *
1265 * @param data The intent describing the shortcut.
1266 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001268 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001269 int cellY) {
1270 int[] cellXY = mTmpAddItemCellCoordinates;
1271 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001272 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001273
Michael Jurkad3ef3062010-11-23 16:23:58 -08001274 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001275
Adam Cohen558baaf2011-08-15 15:22:57 -07001276 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001277 if (info == null) {
1278 return;
1279 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001280 final View view = createShortcut(info);
1281
Adam Cohenfbba09b2011-07-18 21:43:05 -07001282 // First we check if we already know the exact location where we want to add this item.
1283 if (cellX >= 0 && cellY >= 0) {
1284 cellXY[0] = cellX;
1285 cellXY[1] = cellY;
1286 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001287
1288 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001289 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001290 true, null,null)) {
1291 return;
1292 }
1293 DragObject dragObject = new DragObject();
1294 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001295 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1296 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001297 return;
1298 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001299 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001300 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001301 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001302 foundCellSpan = (result != null);
1303 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001304 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001305 }
1306
1307 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001308 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001309 return;
1310 }
1311
Adam Cohendcd297f2013-06-18 13:13:40 -07001312 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001313
1314 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001315 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001316 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 }
1318 }
1319
Adam Cohen2f093b62012-04-30 18:59:53 -07001320 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1321 int minHeight) {
1322 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001323 // We want to account for the extra amount of padding that we are adding to the widget
1324 // to ensure that it gets the full amount of space that it has requested
1325 int requiredWidth = minWidth + padding.left + padding.right;
1326 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001327 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001328 }
1329
Adam Cohen2f093b62012-04-30 18:59:53 -07001330 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1331 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001332 }
1333
Adam Cohen2f093b62012-04-30 18:59:53 -07001334 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1335 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001336 }
1337
Adam Cohen2f093b62012-04-30 18:59:53 -07001338 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1339 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001340 }
1341
Adam Cohen2f093b62012-04-30 18:59:53 -07001342 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1343 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001344 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001345 }
1346
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001348 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001350 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001351 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001353 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001354 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1355 if (appWidgetInfo == null) {
1356 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1357 }
Romain Guycbb89e42009-06-08 15:52:54 -07001358
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001359 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001360 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001361
Adam Cohen2f093b62012-04-30 18:59:53 -07001362 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1363 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001364
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001366 // We have saved the position to which the widget was dragged-- this really only matters
1367 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001368 int[] cellXY = mTmpAddItemCellCoordinates;
1369 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001370 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001371 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001372 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1373 cellXY[0] = mPendingAddInfo.cellX;
1374 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001375 spanXY[0] = mPendingAddInfo.spanX;
1376 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001377 foundCellSpan = true;
1378 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001379 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001381 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1382 spanXY[1], cellXY, finalSpan);
1383 spanXY[0] = finalSpan[0];
1384 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001385 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001386 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001387 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001388 }
1389
Michael Jurka0280c3b2010-09-17 15:00:07 -07001390 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001391 if (appWidgetId != -1) {
1392 // Deleting an app widget ID is a void call but writes to disk before returning
1393 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001394 new Thread("deleteAppWidgetId") {
1395 public void run() {
1396 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1397 }
1398 }.start();
1399 }
Winson Chung93eef082012-03-23 15:59:27 -07001400 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001401 return;
1402 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001404 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001405 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1406 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001407 launcherInfo.spanX = spanXY[0];
1408 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001409 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1410 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001411
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001413 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414
1415 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001416 if (hostView == null) {
1417 // Perform actual inflation because we're live
1418 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1419 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1420 } else {
1421 // The AppWidgetHostView has already been inflated and instantiated
1422 launcherInfo.hostView = hostView;
1423 }
Romain Guycbb89e42009-06-08 15:52:54 -07001424
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001425 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001426 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001427 launcherInfo.notifyWidgetSizeChanged(this);
1428
Adam Cohendcd297f2013-06-18 13:13:40 -07001429 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001430 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001431
1432 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001434 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 }
Romain Guycbb89e42009-06-08 15:52:54 -07001436
Adam Cohended9f8d2010-11-03 13:25:16 -07001437 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1438 @Override
1439 public void onReceive(Context context, Intent intent) {
1440 final String action = intent.getAction();
1441 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1442 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001443 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001444 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001445
Winson Chungc100e8e2011-08-09 16:02:43 -07001446 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001447 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001448 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001449 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001450 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001451 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1452 mUserPresent = true;
1453 updateRunning();
1454 }
1455 }
1456 };
1457
1458 @Override
1459 public void onAttachedToWindow() {
1460 super.onAttachedToWindow();
1461
1462 // Listen for broadcasts related to user-presence
1463 final IntentFilter filter = new IntentFilter();
1464 filter.addAction(Intent.ACTION_SCREEN_OFF);
1465 filter.addAction(Intent.ACTION_USER_PRESENT);
1466 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001467 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001468 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001469 mVisible = true;
1470 }
1471
1472 @Override
1473 public void onDetachedFromWindow() {
1474 super.onDetachedFromWindow();
1475 mVisible = false;
1476
Adam Cohend113e0c2010-11-11 10:48:05 -08001477 if (mAttached) {
1478 unregisterReceiver(mReceiver);
1479 mAttached = false;
1480 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001481 updateRunning();
1482 }
1483
1484 public void onWindowVisibilityChanged(int visibility) {
1485 mVisible = visibility == View.VISIBLE;
1486 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001487 // The following code used to be in onResume, but it turns out onResume is called when
1488 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1489 // is a more appropriate event to handle
1490 if (mVisible) {
1491 mAppsCustomizeTabHost.onWindowVisible();
1492 if (!mWorkspaceLoading) {
1493 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001494 // We want to let Launcher draw itself at least once before we force it to build
1495 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001496 // apps is nice and speedy.
1497 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001498 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001499 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001500 if (mStarted) return;
1501 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001502 // We delay the layer building a bit in order to give
1503 // other message processing a time to run. In particular
1504 // this avoids a delay in hiding the IME if it was
1505 // currently shown, because doing that may involve
1506 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001507 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001508 final ViewTreeObserver.OnDrawListener listener = this;
1509 mWorkspace.post(new Runnable() {
1510 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001511 if (mWorkspace != null &&
1512 mWorkspace.getViewTreeObserver() != null) {
1513 mWorkspace.getViewTreeObserver().
1514 removeOnDrawListener(listener);
1515 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001516 }
1517 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001518 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001519 }
1520 });
1521 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001522 // When Launcher comes back to foreground, a different Activity might be responsible for
1523 // the app market intent, so refresh the icon
1524 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001525 clearTypedText();
1526 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001527 }
1528
1529 private void sendAdvanceMessage(long delay) {
1530 mHandler.removeMessages(ADVANCE_MSG);
1531 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1532 mHandler.sendMessageDelayed(msg, delay);
1533 mAutoAdvanceSentTime = System.currentTimeMillis();
1534 }
1535
1536 private void updateRunning() {
1537 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1538 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1539 mAutoAdvanceRunning = autoAdvanceRunning;
1540 if (autoAdvanceRunning) {
1541 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1542 sendAdvanceMessage(delay);
1543 } else {
1544 if (!mWidgetsToAdvance.isEmpty()) {
1545 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1546 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1547 }
1548 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001549 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001550 }
1551 }
1552 }
1553
1554 private final Handler mHandler = new Handler() {
1555 @Override
1556 public void handleMessage(Message msg) {
1557 if (msg.what == ADVANCE_MSG) {
1558 int i = 0;
1559 for (View key: mWidgetsToAdvance.keySet()) {
1560 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1561 final int delay = mAdvanceStagger * i;
1562 if (v instanceof Advanceable) {
1563 postDelayed(new Runnable() {
1564 public void run() {
1565 ((Advanceable) v).advance();
1566 }
1567 }, delay);
1568 }
1569 i++;
1570 }
1571 sendAdvanceMessage(mAdvanceInterval);
1572 }
1573 }
1574 };
1575
1576 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001577 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001578 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1579 if (v instanceof Advanceable) {
1580 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001581 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001582 updateRunning();
1583 }
1584 }
1585
1586 void removeWidgetToAutoAdvance(View hostView) {
1587 if (mWidgetsToAdvance.containsKey(hostView)) {
1588 mWidgetsToAdvance.remove(hostView);
1589 updateRunning();
1590 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001591 }
1592
Joe Onorato9c1289c2009-08-17 11:03:03 -04001593 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001594 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001595 launcherInfo.hostView = null;
1596 }
1597
Winson Chung93eef082012-03-23 15:59:27 -07001598 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1599 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1600 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001601 }
1602
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001603 public LauncherAppWidgetHost getAppWidgetHost() {
1604 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605 }
Romain Guycbb89e42009-06-08 15:52:54 -07001606
Winson Chunga9abd0e2010-10-27 17:18:37 -07001607 public LauncherModel getModel() {
1608 return mModel;
1609 }
1610
Bjorn Bringertc459e522013-06-07 19:36:01 +01001611 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001612 getWindow().closeAllPanels();
1613
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001614 // Whatever we were doing is hereby canceled.
1615 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001616 }
1617
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618 @Override
1619 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001620 long startTime = 0;
1621 if (DEBUG_RESUME_TIME) {
1622 startTime = System.currentTimeMillis();
1623 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 super.onNewIntent(intent);
1625
1626 // Close the menu
1627 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001628 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001629 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001630
Jamie Genniscb222e82012-10-23 15:44:26 -07001631 final boolean alreadyOnHome =
1632 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001633 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001634
Jamie Genniscb222e82012-10-23 15:44:26 -07001635 Runnable processIntent = new Runnable() {
1636 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001637 if (mWorkspace == null) {
1638 // Can be cases where mWorkspace is null, this prevents a NPE
1639 return;
1640 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001641 Folder openFolder = mWorkspace.getOpenFolder();
1642 // In all these cases, only animate if we're already on home
1643 mWorkspace.exitWidgetResizeMode();
1644 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1645 openFolder == null) {
1646 mWorkspace.moveToDefaultScreen(true);
1647 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001648
Jamie Genniscb222e82012-10-23 15:44:26 -07001649 closeFolder();
1650 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001651
Jamie Genniscb222e82012-10-23 15:44:26 -07001652 // If we are already on home, then just animate back to the workspace,
1653 // otherwise, just wait until onResume to set the state back to Workspace
1654 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001655 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001656 } else {
1657 mOnResumeState = State.WORKSPACE;
1658 }
1659
1660 final View v = getWindow().peekDecorView();
1661 if (v != null && v.getWindowToken() != null) {
1662 InputMethodManager imm = (InputMethodManager)getSystemService(
1663 INPUT_METHOD_SERVICE);
1664 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1665 }
1666
Winson Chung7819a562013-09-19 15:55:45 -07001667 // Reset the apps customize page
1668 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001669 mAppsCustomizeTabHost.reset();
1670 }
1671 }
1672 };
1673
1674 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1675 // Delay processing of the intent to allow the status bar animation to finish
1676 // first in order to avoid janky animations.
1677 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001678 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001679 // Process the intent immediately.
1680 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001681 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001682
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001683 }
Michael Jurka447bf842013-05-15 14:52:15 +02001684 if (DEBUG_RESUME_TIME) {
1685 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1686 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001687 }
1688
Adam Cohen040a5d22013-09-16 17:09:33 -07001689 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1690 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001691 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001692 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001693 }
1694 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001695 protected void showWorkspaceAndExitOverviewMode() {
1696 showWorkspaceAndExitOverviewMode(true);
1697 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001698
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001700 public void onRestoreInstanceState(Bundle state) {
1701 super.onRestoreInstanceState(state);
1702 for (int page: mSynchronouslyBoundPages) {
1703 mWorkspace.restoreInstanceStateForChild(page);
1704 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 }
1706
1707 @Override
1708 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001709 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001710 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711
Michael Jurka883f55b2010-10-21 15:47:14 -07001712 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001713 // We close any open folder since it will not be re-opened, and we need to make sure
1714 // this state is reflected.
1715 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716
Adam Cohendcd297f2013-06-18 13:13:40 -07001717 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001718 mWaitingForResult) {
1719 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001720 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001721 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1722 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001723 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1724 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1725 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 }
1727
1728 if (mFolderInfo != null && mWaitingForResult) {
1729 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1730 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1731 }
Michael Jurka946ad472010-07-09 18:05:18 -07001732
Winson Chung785d2eb2011-04-14 16:08:02 -07001733 // Save the current AppsCustomize tab
1734 if (mAppsCustomizeTabHost != null) {
1735 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1736 if (currentTabTag != null) {
1737 outState.putString("apps_customize_currentTab", currentTabTag);
1738 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001739 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1740 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001741 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001742 }
1743
1744 @Override
1745 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001747
Winson Chunge7a03942011-08-05 15:05:12 -07001748 // Remove all pending runnables
1749 mHandler.removeMessages(ADVANCE_MSG);
1750 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001751 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001752
Winson Chungcd2b0142011-06-08 16:02:26 -07001753 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001754 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001755 mModel.stopLoader();
1756 app.setLauncher(null);
1757
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001759 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001761 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001763 mAppWidgetHost = null;
1764
1765 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766
1767 TextKeyListener.getInstance().release();
1768
Winson Chung81b52252012-08-27 15:34:29 -07001769 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1770 // to prevent leaking Launcher activities on orientation change.
1771 if (mModel != null) {
1772 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1773 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001774
1775 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001776 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001777
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001778 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001779 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1780 mWorkspace.removeAllViews();
1781 mWorkspace = null;
1782 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001783
Michael Jurka2ecf9952012-06-18 12:52:28 -07001784 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 }
1786
Adam Cohena9cf38f2011-05-02 15:36:58 -07001787 public DragController getDragController() {
1788 return mDragController;
1789 }
1790
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 @Override
1792 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001793 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001794 super.startActivityForResult(intent, requestCode);
1795 }
1796
Winson Chung70d72102011-08-12 11:24:35 -07001797 /**
1798 * Indicates that we want global search for this activity by setting the globalSearch
1799 * argument for {@link #startSearch} to true.
1800 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001801 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001802 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001804
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001805 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001806
Karl Rosaen138a0412009-04-23 19:00:21 -07001807 if (initialQuery == null) {
1808 // Use any text typed in the launcher as the initial query
1809 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001810 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 if (appSearchData == null) {
1812 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001813 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 }
Winson Chungadf0c182012-08-23 14:59:07 -07001815 Rect sourceBounds = new Rect();
1816 if (mSearchDropTargetBar != null) {
1817 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1818 }
Romain Guycbb89e42009-06-08 15:52:54 -07001819
Bjorn Bringertc459e522013-06-07 19:36:01 +01001820 startSearch(initialQuery, selectInitialQuery,
1821 appSearchData, sourceBounds);
1822 }
1823
1824 public void startSearch(String initialQuery,
1825 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001826 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001827 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001828 }
1829
1830 /**
1831 * Starts the global search activity. This code is a copied from SearchManager
1832 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001833 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001834 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001835 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001836 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1837 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1838 if (globalSearchActivity == null) {
1839 Log.w(TAG, "No global search activity found.");
1840 return;
1841 }
1842 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1843 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1844 intent.setComponent(globalSearchActivity);
1845 // Make sure that we have a Bundle to put source in
1846 if (appSearchData == null) {
1847 appSearchData = new Bundle();
1848 } else {
1849 appSearchData = new Bundle(appSearchData);
1850 }
1851 // Set source to package name of app that starts global search, if not set already.
1852 if (!appSearchData.containsKey("source")) {
1853 appSearchData.putString("source", getPackageName());
1854 }
1855 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1856 if (!TextUtils.isEmpty(initialQuery)) {
1857 intent.putExtra(SearchManager.QUERY, initialQuery);
1858 }
1859 if (selectInitialQuery) {
1860 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1861 }
1862 intent.setSourceBounds(sourceBounds);
1863 try {
1864 startActivity(intent);
1865 } catch (ActivityNotFoundException ex) {
1866 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1867 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001868 }
1869
Winson Chung70d72102011-08-12 11:24:35 -07001870 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001871 public boolean onPrepareOptionsMenu(Menu menu) {
1872 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001873 if (!mWorkspace.isInOverviewMode()) {
1874 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001875 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001876 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001877 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001879 @Override
1880 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001881 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001882 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001883 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001884 }
1885
Joe Onorato9c1289c2009-08-17 11:03:03 -04001886 public boolean isWorkspaceLocked() {
1887 return mWorkspaceLoading || mWaitingForResult;
1888 }
1889
Michael Jurka0280c3b2010-09-17 15:00:07 -07001890 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001891 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001892 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001893 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1894 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001895 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001896 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001897 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001898
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001899 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1900 AppWidgetProviderInfo appWidgetInfo) {
1901 if (appWidgetInfo.configure != null) {
1902 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001903
Bjorn Bringert7984c942009-12-09 15:38:25 +00001904 // Launch over to configure widget, if needed
1905 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001906 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001907 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001908 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001910 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001911 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001912 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001913 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001914 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 }
1916 }
Romain Guycbb89e42009-06-08 15:52:54 -07001917
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001918 protected void moveToCustomContentScreen(boolean animate) {
1919 mWorkspace.moveToCustomContentScreen(animate);
1920 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001921 /**
1922 * Process a shortcut drop.
1923 *
1924 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001925 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001926 * @param cell The cell it should be added to, optional
1927 * @param position The location on the screen where it was dropped, optional
1928 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001929 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001930 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001931 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001932 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001933 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001934 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001935
1936 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001937 mPendingAddInfo.cellX = cell[0];
1938 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001939 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001940
1941 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1942 createShortcutIntent.setComponent(componentName);
1943 processShortcut(createShortcutIntent);
1944 }
1945
Adam Cohenfbba09b2011-07-18 21:43:05 -07001946 /**
1947 * Process a widget drop.
1948 *
1949 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001950 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001951 * @param cell The cell it should be added to, optional
1952 * @param position The location on the screen where it was dropped, optional
1953 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001954 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001955 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001956 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001957 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001958 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001960 mPendingAddInfo.minSpanX = info.minSpanX;
1961 mPendingAddInfo.minSpanY = info.minSpanY;
1962
Adam Cohenfbba09b2011-07-18 21:43:05 -07001963 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001964 mPendingAddInfo.cellX = cell[0];
1965 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001966 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001967 if (span != null) {
1968 mPendingAddInfo.spanX = span[0];
1969 mPendingAddInfo.spanY = span[1];
1970 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001971
Adam Cohened66b2b2012-01-23 17:28:51 -08001972 AppWidgetHostView hostView = info.boundWidget;
1973 int appWidgetId;
1974 if (hostView != null) {
1975 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001976 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001977 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001978 // In this case, we either need to start an activity to get permission to bind
1979 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001980 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001981 Bundle options = info.bindOptions;
1982
1983 boolean success = false;
1984 if (options != null) {
1985 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1986 info.componentName, options);
1987 } else {
1988 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1989 info.componentName);
1990 }
1991 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001992 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001993 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001994 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001995 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1996 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1997 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001998 // TODO: we need to make sure that this accounts for the options bundle.
1999 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002000 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2001 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002002 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002003 }
2004
Joe Onoratodeb98af2010-02-19 14:59:39 -08002005 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002006 // Handle case where user selected "Applications"
2007 String applicationName = getResources().getString(R.string.group_applications);
2008 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002009
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002010 if (applicationName != null && applicationName.equals(shortcutName)) {
2011 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2012 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002013
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002014 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2015 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002016 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002017 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002018 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002019 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002020 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 }
2022
Winson Chung24ab2f12010-09-16 14:10:47 -07002023 void processWallpaper(Intent intent) {
2024 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2025 }
2026
Adam Cohendcd297f2013-06-18 13:13:40 -07002027 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002028 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002029 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 folderInfo.title = getText(R.string.folder_name);
2031
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002032 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002033 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002034 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002035 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036
2037 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002038 FolderIcon newFolder =
2039 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002040 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002042 // Force measure the new folder icon
2043 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2044 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002045 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046 }
Romain Guycbb89e42009-06-08 15:52:54 -07002047
Joe Onorato9c1289c2009-08-17 11:03:03 -04002048 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002049 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002050 }
2051
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002052 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002053 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002055 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002056 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 }
2058
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002059 protected ComponentName getWallpaperPickerComponent() {
2060 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2061 }
2062
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002063 /**
2064 * Registers various content observers. The current implementation registers
2065 * only a favorites observer to keep track of the favorites applications.
2066 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002067 private void registerContentObservers() {
2068 ContentResolver resolver = getContentResolver();
2069 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2070 true, mWidgetObserver);
2071 }
2072
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002073 @Override
2074 public boolean dispatchKeyEvent(KeyEvent event) {
2075 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2076 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002078 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002079 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002080 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002081 dumpState();
2082 return true;
2083 }
2084 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002085 }
2086 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2087 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002088 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 return true;
2090 }
2091 }
2092
2093 return super.dispatchKeyEvent(event);
2094 }
2095
Joe Onorato88ec0992009-11-19 13:16:06 -08002096 @Override
2097 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002098 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002099 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002100 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002101 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002102 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002103 Folder openFolder = mWorkspace.getOpenFolder();
2104 if (openFolder.isEditingName()) {
2105 openFolder.dismissEditingName();
2106 } else {
2107 closeFolder();
2108 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002109 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002110 mWorkspace.exitWidgetResizeMode();
2111
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002112 // Back button is a no-op here, but give at least some feedback for the button press
2113 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002114 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002115 }
2116
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002118 * Re-listen when widgets are reset.
2119 */
2120 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002121 if (mAppWidgetHost != null) {
2122 mAppWidgetHost.startListening();
2123 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002124 }
2125
2126 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002127 * Launches the intent referred by the clicked shortcut.
2128 *
2129 * @param v The view representing the clicked shortcut.
2130 */
2131 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002132 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2133 // view has detached (it's possible for this to happen if the view is removed mid touch).
2134 if (v.getWindowToken() == null) {
2135 return;
2136 }
2137
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002138 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002139 return;
2140 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002141
Adam Cohen1697b792013-09-17 19:08:21 -07002142 if (v instanceof Workspace) {
2143 if (mWorkspace.isInOverviewMode()) {
2144 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002145 }
2146 return;
2147 }
2148
2149 if (v instanceof CellLayout) {
2150 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002151 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002152 }
2153 }
2154
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002155 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002156 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002158 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2159 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002160
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002161 // Check for special shortcuts
2162 if (intent.getComponent() != null) {
2163 final String shortcutClass = intent.getComponent().getClassName();
2164
2165 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002166 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002167 return;
2168 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2169 MemoryDumpActivity.startDump(this);
2170 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002171 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2172 toggleShowWeightWatcher();
2173 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002174 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002175 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002176
2177 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002178 int[] pos = new int[2];
2179 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002180 intent.setSourceBounds(new Rect(pos[0], pos[1],
2181 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002182
2183 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002184
Daniel Sandlerff02d492013-08-05 02:12:05 -04002185 mStats.recordLaunch(intent, shortcut);
2186
Michael Jurkaddd62e92011-02-16 17:49:14 -08002187 if (success && v instanceof BubbleTextView) {
2188 mWaitingForResume = (BubbleTextView) v;
2189 mWaitingForResume.setStayPressed(true);
2190 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002192 if (v instanceof FolderIcon) {
2193 FolderIcon fi = (FolderIcon) v;
2194 handleFolderClick(fi);
2195 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002196 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002197 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002198 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002199 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002200 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002201 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 }
2203 }
2204
Michael Jurka0e260592010-06-30 17:07:39 -07002205 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002206 return false;
2207 }
2208
Michael Jurkaaf442092010-06-10 17:01:57 -07002209 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002210 * Event handler for the search button
2211 *
2212 * @param v The view that was clicked.
2213 */
2214 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002215 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2216
Amith Yamasania135ba82011-08-09 17:42:01 -07002217 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002218 }
2219
2220 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002221 * Event handler for the voice button
2222 *
2223 * @param v The view that was clicked.
2224 */
2225 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002226 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002227
Bjorn Bringertc459e522013-06-07 19:36:01 +01002228 startVoice();
2229 }
2230
2231 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002232 try {
2233 final SearchManager searchManager =
2234 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2235 ComponentName activityName = searchManager.getGlobalSearchActivity();
2236 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002237 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002238 if (activityName != null) {
2239 intent.setPackage(activityName.getPackageName());
2240 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002241 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002242 } catch (ActivityNotFoundException e) {
2243 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002244 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002245 startActivitySafely(null, intent, "onClickVoiceButton");
2246 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002247 }
2248
2249 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002250 * Event handler for the "grid" button that appears on the home screen, which
2251 * enters all apps mode.
2252 *
2253 * @param v The view that was clicked.
2254 */
2255 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002256 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002257 }
2258
2259 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002260 // Provide the same haptic feedback that the system offers for virtual keys.
2261 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002262 }
2263
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002264 public void onClickAppMarketButton(View v) {
2265 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002266 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002267 } else {
2268 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002269 }
2270 }
2271
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002272 /**
2273 * Called when the user stops interacting with the launcher.
2274 * This implies that the user is now on the homescreen and is not doing housekeeping.
2275 */
2276 protected void onInteractionEnd() {}
2277
2278 /**
2279 * Called when the user starts interacting with the launcher.
2280 * The possible interactions are:
2281 * - open all apps
2282 * - reorder an app shortcut, or a widget
2283 * - open the overview mode.
2284 * This is a good time to stop doing things that only make sense
2285 * when the user is on the homescreen and not doing housekeeping.
2286 */
2287 protected void onInteractionBegin() {}
2288
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002289 void startApplicationDetailsActivity(ComponentName componentName) {
2290 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002291 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2292 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002293 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002294 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002295 }
2296
Michael Jurka1e2f4652013-07-08 18:03:46 -07002297 // returns true if the activity was started
2298 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002299 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002300 // System applications cannot be installed. For now, show a toast explaining that.
2301 // We may give them the option of disabling apps this way.
2302 int messageId = R.string.uninstall_system_app_text;
2303 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002304 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002305 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002306 String packageName = componentName.getPackageName();
2307 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002308 Intent intent = new Intent(
2309 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002310 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2311 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002312 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002313 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002314 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002315 }
2316
Michael Jurka86a720e2012-05-09 11:23:23 -07002317 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002318 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002319
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002321 // Only launch using the new animation if the shortcut has not opted out (this is a
2322 // private contract between launcher and may be ignored in the future).
2323 boolean useLaunchAnimation = (v != null) &&
2324 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2325 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002326 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2327 v.getMeasuredWidth(), v.getMeasuredHeight());
2328
2329 startActivity(intent, opts.toBundle());
2330 } else {
2331 startActivity(intent);
2332 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002333 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 } catch (SecurityException e) {
2335 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002336 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002337 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002338 "or use the exported attribute for this activity. "
2339 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002341 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002343
Michael Jurka86a720e2012-05-09 11:23:23 -07002344 boolean startActivitySafely(View v, Intent intent, Object tag) {
2345 boolean success = false;
2346 try {
2347 success = startActivity(v, intent, tag);
2348 } catch (ActivityNotFoundException e) {
2349 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2350 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2351 }
2352 return success;
2353 }
2354
Adam Cohena9cf38f2011-05-02 15:36:58 -07002355 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002356 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002357 Folder openFolder = mWorkspace.getFolderForTag(info);
2358
2359 // If the folder info reports that the associated folder is open, then verify that
2360 // it is actually opened. There have been a few instances where this gets out of sync.
2361 if (info.opened && openFolder == null) {
2362 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002363 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002364 info.opened = false;
2365 }
2366
Adam Cohenfb91f302012-06-11 15:45:18 -07002367 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002368 // Close any open folder
2369 closeFolder();
2370 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002371 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372 } else {
2373 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 int folderScreen;
2375 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002376 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002377 // .. and close it
2378 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002379 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002380 // Close any folder open on the current screen
2381 closeFolder();
2382 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002383 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002384 }
2385 }
2386 }
2387 }
2388
Adam Cohen268c4752012-06-06 17:47:33 -07002389 /**
2390 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2391 * in the DragLayer in the exact absolute location of the original FolderIcon.
2392 */
2393 private void copyFolderIconToImage(FolderIcon fi) {
2394 final int width = fi.getMeasuredWidth();
2395 final int height = fi.getMeasuredHeight();
2396
2397 // Lazy load ImageView, Bitmap and Canvas
2398 if (mFolderIconImageView == null) {
2399 mFolderIconImageView = new ImageView(this);
2400 }
2401 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2402 mFolderIconBitmap.getHeight() != height) {
2403 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2404 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2405 }
2406
2407 DragLayer.LayoutParams lp;
2408 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2409 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2410 } else {
2411 lp = new DragLayer.LayoutParams(width, height);
2412 }
2413
Adam Cohen307fe232012-08-16 17:55:58 -07002414 // The layout from which the folder is being opened may be scaled, adjust the starting
2415 // view size by this scale factor.
2416 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002417 lp.customPosition = true;
2418 lp.x = mRectForFolderAnimation.left;
2419 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002420 lp.width = (int) (scale * width);
2421 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002422
2423 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2424 fi.draw(mFolderIconCanvas);
2425 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002426 if (fi.getFolder() != null) {
2427 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2428 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002429 }
Adam Cohen268c4752012-06-06 17:47:33 -07002430 // Just in case this image view is still in the drag layer from a previous animation,
2431 // we remove it and re-add it.
2432 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2433 mDragLayer.removeView(mFolderIconImageView);
2434 }
2435 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002436 if (fi.getFolder() != null) {
2437 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002438 }
Adam Cohen268c4752012-06-06 17:47:33 -07002439 }
2440
Adam Cohen2801caf2011-05-13 20:57:39 -07002441 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002442 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002443 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2444 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2445 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2446
Adam Cohenc51934b2011-07-26 21:07:43 -07002447 FolderInfo info = (FolderInfo) fi.getTag();
2448 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2449 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002450 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2451 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002452 }
2453
Adam Cohen268c4752012-06-06 17:47:33 -07002454 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2455 copyFolderIconToImage(fi);
2456 fi.setVisibility(View.INVISIBLE);
2457
Michael Jurka2ecf9952012-06-18 12:52:28 -07002458 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002459 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002460 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2461 oa.start();
2462 }
2463
Adam Cohen268c4752012-06-06 17:47:33 -07002464 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002465 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002466 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2467 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2468 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2469
Adam Cohen268c4752012-06-06 17:47:33 -07002470 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002471
Adam Cohen268c4752012-06-06 17:47:33 -07002472 // We remove and re-draw the FolderIcon in-case it has changed
2473 mDragLayer.removeView(mFolderIconImageView);
2474 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002475 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002476 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002477 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002478 oa.addListener(new AnimatorListenerAdapter() {
2479 @Override
2480 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002481 if (cl != null) {
2482 cl.clearFolderLeaveBehind();
2483 // Remove the ImageView copy of the FolderIcon and make the original visible.
2484 mDragLayer.removeView(mFolderIconImageView);
2485 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002486 }
2487 }
2488 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002489 oa.start();
2490 }
2491
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002492 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002493 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002494 * is animated relative to the specified View. If the View is null, no animation
2495 * is played.
2496 *
2497 * @param folderInfo The FolderInfo describing the folder to open.
2498 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002499 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002500 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002501 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502
Adam Cohena9cf38f2011-05-02 15:36:58 -07002503 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002504
Adam Cohen4554ee12011-08-03 16:13:21 -07002505 // Just verify that the folder hasn't already been added to the DragLayer.
2506 // There was a one-off crash where the folder had a parent already.
2507 if (folder.getParent() == null) {
2508 mDragLayer.addView(folder);
2509 mDragController.addDropTarget((DropTarget) folder);
2510 } else {
2511 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2512 folder.getParent() + ").");
2513 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002514 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002515 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002516
2517 // Notify the accessibility manager that this folder "window" has appeared and occluded
2518 // the workspace items
2519 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2520 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002521 }
2522
2523 public void closeFolder() {
2524 Folder folder = mWorkspace.getOpenFolder();
2525 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002526 if (folder.isEditingName()) {
2527 folder.dismissEditingName();
2528 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002529 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002530
2531 // Dismiss the folder cling
2532 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002533 }
2534 }
2535
2536 void closeFolder(Folder folder) {
2537 folder.getInfo().opened = false;
2538
2539 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2540 if (parent != null) {
2541 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2542 shrinkAndFadeInFolderIcon(fi);
2543 }
2544 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002545
2546 // Notify the accessibility manager that this folder "window" has disappeard and no
2547 // longer occludeds the workspace items
2548 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002549 }
2550
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002551 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002552 if (!isDraggingEnabled()) return false;
2553 if (isWorkspaceLocked()) return false;
2554 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555
Adam Cohen1697b792013-09-17 19:08:21 -07002556 if (v instanceof Workspace) {
2557 if (!mWorkspace.isInOverviewMode()) {
2558 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2559 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2560 mWorkspace.enterOverviewMode();
2561 }
2562 return true;
2563 }
2564
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002565 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002566 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 }
2568
Michael Jurka0280c3b2010-09-17 15:00:07 -07002569 resetAddInfo();
2570 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002571 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002572 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002573 return true;
2574 }
2575
Winson Chung3d503fb2011-07-13 17:25:49 -07002576 // The hotseat touch handling does not go through Workspace, and we always allow long press
2577 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002578 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002579 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2580 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002581 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002582 // User long pressed on empty space
2583 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2584 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2585 // Disabling reordering until we sort out some issues.
2586 if (mWorkspace.isInOverviewMode()) {
2587 mWorkspace.startReordering(v);
2588 } else {
2589 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002590 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002592 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002594 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002595 }
2596 }
2597 }
2598 return true;
2599 }
2600
Winson Chung3d503fb2011-07-13 17:25:49 -07002601 boolean isHotseatLayout(View layout) {
2602 return mHotseat != null && layout != null &&
2603 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2604 }
2605 Hotseat getHotseat() {
2606 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002607 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002608 View getOverviewPanel() {
2609 return mOverviewPanel;
2610 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002611 SearchDropTargetBar getSearchBar() {
2612 return mSearchDropTargetBar;
2613 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002614
Winson Chung3d503fb2011-07-13 17:25:49 -07002615 /**
2616 * Returns the CellLayout of the specified container at the specified screen.
2617 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002618 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002619 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2620 if (mHotseat != null) {
2621 return mHotseat.getLayout();
2622 } else {
2623 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002624 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002625 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002626 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002627 }
2628 }
2629
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002630 Workspace getWorkspace() {
2631 return mWorkspace;
2632 }
2633
Daniel Sandler843e8602010-06-07 14:59:01 -04002634 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002635 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002636 }
2637
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002638 /**
2639 * Helper method for the cameraZoomIn/cameraZoomOut animations
2640 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002641 * @param scaleFactor The scale factor used for the zoom
2642 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002643 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002645 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002647
Winson Chung18f41f82012-05-09 13:28:10 -07002648 void disableWallpaperIfInAllApps() {
2649 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002650 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002651 if (mAppsCustomizeTabHost != null &&
2652 !mAppsCustomizeTabHost.isTransitioning()) {
2653 updateWallpaperVisibility(false);
2654 }
2655 }
2656 }
2657
Craig Mautner360310b2012-10-26 15:13:08 -07002658 private void setWorkspaceBackground(boolean workspace) {
2659 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002660 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002661 }
2662
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002663 void updateWallpaperVisibility(boolean visible) {
2664 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2665 int curflags = getWindow().getAttributes().flags
2666 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2667 if (wpflags != curflags) {
2668 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2669 }
Craig Mautner360310b2012-10-26 15:13:08 -07002670 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002671 }
2672
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002673 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2674 if (v instanceof LauncherTransitionable) {
2675 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2676 }
2677 }
2678
Michael Jurkabed61d22012-02-14 22:51:29 -08002679 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2680 if (v instanceof LauncherTransitionable) {
2681 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2682 }
Winson Chung70442722012-02-10 15:43:22 -08002683
2684 // Update the workspace transition step as well
2685 dispatchOnLauncherTransitionStep(v, 0f);
2686 }
2687
2688 private void dispatchOnLauncherTransitionStep(View v, float t) {
2689 if (v instanceof LauncherTransitionable) {
2690 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2691 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002692 }
2693
2694 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2695 if (v instanceof LauncherTransitionable) {
2696 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2697 }
Winson Chung70442722012-02-10 15:43:22 -08002698
2699 // Update the workspace transition step as well
2700 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002701 }
2702
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002703 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002704 * Things to test when changing the following seven functions.
2705 * - Home from workspace
2706 * - from center screen
2707 * - from other screens
2708 * - Home from all apps
2709 * - from center screen
2710 * - from other screens
2711 * - Back from all apps
2712 * - from center screen
2713 * - from other screens
2714 * - Launch app from workspace and quit
2715 * - with back
2716 * - with home
2717 * - Launch app from all apps and quit
2718 * - with back
2719 * - with home
2720 * - Go to a screen that's not the default, then all
2721 * apps, and launch and app, and go back
2722 * - with back
2723 * -with home
2724 * - On workspace, long press power and go back
2725 * - with back
2726 * - with home
2727 * - On all apps, long press power and go back
2728 * - with back
2729 * - with home
2730 * - On workspace, power off
2731 * - On all apps, power off
2732 * - Launch an app and turn off the screen while in that app
2733 * - Go back with home key
2734 * - Go back with back key TODO: make this not go to workspace
2735 * - From all apps
2736 * - From workspace
2737 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2738 * - From all apps
2739 * - From the center workspace
2740 * - From another workspace
2741 */
2742
2743 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002744 * Zoom the camera out from the workspace to reveal 'toView'.
2745 * Assumes that the view to show is anchored at either the very top or very bottom
2746 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002747 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002748 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002749 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2750 showAppsCustomizeHelper(animated, springLoaded, contentType);
2751 }
2752 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2753 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002754 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002755 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002756 mStateAnimation.cancel();
2757 mStateAnimation = null;
2758 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002759 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002760
Winson Chungf0ea4d32011-06-06 14:27:16 -07002761 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2762 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2763 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002764 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002765 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002766 final int startDelay =
2767 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002768
Michael Jurkab3e22d92011-10-31 15:58:33 -07002769 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002770
Michael Jurkad74c9842011-07-10 12:44:21 -07002771 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002772 Animator workspaceAnim =
2773 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002774 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2775 // Set the content type for the all apps space
2776 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2777 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002778
2779 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002780 toView.setScaleX(scale);
2781 toView.setScaleY(scale);
2782 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2783 scaleAnim.
2784 scaleX(1f).scaleY(1f).
2785 setDuration(duration).
2786 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002787
Winson Chungf0ea4d32011-06-06 14:27:16 -07002788 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002789 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002790 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002791 .ofFloat(toView, "alpha", 0f, 1f)
2792 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002793 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002794 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2795 @Override
2796 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002797 if (animation == null) {
2798 throw new RuntimeException("animation is null");
2799 }
Winson Chung70442722012-02-10 15:43:22 -08002800 float t = (Float) animation.getAnimatedValue();
2801 dispatchOnLauncherTransitionStep(fromView, t);
2802 dispatchOnLauncherTransitionStep(toView, t);
2803 }
2804 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002805
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002806 // toView should appear right at the end of the workspace shrink
2807 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002808 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002809 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002810 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002811
2812 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002813 boolean animationCancelled = false;
2814
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002815 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002816 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002817 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002818 // Prepare the position
2819 toView.setTranslationX(0.0f);
2820 toView.setTranslationY(0.0f);
2821 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002822 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002823 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002824 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002825 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002826 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2827 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002828
Adam Cohenf4ddea32011-09-12 13:46:42 -07002829 if (!animationCancelled) {
2830 updateWallpaperVisibility(false);
2831 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002832
2833 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002834 if (mSearchDropTargetBar != null) {
2835 mSearchDropTargetBar.hideSearchBar(false);
2836 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002837 }
2838
Adam Cohencff6af82011-09-13 14:51:53 -07002839 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002840 public void onAnimationCancel(Animator animation) {
2841 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002842 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002843 });
2844
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002845 if (workspaceAnim != null) {
2846 mStateAnimation.play(workspaceAnim);
2847 }
Michael Jurka1899a362011-11-03 13:50:45 -07002848
2849 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002850
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002851 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2852 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853
2854 // If any of the objects being animated haven't been measured/laid out
2855 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002856 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857 (mWorkspace.getMeasuredWidth() == 0) ||
2858 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002859 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002860 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002861
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002862 final AnimatorSet stateAnimation = mStateAnimation;
2863 final Runnable startAnimRunnable = new Runnable() {
2864 public void run() {
2865 // Check that mStateAnimation hasn't changed while
2866 // we waited for a layout/draw pass
2867 if (mStateAnimation != stateAnimation)
2868 return;
2869 setPivotsForZoom(toView, scale);
2870 dispatchOnLauncherTransitionStart(fromView, animated, false);
2871 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002872 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002873 }
2874 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002875 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002876 final ViewTreeObserver observer = toView.getViewTreeObserver();
2877 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2878 public void onGlobalLayout() {
2879 startAnimRunnable.run();
2880 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2881 }
2882 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002883 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002884 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002885 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002886 } else {
2887 toView.setTranslationX(0.0f);
2888 toView.setTranslationY(0.0f);
2889 toView.setScaleX(1.0f);
2890 toView.setScaleY(1.0f);
2891 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002892 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002893
Daniel Sandlere4f98912013-06-25 15:13:26 -04002894 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002895 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002896 if (mSearchDropTargetBar != null) {
2897 mSearchDropTargetBar.hideSearchBar(false);
2898 }
Michael Jurkaabded662011-03-04 12:06:57 -08002899 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002900 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002901 dispatchOnLauncherTransitionStart(fromView, animated, false);
2902 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002903 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002904 dispatchOnLauncherTransitionStart(toView, animated, false);
2905 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002906 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002907 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002908 }
2909
2910 /**
2911 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002912 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002913 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002914 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002915 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2916 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002917
Michael Jurkab3e22d92011-10-31 15:58:33 -07002918 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002919 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002920 mStateAnimation.cancel();
2921 mStateAnimation = null;
2922 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002923 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002924
Winson Chungf0ea4d32011-06-06 14:27:16 -07002925 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002926 final int fadeOutDuration =
2927 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002928 final float scaleFactor = (float)
2929 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2930 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002931 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002932 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002933 if (toState == State.WORKSPACE) {
2934 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2935 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002936 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002937 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2938 workspaceAnim = mWorkspace.getChangeStateAnimation(
2939 Workspace.State.SPRING_LOADED, animated);
2940 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002941
Michael Jurkab3e22d92011-10-31 15:58:33 -07002942 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002943 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002944 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002945 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002946 final LauncherViewPropertyAnimator scaleAnim =
2947 new LauncherViewPropertyAnimator(fromView);
2948 scaleAnim.
2949 scaleX(scaleFactor).scaleY(scaleFactor).
2950 setDuration(duration).
2951 setInterpolator(new Workspace.ZoomInInterpolator());
2952
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002953 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002954 .ofFloat(fromView, "alpha", 1f, 0f)
2955 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002956 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002957 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2958 @Override
2959 public void onAnimationUpdate(ValueAnimator animation) {
2960 float t = 1f - (Float) animation.getAnimatedValue();
2961 dispatchOnLauncherTransitionStep(fromView, t);
2962 dispatchOnLauncherTransitionStep(toView, t);
2963 }
2964 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002965
Michael Jurka2ecf9952012-06-18 12:52:28 -07002966 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002967
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002968 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2969 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002970 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002971
2972 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002973 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002974 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002975 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002976 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002977 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2978 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002979 if (onCompleteRunnable != null) {
2980 onCompleteRunnable.run();
2981 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002982 mAppsCustomizeContent.updateCurrentPageScroll();
2983 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002984 }
2985 });
2986
Winson Chungf0ea4d32011-06-06 14:27:16 -07002987 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002988 if (workspaceAnim != null) {
2989 mStateAnimation.play(workspaceAnim);
2990 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002991 dispatchOnLauncherTransitionStart(fromView, animated, true);
2992 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002993 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002994 } else {
2995 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002996 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002997 dispatchOnLauncherTransitionStart(fromView, animated, true);
2998 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002999 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003000 dispatchOnLauncherTransitionStart(toView, animated, true);
3001 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003002 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003003 }
3004
Michael Jurkae326f182011-11-21 14:05:46 -08003005 @Override
3006 public void onTrimMemory(int level) {
3007 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003008 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003009 mAppsCustomizeTabHost.onTrimMemory();
3010 }
3011 }
3012
Winson Chung18f41f82012-05-09 13:28:10 -07003013 @Override
3014 public void onWindowFocusChanged(boolean hasFocus) {
3015 if (!hasFocus) {
3016 // When another window occludes launcher (like the notification shade, or recents),
3017 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3018 updateWallpaperVisibility(true);
3019 } else {
3020 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003021 mWorkspace.postDelayed(new Runnable() {
3022 @Override
3023 public void run() {
3024 disableWallpaperIfInAllApps();
3025 }
3026 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003027 }
3028 }
3029
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003030 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003031 showWorkspace(animated, null);
3032 }
3033
3034 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003035 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003036 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003037 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003038 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003039
Winson Chungc7d2b602012-05-16 17:02:20 -07003040 // Show the search bar (only animate if we were showing the drop target bar in spring
3041 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003042 if (mSearchDropTargetBar != null) {
3043 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3044 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003045
Michael Jurkab3e22d92011-10-31 15:58:33 -07003046 // Set focus to the AppsCustomize button
3047 if (mAllAppsButton != null) {
3048 mAllAppsButton.requestFocus();
3049 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003050 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003051
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003052 // Change the state *after* we've called all the transition code
3053 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003054
Winson Chung5fb63472011-02-02 17:03:37 -08003055 // Resume the auto-advance of widgets
3056 mUserPresent = true;
3057 updateRunning();
3058
alanv1d4fde62012-10-17 13:15:47 -07003059 // Send an accessibility event to announce the context change
3060 getWindow().getDecorView()
3061 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003062
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003063 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003064 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003065 }
3066
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003067 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003068 }
3069
Winson Chungc58497e2013-09-03 17:48:37 -07003070 void showAllApps(boolean animated,
3071 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003072 if (mState != State.WORKSPACE) return;
3073
Winson Chungc58497e2013-09-03 17:48:37 -07003074 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003075 mAppsCustomizeTabHost.requestFocus();
3076
Michael Jurkab3e22d92011-10-31 15:58:33 -07003077 // Change the state *after* we've called all the transition code
3078 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003079 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003080
3081 // Pause the auto-advance of widgets until we are out of AllApps
3082 mUserPresent = false;
3083 updateRunning();
3084 closeFolder();
3085
3086 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003087 getWindow().getDecorView()
3088 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003089 }
3090
Adam Cohen7777d962011-08-18 18:58:38 -07003091 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003092 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003093 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003094 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003095 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003096 }
Adam Cohen7777d962011-08-18 18:58:38 -07003097
Adam Cohened66b2b2012-01-23 17:28:51 -08003098 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3099 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003100 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3101
Winson Chunge7a03942011-08-05 15:05:12 -07003102 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003103 @Override
3104 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003105 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003106 // Before we show workspace, hide all apps again because
3107 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3108 // clean up our state transition functions
3109 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003110 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003111 } else {
3112 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003113 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003114 }
3115 }, (extendedDelay ?
3116 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3117 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3118 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003119
Michael Jurkad3ef3062010-11-23 16:23:58 -08003120 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003121 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003122 final boolean animated = true;
3123 final boolean springLoaded = true;
3124 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003125 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003126 }
3127 // Otherwise, we are not in spring loaded mode, so don't do anything.
3128 }
3129
Michael Jurkab3e22d92011-10-31 15:58:33 -07003130 void lockAllApps() {
3131 // TODO
3132 }
3133
3134 void unlockAllApps() {
3135 // TODO
3136 }
3137
Winson Chungf0ea4d32011-06-06 14:27:16 -07003138 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003139 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003140 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003142 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003143 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003144 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003145 int duration = 0;
3146 if (mSearchDropTargetBar != null) {
3147 duration = mSearchDropTargetBar.getTransitionInDuration();
3148 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003149 mHotseat.animate().alpha(1f).setDuration(duration);
3150 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003151 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003152 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 }
3154 }
3155 }
3156
3157 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003158 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003159 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003160 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003161 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003162 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003163 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003164 int duration = 0;
3165 if (mSearchDropTargetBar != null) {
3166 duration = mSearchDropTargetBar.getTransitionOutDuration();
3167 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003168 mHotseat.animate().alpha(0f).setDuration(duration);
3169 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003170 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003171 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003172 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003173 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003174 }
3175
Patrick Dubroy5f445422011-02-18 14:35:21 -08003176 /**
3177 * Add an item from all apps or customize onto the given workspace screen.
3178 * If layout is null, add to the current screen.
3179 */
3180 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003181 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003182 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003183 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003184 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003185
Winson Chungdff8ebb2011-09-08 17:25:31 -07003186 /** Maps the current orientation to an index for referencing orientation correct global icons */
3187 private int getCurrentOrientationIndexForGlobalIcons() {
3188 // default - 0, landscape - 1
3189 switch (getResources().getConfiguration().orientation) {
3190 case Configuration.ORIENTATION_LANDSCAPE:
3191 return 1;
3192 default:
3193 return 0;
3194 }
3195 }
3196
Michael Jurkaae65ee32012-04-30 11:45:54 -07003197 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003198 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003199 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003200 // Look for the toolbar icon specified in the activity meta-data
3201 Bundle metaData = packageManager.getActivityInfo(
3202 activityName, PackageManager.GET_META_DATA).metaData;
3203 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003204 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003205 if (iconResId != 0) {
3206 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003207 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003208 }
3209 }
3210 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003211 // This can happen if the activity defines an invalid drawable
3212 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3213 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003214 } catch (Resources.NotFoundException nfe) {
3215 // This can happen if the activity defines an invalid drawable
3216 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3217 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003218 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003219 return null;
3220 }
3221
3222 // if successful in getting icon, return it; otherwise, set button to use default drawable
3223 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003224 int buttonId, ComponentName activityName, int fallbackDrawableId,
3225 String toolbarResourceName) {
3226 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003227 Resources r = getResources();
3228 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3229 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003230
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003231 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003232 // If we were unable to find the icon via the meta-data, use a generic one
3233 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003234 toolbarIcon = r.getDrawable(fallbackDrawableId);
3235 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003236 if (button != null) {
3237 button.setCompoundDrawables(toolbarIcon, null, null, null);
3238 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003239 return null;
3240 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003241 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003242 if (button != null) {
3243 button.setCompoundDrawables(toolbarIcon, null, null, null);
3244 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003245 return toolbarIcon.getConstantState();
3246 }
3247 }
3248
3249 // if successful in getting icon, return it; otherwise, set button to use default drawable
3250 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003251 int buttonId, ComponentName activityName, int fallbackDrawableId,
3252 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003253 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003254 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003255
Michael Jurka19e0fc52011-07-22 18:00:21 -07003256 if (button != null) {
3257 // If we were unable to find the icon via the meta-data, use a
3258 // generic one
3259 if (toolbarIcon == null) {
3260 button.setImageResource(fallbackDrawableId);
3261 } else {
3262 button.setImageDrawable(toolbarIcon);
3263 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003264 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003265
3266 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3267
Michael Jurka0423dcf2010-10-05 14:56:18 -07003268 }
3269
Winson Chung1b884092012-06-08 17:13:02 -07003270 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003271 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003272 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003273 }
3274
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003275 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003276 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003277 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003278 }
3279
Winson Chungbb185bd2011-11-21 12:31:42 -08003280 private void invalidatePressedFocusedStates(View container, View button) {
3281 if (container instanceof HolographicLinearLayout) {
3282 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3283 layout.invalidatePressedFocusedStates();
3284 } else if (button instanceof HolographicImageView) {
3285 HolographicImageView view = (HolographicImageView) button;
3286 view.invalidatePressedFocusedStates();
3287 }
3288 }
3289
Cristina Stancu476493b2013-08-07 17:20:14 +01003290 public View getQsbBar() {
3291 if (mQsbBar == null) {
3292 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3293 }
3294 return mQsbBar;
3295 }
3296
3297 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003298 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003299 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003300 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003301 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003302
Winson Chung1cad91e2011-05-25 17:41:01 -07003303 final SearchManager searchManager =
3304 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3305 ComponentName activityName = searchManager.getGlobalSearchActivity();
3306 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003307 int coi = getCurrentOrientationIndexForGlobalIcons();
3308 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003309 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3310 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3311 if (sGlobalSearchIcon[coi] == null) {
3312 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3313 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3314 TOOLBAR_ICON_METADATA_NAME);
3315 }
3316
Winson Chungc51db6a2011-10-05 11:44:49 -07003317 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3318 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003319 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003320 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003321 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003322 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003323 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3324 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003325 if (searchButton != null) searchButton.setVisibility(View.GONE);
3326 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003327 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003328 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003329 }
3330 }
3331
Cristina Stancu476493b2013-08-07 17:20:14 +01003332 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003333 final View searchButtonContainer = findViewById(R.id.search_button_container);
3334 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003335 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003336 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003337 }
3338
Cristina Stancu476493b2013-08-07 17:20:14 +01003339 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003340 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003341 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003342
Winson Chungc51db6a2011-10-05 11:44:49 -07003343 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003344 final SearchManager searchManager =
3345 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3346 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3347
3348 ComponentName activityName = null;
3349 if (globalSearchActivity != null) {
3350 // Check if the global search activity handles voice search
3351 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3352 intent.setPackage(globalSearchActivity.getPackageName());
3353 activityName = intent.resolveActivity(getPackageManager());
3354 }
3355
3356 if (activityName == null) {
3357 // Fallback: check if an activity other than the global search activity
3358 // resolves this
3359 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3360 activityName = intent.resolveActivity(getPackageManager());
3361 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003362 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003363 int coi = getCurrentOrientationIndexForGlobalIcons();
3364 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003365 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3366 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3367 if (sVoiceSearchIcon[coi] == null) {
3368 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3369 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3370 TOOLBAR_ICON_METADATA_NAME);
3371 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003372 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003373 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003374 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003375 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003376 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003377 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003378 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003379 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003380 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003381 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003382 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003383 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003384
Cristina Stancu476493b2013-08-07 17:20:14 +01003385 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003386 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3387 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003388 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003389 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003390 }
3391
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003392 public void setVoiceButtonProxyVisible(boolean visible) {
3393 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3394 if (voiceButtonProxy != null) {
3395 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3396 }
3397 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003398 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003399 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003400 */
3401 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003402 final View marketButton = findViewById(R.id.market_button);
3403 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3404 // Find the app market activity by resolving an intent.
3405 // (If multiple app markets are installed, it will return the ResolverActivity.)
3406 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003407 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003408 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003409 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003410 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003411 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3412 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003413 marketButton.setVisibility(View.VISIBLE);
3414 } else {
3415 // We should hide and disable the view so that we don't try and restore the visibility
3416 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3417 marketButton.setVisibility(View.GONE);
3418 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003419 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003420 }
3421
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003422 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003423 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3424 Resources r = getResources();
3425 Drawable marketIconDrawable = d.newDrawable(r);
3426 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3427 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3428 marketIconDrawable.setBounds(0, 0, w, h);
3429
3430 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003431 }
3432
Michael Jurkad7c28052012-04-27 15:43:36 -07003433 @Override
3434 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003435 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003436 final List<CharSequence> text = event.getText();
3437 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003438 // Populate event with a fake title based on the current state.
3439 if (mState == State.APPS_CUSTOMIZE) {
3440 text.add(getString(R.string.all_apps_button_label));
3441 } else {
3442 text.add(getString(R.string.all_apps_home_button_label));
3443 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003444 return result;
3445 }
3446
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003447 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003448 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003449 */
3450 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3451 @Override
3452 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003453 closeSystemDialogs();
3454 }
3455 }
3456
3457 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003458 * Receives notifications whenever the appwidgets are reset.
3459 */
3460 private class AppWidgetResetObserver extends ContentObserver {
3461 public AppWidgetResetObserver() {
3462 super(new Handler());
3463 }
3464
3465 @Override
3466 public void onChange(boolean selfChange) {
3467 onAppWidgetReset();
3468 }
3469 }
3470
3471 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003472 * If the activity is currently paused, signal that we need to run the passed Runnable
3473 * in onResume.
3474 *
3475 * This needs to be called from incoming places where resources might have been loaded
3476 * while we are paused. That is becaues the Configuration might be wrong
3477 * when we're not running, and if it comes back to what it was when we
3478 * were paused, we are not restarted.
3479 *
3480 * Implementation of the method from LauncherModel.Callbacks.
3481 *
3482 * @return true if we are currently paused. The caller might be able to
3483 * skip some work in that case since we will come back again.
3484 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003485 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003486 if (mPaused) {
3487 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003488 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003489 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003490 }
3491 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003492 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003493 return true;
3494 } else {
3495 return false;
3496 }
3497 }
3498
Michael Jurkac402cd92013-05-20 15:49:32 +02003499 private boolean waitUntilResume(Runnable run) {
3500 return waitUntilResume(run, false);
3501 }
3502
Michael Jurka1e2f4652013-07-08 18:03:46 -07003503 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003504 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003505 }
3506
Michael Jurka7607c2f2013-04-03 14:33:19 -07003507 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003508 * If the activity is currently paused, signal that we need to re-run the loader
3509 * in onResume.
3510 *
3511 * This needs to be called from incoming places where resources might have been loaded
3512 * while we are paused. That is becaues the Configuration might be wrong
3513 * when we're not running, and if it comes back to what it was when we
3514 * were paused, we are not restarted.
3515 *
3516 * Implementation of the method from LauncherModel.Callbacks.
3517 *
3518 * @return true if we are currently paused. The caller might be able to
3519 * skip some work in that case since we will come back again.
3520 */
3521 public boolean setLoadOnResume() {
3522 if (mPaused) {
3523 Log.i(TAG, "setLoadOnResume");
3524 mOnResumeNeedsLoad = true;
3525 return true;
3526 } else {
3527 return false;
3528 }
3529 }
3530
3531 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003532 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003533 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003534 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003535 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003536 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003537 } else {
3538 return SCREEN_COUNT / 2;
3539 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003540 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003541
Joe Onorato9c1289c2009-08-17 11:03:03 -04003542 /**
3543 * Refreshes the shortcuts shown on the workspace.
3544 *
3545 * Implementation of the method from LauncherModel.Callbacks.
3546 */
3547 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003548 // If we're starting binding all over again, clear any bind calls we'd postponed in
3549 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3550 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003551 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003552
Winson Chungd64d1762013-08-20 14:37:16 -07003553 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003554 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003555 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003556
Michael Jurka05bf644e2011-11-30 20:28:53 -08003557 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003558 if (mHotseat != null) {
3559 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003560 }
3561 }
3562
Adam Cohendcd297f2013-06-18 13:13:40 -07003563 @Override
3564 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003565 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003566
Adam Cohen5084cba2013-09-03 12:01:16 -07003567 // If there are no screens, we need to have an empty screen
3568 if (orderedScreenIds.size() == 0) {
3569 mWorkspace.addExtraEmptyScreen();
3570 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003571
3572 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003573 // setCurrentPage() so ensure that all pages are added before calling this).
3574 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003575 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3576 mWorkspace.createCustomContentPage();
3577 }
Winson Chung64359a52013-07-08 17:17:08 -07003578 }
3579
3580 @Override
3581 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003582 int count = orderedScreenIds.size();
3583 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003584 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003585 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003586 }
3587
Adam Cohen39a06042013-07-19 14:30:12 -07003588 private boolean shouldShowWeightWatcher() {
3589 String spKey = LauncherAppState.getSharedPreferencesKey();
3590 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003591 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003592
3593 return show;
3594 }
3595
Adam Cohen4caf2982013-08-20 18:54:31 -07003596 private boolean emailSent() {
3597 String spKey = LauncherAppState.getSharedPreferencesKey();
3598 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3599 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3600 return show;
3601 }
3602
3603 private void setEmailSent(boolean sent) {
3604 String spKey = LauncherAppState.getSharedPreferencesKey();
3605 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3606
3607 SharedPreferences.Editor editor = sp.edit();
3608 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3609 editor.commit();
3610 }
3611
Adam Cohen39a06042013-07-19 14:30:12 -07003612 private void toggleShowWeightWatcher() {
3613 String spKey = LauncherAppState.getSharedPreferencesKey();
3614 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3615 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3616
3617 show = !show;
3618
3619 SharedPreferences.Editor editor = sp.edit();
3620 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3621 editor.commit();
3622
3623 if (mWeightWatcher != null) {
3624 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3625 }
3626 }
3627
Winson Chungd64d1762013-08-20 14:37:16 -07003628 public void bindAppsAdded(final ArrayList<Long> newScreens,
3629 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003630 final ArrayList<ItemInfo> addAnimated,
3631 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003632 Runnable r = new Runnable() {
3633 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003634 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003635 }
3636 };
3637 if (waitUntilResume(r)) {
3638 return;
3639 }
3640
Winson Chungd64d1762013-08-20 14:37:16 -07003641 // Add the new screens
3642 bindAddScreens(newScreens);
3643
3644 // We add the items without animation on non-visible pages, and with
3645 // animations on the new page (which we will try and snap to).
3646 if (!addNotAnimated.isEmpty()) {
3647 bindItems(addNotAnimated, 0,
3648 addNotAnimated.size(), false);
3649 }
3650 if (!addAnimated.isEmpty()) {
3651 bindItems(addAnimated, 0,
3652 addAnimated.size(), true);
3653 }
Winson Chungc58497e2013-09-03 17:48:37 -07003654
3655 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3656 addedApps != null && mAppsCustomizeContent != null) {
3657 mAppsCustomizeContent.addApps(addedApps);
3658 }
Winson Chungd64d1762013-08-20 14:37:16 -07003659 }
3660
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003661 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003662 * Bind the items start-end from the list.
3663 *
3664 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003665 */
Winson Chung64359a52013-07-08 17:17:08 -07003666 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3667 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003668 Runnable r = new Runnable() {
3669 public void run() {
3670 bindItems(shortcuts, start, end, forceAnimateIcons);
3671 }
3672 };
3673 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003674 return;
3675 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003676
Winson Chungf0c6ae02012-03-21 16:10:31 -07003677 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003678 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3679 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003680 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003681 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003682 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003683 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003684 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003685
3686 // Short circuit if we are loading dock items for a configuration which has no dock
3687 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3688 mHotseat == null) {
3689 continue;
3690 }
3691
Joe Onorato9c1289c2009-08-17 11:03:03 -04003692 switch (item.itemType) {
3693 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3694 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003695 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003696 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003697
Winson Chung64359a52013-07-08 17:17:08 -07003698 /*
3699 * TODO: FIX collision case
3700 */
Winson Chungce376632013-07-11 16:12:41 -07003701 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3702 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3703 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3704 throw new RuntimeException("OCCUPIED");
3705 }
Winson Chung64359a52013-07-08 17:17:08 -07003706 }
3707
Adam Cohendcd297f2013-06-18 13:13:40 -07003708 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3709 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003710 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003711 // Animate all the applications up now
3712 shortcut.setAlpha(0f);
3713 shortcut.setScaleX(0f);
3714 shortcut.setScaleY(0f);
3715 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003716 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003717 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003718 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003719 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003720 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003721 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003722 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003723 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3724 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003725 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003726 default:
3727 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003728 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003729 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003730
Winson Chung997a9232013-07-24 15:33:46 -07003731 if (animateIcons) {
3732 // Animate to the correct page
3733 if (newShortcutsScreenId > -1) {
3734 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3735 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3736 if (newShortcutsScreenId != currentScreenId) {
3737 mWorkspace.snapToPage(newScreenIndex);
3738 }
3739 }
3740
Winson Chung64359a52013-07-08 17:17:08 -07003741 // We post the animation slightly delayed to prevent slowdowns when we are loading
3742 // right after we return to launcher.
3743 mWorkspace.postDelayed(new Runnable() {
3744 public void run() {
3745 anim.playTogether(bounceAnims);
3746 anim.start();
3747 }
3748 }, NEW_APPS_ANIMATION_DELAY);
3749 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003750 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003751 }
3752
Joe Onorato9c1289c2009-08-17 11:03:03 -04003753 /**
3754 * Implementation of the method from LauncherModel.Callbacks.
3755 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003756 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003757 Runnable r = new Runnable() {
3758 public void run() {
3759 bindFolders(folders);
3760 }
3761 };
3762 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003763 return;
3764 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003765 sFolders.clear();
3766 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003767 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003768
3769 /**
3770 * Add the views for a widget to the workspace.
3771 *
3772 * Implementation of the method from LauncherModel.Callbacks.
3773 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003774 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003775 Runnable r = new Runnable() {
3776 public void run() {
3777 bindAppWidget(item);
3778 }
3779 };
3780 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003781 return;
3782 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003783
Daniel Sandler843e8602010-06-07 14:59:01 -04003784 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3785 if (DEBUG_WIDGETS) {
3786 Log.d(TAG, "bindAppWidget: " + item);
3787 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003788 final Workspace workspace = mWorkspace;
3789
3790 final int appWidgetId = item.appWidgetId;
3791 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003792 if (DEBUG_WIDGETS) {
3793 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3794 }
3795
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3797
Joe Onorato9c1289c2009-08-17 11:03:03 -04003798 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003799 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003800
Adam Cohendcd297f2013-06-18 13:13:40 -07003801 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003802 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003803 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3804
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805 workspace.requestLayout();
3806
Daniel Sandler843e8602010-06-07 14:59:01 -04003807 if (DEBUG_WIDGETS) {
3808 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3809 + (SystemClock.uptimeMillis()-start) + "ms");
3810 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003811 }
3812
Adam Cohen1462de32012-07-24 22:34:36 -07003813 public void onPageBoundSynchronously(int page) {
3814 mSynchronouslyBoundPages.add(page);
3815 }
3816
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 /**
3818 * Callback saying that there aren't any more items to bind.
3819 *
3820 * Implementation of the method from LauncherModel.Callbacks.
3821 */
Adam Cohene25af792013-06-06 23:08:25 -07003822 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003823 Runnable r = new Runnable() {
3824 public void run() {
3825 finishBindingItems(upgradePath);
3826 }
3827 };
3828 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003829 return;
3830 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003831 if (mSavedState != null) {
3832 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003833 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003834 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003835 mSavedState = null;
3836 }
3837
Adam Cohen1462de32012-07-24 22:34:36 -07003838 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003839
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003840 // If we received the result of any pending adds while the loader was running (e.g. the
3841 // widget configuration forced an orientation change), process them now.
3842 for (int i = 0; i < sPendingAddList.size(); i++) {
3843 completeAdd(sPendingAddList.get(i));
3844 }
3845 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003846
Winson Chungc51db6a2011-10-05 11:44:49 -07003847 // Update the market app icon as necessary (the other icons will be managed in response to
3848 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003849 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003850
Winson Chungf0c6ae02012-03-21 16:10:31 -07003851 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003852 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003853 mWorkspace.getUniqueComponents(true, null);
3854 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003855 }
Adam Cohen99894d92013-06-14 11:22:59 -07003856
Adam Cohen66a01fd2013-06-11 12:48:00 -07003857 mWorkspace.post(new Runnable() {
3858 @Override
3859 public void run() {
3860 onFinishBindingItems();
3861 }
3862 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003863 }
3864
Winson Chunga2413752012-04-03 14:22:34 -07003865 private boolean canRunNewAppsAnimation() {
3866 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3867 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3868 }
3869
Winson Chungc9168342013-06-26 14:54:55 -07003870 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3871 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3872 PropertyValuesHolder.ofFloat("alpha", 1f),
3873 PropertyValuesHolder.ofFloat("scaleX", 1f),
3874 PropertyValuesHolder.ofFloat("scaleY", 1f));
3875 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3876 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3877 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3878 return bounceAnim;
3879 }
3880
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003881 @Override
3882 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003883 boolean searchVisible = updateGlobalSearchIcon();
3884 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003885 if (mSearchDropTargetBar != null) {
3886 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3887 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003888 }
3889
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003890 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003891 * Add the icons for all apps.
3892 *
3893 * Implementation of the method from LauncherModel.Callbacks.
3894 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003895 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003896 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3897 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3898 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3899 getHotseat().addAllAppsFolder(mIconCache, apps,
3900 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3901 }
3902 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003903 }
Winson Chungc58497e2013-09-03 17:48:37 -07003904 } else {
3905 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3906 mAppsCustomizeContent != null) {
3907 mAppsCustomizeContent.setApps(apps);
3908 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003909 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003910 }
3911
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003912 @Override
3913 public boolean shouldShowApp(ResolveInfo app) {
3914 return true;
3915 }
3916
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917 /**
3918 * A package was updated.
3919 *
3920 * Implementation of the method from LauncherModel.Callbacks.
3921 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003922 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003923 Runnable r = new Runnable() {
3924 public void run() {
3925 bindAppsUpdated(apps);
3926 }
3927 };
3928 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003929 return;
3930 }
3931
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003932 if (mWorkspace != null) {
3933 mWorkspace.updateShortcuts(apps);
3934 }
Winson Chungc58497e2013-09-03 17:48:37 -07003935
3936 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3937 mAppsCustomizeContent != null) {
3938 mAppsCustomizeContent.updateApps(apps);
3939 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003940 }
3941
3942 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003943 * A package was uninstalled. We take both the super set of packageNames
3944 * in addition to specific applications to remove, the reason being that
3945 * this can be called when a package is updated as well. In that scenario,
3946 * we only remove specific components from the workspace, where as
3947 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003948 *
3949 * Implementation of the method from LauncherModel.Callbacks.
3950 */
Winson Chung83892cc2013-05-01 16:53:33 -07003951 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003952 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003953 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003954 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003955 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003956 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003957 }
Winson Chungd64d1762013-08-20 14:37:16 -07003958 };
3959 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003960 return;
3961 }
3962
Winson Chung64359a52013-07-08 17:17:08 -07003963 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003964 mWorkspace.removeItemsByPackageName(packageNames);
3965 } else {
3966 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003967 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003968
Winson Chunga1820962011-10-03 16:31:06 -07003969 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003970 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003971
3972 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3973 mAppsCustomizeContent != null) {
3974 mAppsCustomizeContent.removeApps(appInfos);
3975 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003976 }
Joe Onoratobe386092009-11-17 17:32:16 -08003977
3978 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003979 * A number of packages were updated.
3980 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003981 private ArrayList<Object> mWidgetsAndShortcuts;
3982 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003983 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003984 bindPackagesUpdated(mWidgetsAndShortcuts);
3985 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003986 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003987 };
3988
3989 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3990 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3991 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003992 return;
3993 }
3994
Winson Chung64359a52013-07-08 17:17:08 -07003995 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003996 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3997 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003998 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003999 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004000 }
4001
Winson Chung400438b2011-01-16 17:53:48 -08004002 private int mapConfigurationOriActivityInfoOri(int configOri) {
4003 final Display d = getWindowManager().getDefaultDisplay();
4004 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4005 switch (d.getRotation()) {
4006 case Surface.ROTATION_0:
4007 case Surface.ROTATION_180:
4008 // We are currently in the same basic orientation as the natural orientation
4009 naturalOri = configOri;
4010 break;
4011 case Surface.ROTATION_90:
4012 case Surface.ROTATION_270:
4013 // We are currently in the other basic orientation to the natural orientation
4014 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4015 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4016 break;
4017 }
4018
4019 int[] oriMap = {
4020 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4021 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4022 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4023 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4024 };
4025 // Since the map starts at portrait, we need to offset if this device's natural orientation
4026 // is landscape.
4027 int indexOffset = 0;
4028 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4029 indexOffset = 1;
4030 }
4031 return oriMap[(d.getRotation() + indexOffset) % 4];
4032 }
Adam Cohen446e9402011-09-15 18:21:21 -07004033
Winson Chung4b919f82012-05-01 10:44:08 -07004034 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004035 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004036 getResources().getBoolean(R.bool.allow_rotation);
4037 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004038 }
Winson Chung4b919f82012-05-01 10:44:08 -07004039 public void lockScreenOrientation() {
4040 if (isRotationEnabled()) {
4041 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4042 .getConfiguration().orientation));
4043 }
4044 }
4045 public void unlockScreenOrientation(boolean immediate) {
4046 if (isRotationEnabled()) {
4047 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004048 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004049 } else {
4050 mHandler.postDelayed(new Runnable() {
4051 public void run() {
4052 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4053 }
4054 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004055 }
Winson Chung4b919f82012-05-01 10:44:08 -07004056 }
Winson Chung400438b2011-01-16 17:53:48 -08004057 }
4058
Winson Chung82f55532011-08-09 14:14:23 -07004059 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004060 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004061 if (DISABLE_CLINGS) {
4062 return false;
4063 }
4064
Brett Chabot2a9e2282011-08-23 15:03:13 -07004065 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004066 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004067
Michael Jurkae233a8b2013-03-19 13:49:20 +01004068 // Restricted secondary users (child mode) will potentially have very few apps
4069 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004070// boolean supportsLimitedUsers =
4071// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4072// Account[] accounts = AccountManager.get(this).getAccounts();
4073// if (supportsLimitedUsers && accounts.length == 0) {
4074// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4075// Bundle restrictions = um.getUserRestrictions();
4076// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4077// return false;
4078// }
4079// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004080 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004081 }
Michael Jurka22143132012-10-04 17:42:38 +02004082
Winson Chung7d7541e2011-09-16 20:14:36 -07004083 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02004084 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004085 if (cling != null) {
4086 cling.init(this, positionData);
4087 cling.setVisibility(View.VISIBLE);
4088 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
4089 if (animate) {
4090 cling.buildLayer();
4091 cling.setAlpha(0f);
4092 cling.animate()
4093 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07004094 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07004095 .setDuration(SHOW_CLING_DURATION)
4096 .setStartDelay(delay)
4097 .start();
4098 } else {
4099 cling.setAlpha(1f);
4100 }
Michael Jurka22143132012-10-04 17:42:38 +02004101 cling.setFocusableInTouchMode(true);
4102 cling.post(new Runnable() {
4103 public void run() {
4104 cling.setFocusable(true);
4105 cling.requestFocus();
4106 }
4107 });
4108 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
4109 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004110 }
4111 return cling;
4112 }
Michael Jurka22143132012-10-04 17:42:38 +02004113
Winson Chung7d7541e2011-09-16 20:14:36 -07004114 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08004115 // To catch cases where siblings of top-level views are made invisible, just check whether
4116 // the cling is directly set to GONE before dismissing it.
4117 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07004118 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07004119 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07004120 anim.addListener(new AnimatorListenerAdapter() {
4121 public void onAnimationEnd(Animator animation) {
4122 cling.setVisibility(View.GONE);
4123 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004124 // We should update the shared preferences on a background thread
4125 new Thread("dismissClingThread") {
4126 public void run() {
4127 SharedPreferences.Editor editor = mSharedPrefs.edit();
4128 editor.putBoolean(flag, true);
4129 editor.commit();
4130 }
4131 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07004132 };
4133 });
4134 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02004135 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07004136 }
4137 }
Michael Jurka22143132012-10-04 17:42:38 +02004138
Winson Chung9d9d74f2011-09-19 11:49:12 -07004139 private void removeCling(int id) {
4140 final View cling = findViewById(id);
4141 if (cling != null) {
4142 final ViewGroup parent = (ViewGroup) cling.getParent();
4143 parent.post(new Runnable() {
4144 @Override
4145 public void run() {
4146 parent.removeView(cling);
4147 }
4148 });
Michael Jurka22143132012-10-04 17:42:38 +02004149 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004150 }
4151 }
Michael Jurka974c3862012-05-22 22:00:31 -07004152
4153 private boolean skipCustomClingIfNoAccounts() {
4154 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4155 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4156 if (customCling) {
4157 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004158 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004159 Account[] accounts = am.getAccountsByType("com.google");
4160 return accounts.length == 0;
4161 }
4162 return false;
4163 }
4164
Winson Chung7d7541e2011-09-16 20:14:36 -07004165 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004166 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004167 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07004168 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
4169 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004170 // If we're not using the default workspace layout, replace workspace cling
4171 // with a custom workspace cling (usually specified in an overlay)
4172 // For now, only do this on tablets
4173 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004174 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004175 // Use a custom cling
4176 View cling = findViewById(R.id.workspace_cling);
4177 ViewGroup clingParent = (ViewGroup) cling.getParent();
4178 int clingIndex = clingParent.indexOfChild(cling);
4179 clingParent.removeViewAt(clingIndex);
4180 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4181 clingParent.addView(customCling, clingIndex);
4182 customCling.setId(R.id.workspace_cling);
4183 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004184 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004185 } else {
4186 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004187 }
4188 }
4189 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004190 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004191 if (isClingsEnabled() &&
4192 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004193 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004194 } else {
4195 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004196 }
4197 }
4198 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004199 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004200 if (isClingsEnabled() &&
4201 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4202 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004203 } else {
4204 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004205 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004206 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004207 }
Michael Jurka104c4562013-07-08 18:03:46 -07004208 protected SharedPreferences getSharedPrefs() {
4209 return mSharedPrefs;
4210 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004211 public boolean isFolderClingVisible() {
4212 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004213 if (cling != null) {
4214 return cling.getVisibility() == View.VISIBLE;
4215 }
4216 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004217 }
Winson Chung82f55532011-08-09 14:14:23 -07004218 public void dismissWorkspaceCling(View v) {
4219 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004220 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004221 }
4222 public void dismissAllAppsCling(View v) {
4223 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004224 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4225 }
4226 public void dismissFolderCling(View v) {
4227 Cling cling = (Cling) findViewById(R.id.folder_cling);
4228 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004229 }
4230
Winson Chung80baf5a2010-08-09 16:03:15 -07004231 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004232 * Prints out out state for debugging.
4233 */
4234 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004235 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004236 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004237 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4238 Log.d(TAG, "mRestoring=" + mRestoring);
4239 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4240 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004241 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004242 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004243
Winson Chung785d2eb2011-04-14 16:08:02 -07004244 if (mAppsCustomizeContent != null) {
4245 mAppsCustomizeContent.dumpState();
4246 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004247 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004248 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004249
4250 @Override
4251 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4252 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004253 synchronized (sDumpLogs) {
4254 writer.println(" ");
4255 writer.println("Debug logs: ");
4256 for (int i = 0; i < sDumpLogs.size(); i++) {
4257 writer.println(" " + sDumpLogs.get(i));
4258 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004259 }
4260 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004261
4262 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004263 if (DEBUG_DUMP_LOG) {
4264 synchronized (sDumpLogs) {
4265 Log.d(TAG, "");
4266 Log.d(TAG, "*********************");
4267 Log.d(TAG, "Launcher debug logs: ");
4268 for (int i = 0; i < sDumpLogs.size(); i++) {
4269 Log.d(TAG, " " + sDumpLogs.get(i));
4270 }
4271 Log.d(TAG, "*********************");
4272 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004273 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004274 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004275 }
4276
4277 public static void addDumpLog(String tag, String log, boolean debugLog) {
4278 if (debugLog) {
4279 Log.d(tag, log);
4280 }
Winson Chungede41292013-09-19 16:27:36 -07004281 if (DEBUG_DUMP_LOG) {
4282 sDateStamp.setTime(System.currentTimeMillis());
4283 synchronized (sDumpLogs) {
4284 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004285 }
Winson Chungede41292013-09-19 16:27:36 -07004286 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004287 }
4288
Winson Chungede41292013-09-19 16:27:36 -07004289 public void dumpLogsToLocalData() {
4290 if (DEBUG_DUMP_LOG) {
4291 new Thread("DumpLogsToLocalData") {
4292 @Override
4293 public void run() {
4294 boolean success = false;
4295 sDateStamp.setTime(sRunStart);
4296 String FILENAME = sDateStamp.getMonth() + "-"
4297 + sDateStamp.getDay() + "_"
4298 + sDateStamp.getHours() + "-"
4299 + sDateStamp.getMinutes() + "_"
4300 + sDateStamp.getSeconds() + ".txt";
4301
4302 FileOutputStream fos = null;
4303 File outFile = null;
4304 try {
4305 outFile = new File(getFilesDir(), FILENAME);
4306 outFile.createNewFile();
4307 fos = new FileOutputStream(outFile);
4308 } catch (Exception e) {
4309 e.printStackTrace();
4310 }
4311 if (fos != null) {
4312 PrintWriter writer = new PrintWriter(fos);
4313
4314 writer.println(" ");
4315 writer.println("Debug logs: ");
4316 synchronized (sDumpLogs) {
4317 for (int i = 0; i < sDumpLogs.size(); i++) {
4318 writer.println(" " + sDumpLogs.get(i));
4319 }
4320 }
4321 writer.close();
4322 }
4323 try {
4324 if (fos != null) {
4325 fos.close();
4326 success = true;
4327 }
4328 } catch (IOException e) {
4329 e.printStackTrace();
4330 }
4331 }
4332 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004333 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004334 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004335}
Michael Jurka2763be32011-02-24 11:19:57 -08004336
Michael Jurkaabded662011-03-04 12:06:57 -08004337interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004338 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004339 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004340 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004341 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004342 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004343}