blob: cde36120d40e8f023743df9822464324022c0dcb [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
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;
Winson Chunge6eabff2013-09-24 11:01:23 -0700277 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400278
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700279 private static LocaleConfiguration sLocaleConfiguration = null;
280
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700281 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700282
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700283 private Intent mAppMarketIntent = null;
284
Adam Cohended9f8d2010-11-03 13:25:16 -0700285 // Related to the auto-advancing of widgets
286 private final int ADVANCE_MSG = 1;
287 private final int mAdvanceInterval = 20000;
288 private final int mAdvanceStagger = 250;
289 private long mAutoAdvanceSentTime;
290 private long mAutoAdvanceTimeLeft = -1;
291 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
292 new HashMap<View, AppWidgetProviderInfo>();
293
Winson Chung400438b2011-01-16 17:53:48 -0800294 // Determines how long to wait after a rotation before restoring the screen orientation to
295 // match the sensor state.
296 private final int mRestoreScreenOrientationDelay = 500;
297
Michael Jurka4ef207b2010-11-29 17:05:45 -0800298 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700299 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800302
Craig Mautner360310b2012-10-26 15:13:08 -0700303 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700304
Adam Cohen1462de32012-07-24 22:34:36 -0700305 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
306
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700307 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700308 static Date sDateStamp = new Date();
309 static DateFormat sDateFormat =
310 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
311 static long sRunStart = System.currentTimeMillis();
312 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Adam Cohene25af792013-06-06 23:08:25 -0700318 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
319
Winson Chungf0c6ae02012-03-21 16:10:31 -0700320 // Holds the page that we need to animate to, and the icon views that we need to animate up
321 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700322 private ImageView mFolderIconImageView;
323 private Bitmap mFolderIconBitmap;
324 private Canvas mFolderIconCanvas;
325 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700326
Michael Jurkaddd62e92011-02-16 17:49:14 -0800327 private BubbleTextView mWaitingForResume;
328
Michael Jurka22143132012-10-04 17:42:38 +0200329 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
330 = new HideFromAccessibilityHelper();
331
Michael Jurkac1f5d262011-09-30 19:32:27 -0700332 private Runnable mBuildLayersRunnable = new Runnable() {
333 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700334 if (mWorkspace != null) {
335 mWorkspace.buildPageHardwareLayers();
336 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700337 }
338 };
339
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800340 private static ArrayList<PendingAddArguments> sPendingAddList
341 = new ArrayList<PendingAddArguments>();
342
Michael Jurka0a457bf2012-11-19 14:05:05 -0800343 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
344
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800345 private static class PendingAddArguments {
346 int requestCode;
347 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700348 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700349 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800350 int cellX;
351 int cellY;
352 }
353
Daniel Sandlerff02d492013-08-05 02:12:05 -0400354 private Stats mStats;
355
Michael Jurka0a457bf2012-11-19 14:05:05 -0800356 private static boolean isPropertyEnabled(String propertyName) {
357 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700358 }
359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 @Override
361 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700362 if (DEBUG_STRICT_MODE) {
363 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
364 .detectDiskReads()
365 .detectDiskWrites()
366 .detectNetwork() // or .detectAll() for all detectable problems
367 .penaltyLog()
368 .build());
369 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
370 .detectLeakedSqlLiteObjects()
371 .detectLeakedClosableObjects()
372 .penaltyLog()
373 .penaltyDeath()
374 .build());
375 }
376
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400378
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400379 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400380 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700381
382 // Determine the dynamic grid properties
383 Point smallestSize = new Point();
384 Point largestSize = new Point();
385 Point realSize = new Point();
386 Display display = getWindowManager().getDefaultDisplay();
387 display.getCurrentSizeRange(smallestSize, largestSize);
388 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700389 DisplayMetrics dm = new DisplayMetrics();
390 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700391 // Lazy-initialize the dynamic grid
392 DeviceProfile grid = app.initDynamicGrid(this,
393 Math.min(smallestSize.x, smallestSize.y),
394 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700395 realSize.x, realSize.y,
396 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700397
398 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400399 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700400 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800401 mModel = app.setLauncher(this);
402 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400403 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700405
Daniel Sandlerff02d492013-08-05 02:12:05 -0400406 mStats = new Stats(this);
407
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700408 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700409 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
410 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700411
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700412 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
413 // this also ensures that any synchronous binding below doesn't re-trigger another
414 // LauncherModel load.
415 mPaused = false;
416
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800417 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200418 android.os.Debug.startMethodTracing(
419 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 }
421
422 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800423 setContentView(R.layout.launcher);
424 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100425 grid.layout(this);
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);
Winson Chungaf40f202013-09-18 18:26:31 -0700467
468 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700469 }
470
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 protected void onUserLeaveHint() {
472 super.onUserLeaveHint();
473 sPausedFromUserAction = true;
474 }
475
Winson Chung98ca0f72013-07-29 12:58:51 -0700476 /** To be overriden by subclasses to hint to Launcher that we have custom content */
477 protected boolean hasCustomContentToLeft() {
478 return false;
479 }
480
Dave Hawkeya8881582013-09-17 15:55:33 -0600481 /**
482 * To be overridden by subclasses to create the custom content and call
483 * {@link #addToCustomContentPage}. This will only be invoked if
484 * {@link #hasCustomContentToLeft()} is {@code true}.
485 */
486 protected void addCustomContentToLeft() {
487 }
488
489 /**
490 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
491 * ensure the custom content page is added or removed if necessary.
492 */
493 protected void invalidateHasCustomContentToLeft() {
494 if (mWorkspace.getScreenOrder().isEmpty()) {
495 // Not bound yet, wait for bindScreens to be called.
496 return;
497 }
498
499 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
500 // Create the custom content page and call the subclass to populate it.
501 mWorkspace.createCustomContentPage();
502 addCustomContentToLeft();
503 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
504 mWorkspace.removeCustomContentPage();
505 }
506 }
507
Adam Cohenf9426d52012-06-04 17:26:21 -0700508 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700509 boolean searchVisible = false;
510 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800511 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700512 int coi = getCurrentOrientationIndexForGlobalIcons();
513 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
514 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700515 updateAppMarketIcon();
516 searchVisible = updateGlobalSearchIcon();
517 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700518 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700519 if (sGlobalSearchIcon[coi] != null) {
520 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700521 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700522 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700523 if (sVoiceSearchIcon[coi] != null) {
524 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700525 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700526 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700527 if (sAppMarketIcon[coi] != null) {
528 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800529 }
Winson Chungadf0c182012-08-23 14:59:07 -0700530 if (mSearchDropTargetBar != null) {
531 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
532 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800533 }
Romain Guycbb89e42009-06-08 15:52:54 -0700534
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800535 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700536 if (sLocaleConfiguration == null) {
537 new AsyncTask<Void, Void, LocaleConfiguration>() {
538 @Override
539 protected LocaleConfiguration doInBackground(Void... unused) {
540 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
541 readConfiguration(Launcher.this, localeConfiguration);
542 return localeConfiguration;
543 }
544
545 @Override
546 protected void onPostExecute(LocaleConfiguration result) {
547 sLocaleConfiguration = result;
548 checkForLocaleChange(); // recursive, but now with a locale configuration
549 }
550 }.execute();
551 return;
552 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700553
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800554 final Configuration configuration = getResources().getConfiguration();
555
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700556 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800557 final String locale = configuration.locale.toString();
558
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700559 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 final int mcc = configuration.mcc;
561
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700562 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 final int mnc = configuration.mnc;
564
Romain Guy84f296c2009-11-04 15:00:44 -0800565 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566
Romain Guy84f296c2009-11-04 15:00:44 -0800567 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 sLocaleConfiguration.locale = locale;
569 sLocaleConfiguration.mcc = mcc;
570 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700571
Joe Onorato0589f0f2010-02-08 13:44:00 -0800572 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700573
574 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
575 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700576 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700577 public void run() {
578 writeConfiguration(Launcher.this, localeConfiguration);
579 }
580 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700581 }
582 }
583
584 private static class LocaleConfiguration {
585 public String locale;
586 public int mcc = -1;
587 public int mnc = -1;
588 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700589
Romain Guy98d01652009-06-30 16:21:04 -0700590 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
591 DataInputStream in = null;
592 try {
593 in = new DataInputStream(context.openFileInput(PREFERENCES));
594 configuration.locale = in.readUTF();
595 configuration.mcc = in.readInt();
596 configuration.mnc = in.readInt();
597 } catch (FileNotFoundException e) {
598 // Ignore
599 } catch (IOException e) {
600 // Ignore
601 } finally {
602 if (in != null) {
603 try {
604 in.close();
605 } catch (IOException e) {
606 // Ignore
607 }
608 }
609 }
610 }
611
612 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
613 DataOutputStream out = null;
614 try {
615 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
616 out.writeUTF(configuration.locale);
617 out.writeInt(configuration.mcc);
618 out.writeInt(configuration.mnc);
619 out.flush();
620 } catch (FileNotFoundException e) {
621 // Ignore
622 } catch (IOException e) {
623 //noinspection ResultOfMethodCallIgnored
624 context.getFileStreamPath(PREFERENCES).delete();
625 } finally {
626 if (out != null) {
627 try {
628 out.close();
629 } catch (IOException e) {
630 // Ignore
631 }
632 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 }
634 }
635
Bjorn Bringertc459e522013-06-07 19:36:01 +0100636 public LayoutInflater getInflater() {
637 return mInflater;
638 }
639
Adam Cohen716b51e2011-06-30 12:09:54 -0700640 public DragLayer getDragLayer() {
641 return mDragLayer;
642 }
643
Winson Chung36a62fe2012-05-06 18:04:42 -0700644 boolean isDraggingEnabled() {
645 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
646 // that is subsequently removed from the workspace in startBinding().
647 return !mModel.isLoadingWorkspace();
648 }
649
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650 static int getScreen() {
651 synchronized (sLock) {
652 return sScreen;
653 }
654 }
655
656 static void setScreen(int screen) {
657 synchronized (sLock) {
658 sScreen = screen;
659 }
660 }
661
Winson Chung557d6ed2011-07-08 15:34:52 -0700662 /**
663 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
664 * a configuration step, this allows the proper animations to run after other transitions.
665 */
666 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700667 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800668 switch (args.requestCode) {
669 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700670 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700671 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800672 break;
673 case REQUEST_PICK_SHORTCUT:
674 processShortcut(args.intent);
675 break;
676 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700677 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700678 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700679 result = true;
680 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800681 case REQUEST_CREATE_APPWIDGET:
682 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700683 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700684 result = true;
685 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 }
Michael Jurka27614d22012-04-02 06:40:22 -0700687 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
688 // if you turned the screen off and then back while in All Apps, Launcher would not
689 // return to the workspace. Clearing mAddInfo.container here fixes this issue
690 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700691 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800692 }
693
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700695 protected void onActivityResult(
696 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700697 // Reset the startActivity waiting flag
698 mWaitingForResult = false;
699
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 if (requestCode == REQUEST_BIND_APPWIDGET) {
701 int appWidgetId = data != null ?
702 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
703 if (resultCode == RESULT_CANCELED) {
704 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
705 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700706 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700707 }
708 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200709 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
710 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
711 mWorkspace.exitOverviewMode(false);
712 }
713 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700714 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200715
Winson Chung557d6ed2011-07-08 15:34:52 -0700716 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800717 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
718 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700719
Adam Cohened66b2b2012-01-23 17:28:51 -0800720 // We have special handling for widgets
721 if (isWidgetDrop) {
722 int appWidgetId = data != null ?
723 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700724 if (appWidgetId < 0) {
725 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
726 "widget configuration activity.");
727 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
728 } else {
729 completeTwoStageWidgetDrop(resultCode, appWidgetId);
730 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800731 return;
732 }
733
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 // The pattern used here is that a user PICKs a specific application,
735 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700736
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
738 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700739 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 final PendingAddArguments args = new PendingAddArguments();
741 args.requestCode = requestCode;
742 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700743 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700744 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700745 args.cellX = mPendingAddInfo.cellX;
746 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 if (isWorkspaceLocked()) {
748 sPendingAddList.add(args);
749 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700750 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800753 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700754 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800755 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
756 null);
757 }
758
759 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700761 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800762 Runnable onCompleteRunnable = null;
763 int animationType = 0;
764
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700765 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800766 if (resultCode == RESULT_OK) {
767 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
768 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700769 mPendingAddWidgetInfo);
770 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 onCompleteRunnable = new Runnable() {
772 @Override
773 public void run() {
774 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700775 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
777 null);
778 }
779 };
780 } else if (resultCode == RESULT_CANCELED) {
781 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
782 onCompleteRunnable = new Runnable() {
783 @Override
784 public void run() {
785 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
786 null);
787 }
788 };
789 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700790 if (mDragLayer.getAnimatedView() != null) {
791 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
792 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
793 animationType, boundWidget, true);
794 } else {
795 // The animated view may be null in the case of a rotation during widget configuration
796 onCompleteRunnable.run();
797 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800798 }
799
800 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700801 protected void onStop() {
802 super.onStop();
803 FirstFrameAnimatorHelper.setIsVisible(false);
804 }
805
806 @Override
807 protected void onStart() {
808 super.onStart();
809 FirstFrameAnimatorHelper.setIsVisible(true);
810 }
811
812 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200814 long startTime = 0;
815 if (DEBUG_RESUME_TIME) {
816 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400817 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200818 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700820
Winson Chung4a2afa32012-07-19 14:53:05 -0700821 // Restore the previous launcher state
822 if (mOnResumeState == State.WORKSPACE) {
823 showWorkspace(false);
824 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700825 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700826 }
827 mOnResumeState = State.NONE;
828
Craig Mautner360310b2012-10-26 15:13:08 -0700829 // Background was set to gradient in onPause(), restore to black if in all apps.
830 setWorkspaceBackground(mState == State.WORKSPACE);
831
Winson Chungde0fb8f2012-05-08 14:37:08 -0700832 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700833 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700834
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800835 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700836 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700837 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400838 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700839 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400840 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700841 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700843 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200844 // We might have postponed some bind calls until onResume (see waitUntilResume) --
845 // execute them here
846 long startTimeCallbacks = 0;
847 if (DEBUG_RESUME_TIME) {
848 startTimeCallbacks = System.currentTimeMillis();
849 }
850
851 if (mAppsCustomizeContent != null) {
852 mAppsCustomizeContent.setBulkBind(true);
853 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700854 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
855 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200856 }
857 if (mAppsCustomizeContent != null) {
858 mAppsCustomizeContent.setBulkBind(false);
859 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700860 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200861 if (DEBUG_RESUME_TIME) {
862 Log.d(TAG, "Time spent processing callbacks in onResume: " +
863 (System.currentTimeMillis() - startTimeCallbacks));
864 }
Michael Jurka447bf842013-05-15 14:52:15 +0200865 }
Michael Jurka54554252013-08-01 12:52:23 +0200866 if (mOnResumeCallbacks.size() > 0) {
867 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
868 mOnResumeCallbacks.get(i).run();
869 }
870 mOnResumeCallbacks.clear();
871 }
Winson Chunge4e50662012-01-23 14:45:13 -0800872
873 // Reset the pressed state of icons that were locked in the press state while activities
874 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800875 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800876 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800877 mWaitingForResume.setStayPressed(false);
878 }
Winson Chunge4e50662012-01-23 14:45:13 -0800879 if (mAppsCustomizeContent != null) {
880 // Resets the previous all apps icon press state
881 mAppsCustomizeContent.resetDrawableState();
882 }
Adam Cohen06dff352012-06-01 17:17:08 -0700883 // It is possible that widgets can receive updates while launcher is not in the foreground.
884 // Consequently, the widgets will be inflated in the orientation of the foreground activity
885 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
886 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700887 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700888
889 // Again, as with the above scenario, it's possible that one or more of the global icons
890 // were updated in the wrong orientation.
891 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200892 if (DEBUG_RESUME_TIME) {
893 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
894 }
Adam Cohen06dff352012-06-01 17:17:08 -0700895 }
896
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700898 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700899 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
900 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
901 // when Launcher resumes and we are still in AllApps.
902 updateWallpaperVisibility(true);
903
Winson Chung997a9232013-07-24 15:33:46 -0700904 // Ensure that items added to Launcher are queued until Launcher returns
905 InstallShortcutReceiver.enableInstallQueue();
906
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700907 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700908 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800909 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700910 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700911 }
Romain Guycbb89e42009-06-08 15:52:54 -0700912
Adam Cohen66a01fd2013-06-11 12:48:00 -0700913 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600914 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
915 addCustomContentToLeft();
916 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700917 }
918
Adam Cohenbffe7452013-07-22 18:21:45 -0700919 QSBScroller mQsbScroller = new QSBScroller() {
920 int scrollY = 0;
921
922 @Override
923 public void setScrollY(int scroll) {
924 scrollY = scroll;
925
926 if (mWorkspace.isOnOrMovingToCustomContent()) {
927 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100928 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700929 }
930 }
931 };
932
933 public void resetQSBScroll() {
934 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100935 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700936 }
937
938 public interface CustomContentCallbacks {
939 // Custom content is completely shown
940 public void onShow();
941
942 // Custom content is completely hidden
943 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700944
945 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
946 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700947 }
948
Adam Cohen30bacb22013-08-29 14:25:25 -0700949 protected void startSettings() {
950 }
951
Adam Cohenbffe7452013-07-22 18:21:45 -0700952 public interface QSBScroller {
953 public void setScrollY(int scrollY);
954 }
955
Adam Cohen66a01fd2013-06-11 12:48:00 -0700956 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700957 public QSBScroller addToCustomContentPage(View customContent) {
958 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 }
960
Winson Chung98ca0f72013-07-29 12:58:51 -0700961 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700962 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700963 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700964 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700965 }
966
Adam Cohenedb40762013-07-18 16:45:45 -0700967 // The custom content needs to offset its content to account for the QSB
968 public int getTopOffsetForCustomContent() {
969 return mWorkspace.getPaddingTop();
970 }
971
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700972 @Override
973 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400974 // Flag the loader to stop early before switching
975 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700976 if (mAppsCustomizeContent != null) {
977 mAppsCustomizeContent.surrender();
978 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800979 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700980 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700981
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800982 // We can't hide the IME if it was forced open. So don't bother
983 /*
984 @Override
985 public void onWindowFocusChanged(boolean hasFocus) {
986 super.onWindowFocusChanged(hasFocus);
987
988 if (hasFocus) {
989 final InputMethodManager inputManager = (InputMethodManager)
990 getSystemService(Context.INPUT_METHOD_SERVICE);
991 WindowManager.LayoutParams lp = getWindow().getAttributes();
992 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
993 android.os.Handler()) {
994 protected void onReceiveResult(int resultCode, Bundle resultData) {
995 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
996 }
997 });
998 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
999 }
1000 }
1001 */
1002
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 private boolean acceptFilter() {
1004 final InputMethodManager inputManager = (InputMethodManager)
1005 getSystemService(Context.INPUT_METHOD_SERVICE);
1006 return !inputManager.isFullscreenMode();
1007 }
1008
1009 @Override
1010 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001011 final int uniChar = event.getUnicodeChar();
1012 final boolean handled = super.onKeyDown(keyCode, event);
1013 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1014 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1016 keyCode, event);
1017 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001018 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001019 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001020 // showSearchDialog()
1021 // If there are multiple keystrokes before the search dialog takes focus,
1022 // onSearchRequested() will be called for every keystroke,
1023 // but it is idempotent, so it's fine.
1024 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025 }
1026 }
1027
Joe Onorato8a9625e2010-01-28 15:55:35 -08001028 // Eat the long press event so the keyboard doesn't come up.
1029 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1030 return true;
1031 }
1032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 return handled;
1034 }
1035
Karl Rosaen138a0412009-04-23 19:00:21 -07001036 private String getTypedText() {
1037 return mDefaultKeySsb.toString();
1038 }
1039
1040 private void clearTypedText() {
1041 mDefaultKeySsb.clear();
1042 mDefaultKeySsb.clearSpans();
1043 Selection.setSelection(mDefaultKeySsb, 0);
1044 }
1045
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001047 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1048 * State
1049 */
1050 private static State intToState(int stateOrdinal) {
1051 State state = State.WORKSPACE;
1052 final State[] stateValues = State.values();
1053 for (int i = 0; i < stateValues.length; i++) {
1054 if (stateValues[i].ordinal() == stateOrdinal) {
1055 state = stateValues[i];
1056 break;
1057 }
1058 }
1059 return state;
1060 }
1061
1062 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 * Restores the previous state, if it exists.
1064 *
1065 * @param savedState The previous state.
1066 */
1067 private void restoreState(Bundle savedState) {
1068 if (savedState == null) {
1069 return;
1070 }
1071
Michael Jurka883f55b2010-10-21 15:47:14 -07001072 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001073 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001074 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001075 }
1076
Winson Chungf0c6ae02012-03-21 16:10:31 -07001077 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001079 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 }
1081
Winson Chung3d503fb2011-07-13 17:25:49 -07001082 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001083 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001084
Winson Chung3d503fb2011-07-13 17:25:49 -07001085 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1086 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001087 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1089 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001090 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1091 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1092 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001093 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 mRestoring = true;
1095 }
1096
1097 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1098 if (renameFolder) {
1099 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001100 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 mRestoring = true;
1102 }
Winson Chunga12a2502010-12-20 14:41:35 -08001103
Winson Chung785d2eb2011-04-14 16:08:02 -07001104 // Restore the AppsCustomize tab
1105 if (mAppsCustomizeTabHost != null) {
1106 String curTab = savedState.getString("apps_customize_currentTab");
1107 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001108 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001109 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001110 mAppsCustomizeContent.loadAssociatedPages(
1111 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 }
1113
Winson Chung5afbf7b2011-07-25 11:53:08 -07001114 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1115 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 }
1118
1119 /**
1120 * Finds all the views we need and configure them properly.
1121 */
1122 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001123 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001124
Craig Mautner360310b2012-10-26 15:13:08 -07001125 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001126 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1127 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001128
John Spurlock77e1f472013-09-11 10:09:51 -04001129 mLauncherView.setSystemUiVisibility(
1130 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001131 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132
Winson Chung4c98d922011-05-31 16:50:48 -07001133 // Setup the drag layer
1134 mDragLayer.setup(this, dragController);
1135
Winson Chung3d503fb2011-07-13 17:25:49 -07001136 // Setup the hotseat
1137 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1138 if (mHotseat != null) {
1139 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001140 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001141 }
1142
Adam Cohenf358a4b2013-07-23 16:47:31 -07001143 mOverviewPanel = findViewById(R.id.overview_panel);
1144 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1145 @Override
1146 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001147 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001148 }
1149 });
1150 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1151 @Override
1152 public void onClick(View arg0) {
1153 startWallpaper();
1154 }
1155 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001156 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1157 @Override
1158 public void onClick(View arg0) {
1159 startSettings();
1160 }
1161 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001162 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001163
Winson Chung4c98d922011-05-31 16:50:48 -07001164 // Setup the workspace
1165 mWorkspace.setHapticFeedbackEnabled(false);
1166 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001167 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001168 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001169
Winson Chungf0ea4d32011-06-06 14:27:16 -07001170 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001171 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001172
Winson Chungf0ea4d32011-06-06 14:27:16 -07001173 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001174 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001175 mAppsCustomizeContent = (AppsCustomizePagedView)
1176 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1177 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001178
Winson Chung3d503fb2011-07-13 17:25:49 -07001179 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001180 dragController.setDragScoller(mWorkspace);
1181 dragController.setScrollView(mDragLayer);
1182 dragController.setMoveTarget(mWorkspace);
1183 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001184 if (mSearchDropTargetBar != null) {
1185 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001186 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001187
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001188 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001189 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001190 mWeightWatcher = new WeightWatcher(this);
1191 mWeightWatcher.setAlpha(0.5f);
1192 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001193 new FrameLayout.LayoutParams(
1194 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001195 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 Gravity.BOTTOM)
1197 );
Adam Cohen39a06042013-07-19 14:30:12 -07001198
1199 boolean show = shouldShowWeightWatcher();
1200 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001201 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 }
1203
1204 /**
1205 * Creates a view representing a shortcut.
1206 *
1207 * @param info The data structure describing the shortcut.
1208 *
1209 * @return A View inflated from R.layout.application.
1210 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001211 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001213 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214 }
1215
1216 /**
1217 * Creates a view representing a shortcut inflated from the specified resource.
1218 *
1219 * @param layoutResId The id of the XML layout used to create the shortcut.
1220 * @param parent The group the shortcut belongs to.
1221 * @param info The data structure describing the shortcut.
1222 *
1223 * @return A View inflated from layoutResId.
1224 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001225 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001226 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1227 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 return favorite;
1230 }
1231
1232 /**
1233 * Add an application shortcut to the workspace.
1234 *
1235 * @param data The intent describing the application.
1236 * @param cellInfo The position on screen where to create the shortcut.
1237 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001238 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001239 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001240 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001241
Adam Cohenfbba09b2011-07-18 21:43:05 -07001242 // First we check if we already know the exact location where we want to add this item.
1243 if (cellX >= 0 && cellY >= 0) {
1244 cellXY[0] = cellX;
1245 cellXY[1] = cellY;
1246 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001247 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001248 return;
1249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001251 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001252
Romain Guy73b979d2009-06-09 12:57:21 -07001253 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001254 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001256 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001257 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001258 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001259 } else {
1260 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 }
1262 }
Romain Guycbb89e42009-06-08 15:52:54 -07001263
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 /**
1265 * Add a shortcut to the workspace.
1266 *
1267 * @param data The intent describing the shortcut.
1268 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001269 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001270 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001271 int cellY) {
1272 int[] cellXY = mTmpAddItemCellCoordinates;
1273 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001275
Michael Jurkad3ef3062010-11-23 16:23:58 -08001276 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001277
Adam Cohen558baaf2011-08-15 15:22:57 -07001278 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001279 if (info == null) {
1280 return;
1281 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001282 final View view = createShortcut(info);
1283
Adam Cohenfbba09b2011-07-18 21:43:05 -07001284 // First we check if we already know the exact location where we want to add this item.
1285 if (cellX >= 0 && cellY >= 0) {
1286 cellXY[0] = cellX;
1287 cellXY[1] = cellY;
1288 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001289
1290 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001291 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001292 true, null,null)) {
1293 return;
1294 }
1295 DragObject dragObject = new DragObject();
1296 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001297 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1298 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001299 return;
1300 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001302 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001303 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001304 foundCellSpan = (result != null);
1305 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001306 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001307 }
1308
1309 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001310 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001311 return;
1312 }
1313
Adam Cohendcd297f2013-06-18 13:13:40 -07001314 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315
1316 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001317 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001318 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 }
1320 }
1321
Adam Cohen2f093b62012-04-30 18:59:53 -07001322 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1323 int minHeight) {
1324 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001325 // We want to account for the extra amount of padding that we are adding to the widget
1326 // to ensure that it gets the full amount of space that it has requested
1327 int requiredWidth = minWidth + padding.left + padding.right;
1328 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001329 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001330 }
1331
Adam Cohen2f093b62012-04-30 18:59:53 -07001332 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1333 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1337 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001338 }
1339
Adam Cohen2f093b62012-04-30 18:59:53 -07001340 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1341 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001342 }
1343
Adam Cohen2f093b62012-04-30 18:59:53 -07001344 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1345 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001346 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001347 }
1348
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001350 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001352 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001353 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001355 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001356 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1357 if (appWidgetInfo == null) {
1358 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1359 }
Romain Guycbb89e42009-06-08 15:52:54 -07001360
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001361 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001362 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001363
Adam Cohen2f093b62012-04-30 18:59:53 -07001364 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1365 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001366
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001368 // We have saved the position to which the widget was dragged-- this really only matters
1369 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 int[] cellXY = mTmpAddItemCellCoordinates;
1371 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001372 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001373 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1375 cellXY[0] = mPendingAddInfo.cellX;
1376 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001377 spanXY[0] = mPendingAddInfo.spanX;
1378 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001379 foundCellSpan = true;
1380 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001381 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001382 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001383 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1384 spanXY[1], cellXY, finalSpan);
1385 spanXY[0] = finalSpan[0];
1386 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001387 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001389 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001390 }
1391
Michael Jurka0280c3b2010-09-17 15:00:07 -07001392 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001393 if (appWidgetId != -1) {
1394 // Deleting an app widget ID is a void call but writes to disk before returning
1395 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001396 new Thread("deleteAppWidgetId") {
1397 public void run() {
1398 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1399 }
1400 }.start();
1401 }
Winson Chung93eef082012-03-23 15:59:27 -07001402 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001403 return;
1404 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001405
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001406 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001407 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1408 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 launcherInfo.spanX = spanXY[0];
1410 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001411 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1412 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001413
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001415 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416
1417 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001418 if (hostView == null) {
1419 // Perform actual inflation because we're live
1420 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1421 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1422 } else {
1423 // The AppWidgetHostView has already been inflated and instantiated
1424 launcherInfo.hostView = hostView;
1425 }
Romain Guycbb89e42009-06-08 15:52:54 -07001426
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001428 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001429 launcherInfo.notifyWidgetSizeChanged(this);
1430
Adam Cohendcd297f2013-06-18 13:13:40 -07001431 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001432 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001433
1434 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001436 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001437 }
Romain Guycbb89e42009-06-08 15:52:54 -07001438
Adam Cohended9f8d2010-11-03 13:25:16 -07001439 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1440 @Override
1441 public void onReceive(Context context, Intent intent) {
1442 final String action = intent.getAction();
1443 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1444 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001445 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001446 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001447
Winson Chungc100e8e2011-08-09 16:02:43 -07001448 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001449 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001450 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001451 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001452 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001453 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1454 mUserPresent = true;
1455 updateRunning();
1456 }
1457 }
1458 };
1459
1460 @Override
1461 public void onAttachedToWindow() {
1462 super.onAttachedToWindow();
1463
1464 // Listen for broadcasts related to user-presence
1465 final IntentFilter filter = new IntentFilter();
1466 filter.addAction(Intent.ACTION_SCREEN_OFF);
1467 filter.addAction(Intent.ACTION_USER_PRESENT);
1468 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001469 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001470 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001471 mVisible = true;
1472 }
1473
1474 @Override
1475 public void onDetachedFromWindow() {
1476 super.onDetachedFromWindow();
1477 mVisible = false;
1478
Adam Cohend113e0c2010-11-11 10:48:05 -08001479 if (mAttached) {
1480 unregisterReceiver(mReceiver);
1481 mAttached = false;
1482 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001483 updateRunning();
1484 }
1485
1486 public void onWindowVisibilityChanged(int visibility) {
1487 mVisible = visibility == View.VISIBLE;
1488 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001489 // The following code used to be in onResume, but it turns out onResume is called when
1490 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1491 // is a more appropriate event to handle
1492 if (mVisible) {
1493 mAppsCustomizeTabHost.onWindowVisible();
1494 if (!mWorkspaceLoading) {
1495 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001496 // We want to let Launcher draw itself at least once before we force it to build
1497 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001498 // apps is nice and speedy.
1499 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001500 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001501 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001502 if (mStarted) return;
1503 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001504 // We delay the layer building a bit in order to give
1505 // other message processing a time to run. In particular
1506 // this avoids a delay in hiding the IME if it was
1507 // currently shown, because doing that may involve
1508 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001509 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001510 final ViewTreeObserver.OnDrawListener listener = this;
1511 mWorkspace.post(new Runnable() {
1512 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001513 if (mWorkspace != null &&
1514 mWorkspace.getViewTreeObserver() != null) {
1515 mWorkspace.getViewTreeObserver().
1516 removeOnDrawListener(listener);
1517 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001518 }
1519 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001520 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001521 }
1522 });
1523 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001524 // When Launcher comes back to foreground, a different Activity might be responsible for
1525 // the app market intent, so refresh the icon
1526 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001527 clearTypedText();
1528 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001529 }
1530
1531 private void sendAdvanceMessage(long delay) {
1532 mHandler.removeMessages(ADVANCE_MSG);
1533 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1534 mHandler.sendMessageDelayed(msg, delay);
1535 mAutoAdvanceSentTime = System.currentTimeMillis();
1536 }
1537
1538 private void updateRunning() {
1539 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1540 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1541 mAutoAdvanceRunning = autoAdvanceRunning;
1542 if (autoAdvanceRunning) {
1543 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1544 sendAdvanceMessage(delay);
1545 } else {
1546 if (!mWidgetsToAdvance.isEmpty()) {
1547 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1548 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1549 }
1550 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001551 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001552 }
1553 }
1554 }
1555
1556 private final Handler mHandler = new Handler() {
1557 @Override
1558 public void handleMessage(Message msg) {
1559 if (msg.what == ADVANCE_MSG) {
1560 int i = 0;
1561 for (View key: mWidgetsToAdvance.keySet()) {
1562 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1563 final int delay = mAdvanceStagger * i;
1564 if (v instanceof Advanceable) {
1565 postDelayed(new Runnable() {
1566 public void run() {
1567 ((Advanceable) v).advance();
1568 }
1569 }, delay);
1570 }
1571 i++;
1572 }
1573 sendAdvanceMessage(mAdvanceInterval);
1574 }
1575 }
1576 };
1577
1578 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001579 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001580 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1581 if (v instanceof Advanceable) {
1582 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001583 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 updateRunning();
1585 }
1586 }
1587
1588 void removeWidgetToAutoAdvance(View hostView) {
1589 if (mWidgetsToAdvance.containsKey(hostView)) {
1590 mWidgetsToAdvance.remove(hostView);
1591 updateRunning();
1592 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001593 }
1594
Joe Onorato9c1289c2009-08-17 11:03:03 -04001595 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001597 launcherInfo.hostView = null;
1598 }
1599
Winson Chung93eef082012-03-23 15:59:27 -07001600 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1601 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1602 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 }
1604
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001605 public LauncherAppWidgetHost getAppWidgetHost() {
1606 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607 }
Romain Guycbb89e42009-06-08 15:52:54 -07001608
Winson Chunga9abd0e2010-10-27 17:18:37 -07001609 public LauncherModel getModel() {
1610 return mModel;
1611 }
1612
Bjorn Bringertc459e522013-06-07 19:36:01 +01001613 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001614 getWindow().closeAllPanels();
1615
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001616 // Whatever we were doing is hereby canceled.
1617 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001618 }
1619
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 @Override
1621 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001622 long startTime = 0;
1623 if (DEBUG_RESUME_TIME) {
1624 startTime = System.currentTimeMillis();
1625 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 super.onNewIntent(intent);
1627
1628 // Close the menu
1629 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001630 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001631 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001632
Jamie Genniscb222e82012-10-23 15:44:26 -07001633 final boolean alreadyOnHome =
1634 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001635 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001636
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 Runnable processIntent = new Runnable() {
1638 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001639 if (mWorkspace == null) {
1640 // Can be cases where mWorkspace is null, this prevents a NPE
1641 return;
1642 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001643 Folder openFolder = mWorkspace.getOpenFolder();
1644 // In all these cases, only animate if we're already on home
1645 mWorkspace.exitWidgetResizeMode();
1646 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1647 openFolder == null) {
1648 mWorkspace.moveToDefaultScreen(true);
1649 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001650
Jamie Genniscb222e82012-10-23 15:44:26 -07001651 closeFolder();
1652 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001653
Jamie Genniscb222e82012-10-23 15:44:26 -07001654 // If we are already on home, then just animate back to the workspace,
1655 // otherwise, just wait until onResume to set the state back to Workspace
1656 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001657 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 } else {
1659 mOnResumeState = State.WORKSPACE;
1660 }
1661
1662 final View v = getWindow().peekDecorView();
1663 if (v != null && v.getWindowToken() != null) {
1664 InputMethodManager imm = (InputMethodManager)getSystemService(
1665 INPUT_METHOD_SERVICE);
1666 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1667 }
1668
Winson Chung7819a562013-09-19 15:55:45 -07001669 // Reset the apps customize page
1670 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001671 mAppsCustomizeTabHost.reset();
1672 }
1673 }
1674 };
1675
1676 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1677 // Delay processing of the intent to allow the status bar animation to finish
1678 // first in order to avoid janky animations.
1679 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001680 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001681 // Process the intent immediately.
1682 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001683 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001684
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685 }
Michael Jurka447bf842013-05-15 14:52:15 +02001686 if (DEBUG_RESUME_TIME) {
1687 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1688 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
1690
Adam Cohen040a5d22013-09-16 17:09:33 -07001691 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1692 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001693 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001694 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001695 }
1696 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001697 protected void showWorkspaceAndExitOverviewMode() {
1698 showWorkspaceAndExitOverviewMode(true);
1699 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001700
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001702 public void onRestoreInstanceState(Bundle state) {
1703 super.onRestoreInstanceState(state);
1704 for (int page: mSynchronouslyBoundPages) {
1705 mWorkspace.restoreInstanceStateForChild(page);
1706 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 }
1708
1709 @Override
1710 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001711 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001712 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713
Michael Jurka883f55b2010-10-21 15:47:14 -07001714 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001715 // We close any open folder since it will not be re-opened, and we need to make sure
1716 // this state is reflected.
1717 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718
Adam Cohendcd297f2013-06-18 13:13:40 -07001719 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001720 mWaitingForResult) {
1721 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001722 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001723 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1724 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001725 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1726 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1727 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 }
1729
1730 if (mFolderInfo != null && mWaitingForResult) {
1731 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1732 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1733 }
Michael Jurka946ad472010-07-09 18:05:18 -07001734
Winson Chung785d2eb2011-04-14 16:08:02 -07001735 // Save the current AppsCustomize tab
1736 if (mAppsCustomizeTabHost != null) {
1737 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1738 if (currentTabTag != null) {
1739 outState.putString("apps_customize_currentTab", currentTabTag);
1740 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001741 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1742 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001743 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745
1746 @Override
1747 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001749
Winson Chunge7a03942011-08-05 15:05:12 -07001750 // Remove all pending runnables
1751 mHandler.removeMessages(ADVANCE_MSG);
1752 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001753 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001754
Winson Chungcd2b0142011-06-08 16:02:26 -07001755 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001756 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001757 mModel.stopLoader();
1758 app.setLauncher(null);
1759
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001761 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001763 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001765 mAppWidgetHost = null;
1766
1767 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768
1769 TextKeyListener.getInstance().release();
1770
Winson Chung81b52252012-08-27 15:34:29 -07001771 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1772 // to prevent leaking Launcher activities on orientation change.
1773 if (mModel != null) {
1774 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1775 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001776
1777 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001778 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001779
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001780 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001781 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1782 mWorkspace.removeAllViews();
1783 mWorkspace = null;
1784 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001785
Michael Jurka2ecf9952012-06-18 12:52:28 -07001786 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 }
1788
Adam Cohena9cf38f2011-05-02 15:36:58 -07001789 public DragController getDragController() {
1790 return mDragController;
1791 }
1792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 @Override
1794 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001795 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 super.startActivityForResult(intent, requestCode);
1797 }
1798
Winson Chung70d72102011-08-12 11:24:35 -07001799 /**
1800 * Indicates that we want global search for this activity by setting the globalSearch
1801 * argument for {@link #startSearch} to true.
1802 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001804 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001806
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001807 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001808
Karl Rosaen138a0412009-04-23 19:00:21 -07001809 if (initialQuery == null) {
1810 // Use any text typed in the launcher as the initial query
1811 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001812 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001813 if (appSearchData == null) {
1814 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001815 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
Winson Chungadf0c182012-08-23 14:59:07 -07001817 Rect sourceBounds = new Rect();
1818 if (mSearchDropTargetBar != null) {
1819 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1820 }
Romain Guycbb89e42009-06-08 15:52:54 -07001821
Bjorn Bringertc459e522013-06-07 19:36:01 +01001822 startSearch(initialQuery, selectInitialQuery,
1823 appSearchData, sourceBounds);
1824 }
1825
1826 public void startSearch(String initialQuery,
1827 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001828 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001829 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001830 }
1831
1832 /**
1833 * Starts the global search activity. This code is a copied from SearchManager
1834 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001835 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001836 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001837 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001838 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1839 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1840 if (globalSearchActivity == null) {
1841 Log.w(TAG, "No global search activity found.");
1842 return;
1843 }
1844 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1845 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1846 intent.setComponent(globalSearchActivity);
1847 // Make sure that we have a Bundle to put source in
1848 if (appSearchData == null) {
1849 appSearchData = new Bundle();
1850 } else {
1851 appSearchData = new Bundle(appSearchData);
1852 }
1853 // Set source to package name of app that starts global search, if not set already.
1854 if (!appSearchData.containsKey("source")) {
1855 appSearchData.putString("source", getPackageName());
1856 }
1857 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1858 if (!TextUtils.isEmpty(initialQuery)) {
1859 intent.putExtra(SearchManager.QUERY, initialQuery);
1860 }
1861 if (selectInitialQuery) {
1862 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1863 }
1864 intent.setSourceBounds(sourceBounds);
1865 try {
1866 startActivity(intent);
1867 } catch (ActivityNotFoundException ex) {
1868 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1869 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 }
1871
Winson Chung70d72102011-08-12 11:24:35 -07001872 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001873 public boolean onPrepareOptionsMenu(Menu menu) {
1874 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001875 if (!mWorkspace.isInOverviewMode()) {
1876 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001877 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001878 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001879 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001881 @Override
1882 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001883 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001884 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001885 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001886 }
1887
Joe Onorato9c1289c2009-08-17 11:03:03 -04001888 public boolean isWorkspaceLocked() {
1889 return mWorkspaceLoading || mWaitingForResult;
1890 }
1891
Michael Jurka0280c3b2010-09-17 15:00:07 -07001892 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001893 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001894 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001895 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1896 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001897 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001898 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001899 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001900
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001901 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1902 AppWidgetProviderInfo appWidgetInfo) {
1903 if (appWidgetInfo.configure != null) {
1904 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001905
Bjorn Bringert7984c942009-12-09 15:38:25 +00001906 // Launch over to configure widget, if needed
1907 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001908 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001909 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001910 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001912 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001913 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001914 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001915 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001916 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 }
1918 }
Romain Guycbb89e42009-06-08 15:52:54 -07001919
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001920 protected void moveToCustomContentScreen(boolean animate) {
1921 mWorkspace.moveToCustomContentScreen(animate);
1922 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001923 /**
1924 * Process a shortcut drop.
1925 *
1926 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001927 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001928 * @param cell The cell it should be added to, optional
1929 * @param position The location on the screen where it was dropped, optional
1930 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001931 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001932 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001933 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001934 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001935 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001936 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001937
1938 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001939 mPendingAddInfo.cellX = cell[0];
1940 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001941 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001942
1943 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1944 createShortcutIntent.setComponent(componentName);
1945 processShortcut(createShortcutIntent);
1946 }
1947
Adam Cohenfbba09b2011-07-18 21:43:05 -07001948 /**
1949 * Process a widget drop.
1950 *
1951 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001952 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001953 * @param cell The cell it should be added to, optional
1954 * @param position The location on the screen where it was dropped, optional
1955 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001957 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001958 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001960 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001961 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001962 mPendingAddInfo.minSpanX = info.minSpanX;
1963 mPendingAddInfo.minSpanY = info.minSpanY;
1964
Adam Cohenfbba09b2011-07-18 21:43:05 -07001965 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 mPendingAddInfo.cellX = cell[0];
1967 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001968 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001969 if (span != null) {
1970 mPendingAddInfo.spanX = span[0];
1971 mPendingAddInfo.spanY = span[1];
1972 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001973
Adam Cohened66b2b2012-01-23 17:28:51 -08001974 AppWidgetHostView hostView = info.boundWidget;
1975 int appWidgetId;
1976 if (hostView != null) {
1977 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001978 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001979 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001980 // In this case, we either need to start an activity to get permission to bind
1981 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001982 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001983 Bundle options = info.bindOptions;
1984
1985 boolean success = false;
1986 if (options != null) {
1987 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1988 info.componentName, options);
1989 } else {
1990 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1991 info.componentName);
1992 }
1993 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001994 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001995 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001996 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001997 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1998 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1999 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002000 // TODO: we need to make sure that this accounts for the options bundle.
2001 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002002 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2003 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002004 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002005 }
2006
Joe Onoratodeb98af2010-02-19 14:59:39 -08002007 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002008 // Handle case where user selected "Applications"
2009 String applicationName = getResources().getString(R.string.group_applications);
2010 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002012 if (applicationName != null && applicationName.equals(shortcutName)) {
2013 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2014 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2017 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002018 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002019 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002020 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002021 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002022 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 }
2024
Winson Chung24ab2f12010-09-16 14:10:47 -07002025 void processWallpaper(Intent intent) {
2026 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2027 }
2028
Adam Cohendcd297f2013-06-18 13:13:40 -07002029 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002030 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002031 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002032 folderInfo.title = getText(R.string.folder_name);
2033
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002035 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002036 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002037 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038
2039 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 FolderIcon newFolder =
2041 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002042 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002043 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002044 // Force measure the new folder icon
2045 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2046 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002047 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 }
Romain Guycbb89e42009-06-08 15:52:54 -07002049
Joe Onorato9c1289c2009-08-17 11:03:03 -04002050 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002051 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002052 }
2053
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002054 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002055 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002057 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002058 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 }
2060
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002061 protected ComponentName getWallpaperPickerComponent() {
2062 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2063 }
2064
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002065 /**
2066 * Registers various content observers. The current implementation registers
2067 * only a favorites observer to keep track of the favorites applications.
2068 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002069 private void registerContentObservers() {
2070 ContentResolver resolver = getContentResolver();
2071 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2072 true, mWidgetObserver);
2073 }
2074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 @Override
2076 public boolean dispatchKeyEvent(KeyEvent event) {
2077 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2078 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002080 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002081 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002082 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002083 dumpState();
2084 return true;
2085 }
2086 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002087 }
2088 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2089 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002090 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 return true;
2092 }
2093 }
2094
2095 return super.dispatchKeyEvent(event);
2096 }
2097
Joe Onorato88ec0992009-11-19 13:16:06 -08002098 @Override
2099 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002100 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002101 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002102 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002103 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002104 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002105 Folder openFolder = mWorkspace.getOpenFolder();
2106 if (openFolder.isEditingName()) {
2107 openFolder.dismissEditingName();
2108 } else {
2109 closeFolder();
2110 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002111 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002112 mWorkspace.exitWidgetResizeMode();
2113
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002114 // Back button is a no-op here, but give at least some feedback for the button press
2115 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002116 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002117 }
2118
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002120 * Re-listen when widgets are reset.
2121 */
2122 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002123 if (mAppWidgetHost != null) {
2124 mAppWidgetHost.startListening();
2125 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002126 }
2127
2128 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002129 * Launches the intent referred by the clicked shortcut.
2130 *
2131 * @param v The view representing the clicked shortcut.
2132 */
2133 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002134 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2135 // view has detached (it's possible for this to happen if the view is removed mid touch).
2136 if (v.getWindowToken() == null) {
2137 return;
2138 }
2139
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002140 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002141 return;
2142 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002143
Adam Cohen1697b792013-09-17 19:08:21 -07002144 if (v instanceof Workspace) {
2145 if (mWorkspace.isInOverviewMode()) {
2146 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002147 }
2148 return;
2149 }
2150
2151 if (v instanceof CellLayout) {
2152 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002153 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002154 }
2155 }
2156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002158 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002160 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2161 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002162
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002163 // Check for special shortcuts
2164 if (intent.getComponent() != null) {
2165 final String shortcutClass = intent.getComponent().getClassName();
2166
2167 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002168 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002169 return;
2170 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2171 MemoryDumpActivity.startDump(this);
2172 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002173 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2174 toggleShowWeightWatcher();
2175 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002176 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002177 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002178
2179 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002180 int[] pos = new int[2];
2181 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002182 intent.setSourceBounds(new Rect(pos[0], pos[1],
2183 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002184
2185 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002186
Daniel Sandlerff02d492013-08-05 02:12:05 -04002187 mStats.recordLaunch(intent, shortcut);
2188
Michael Jurkaddd62e92011-02-16 17:49:14 -08002189 if (success && v instanceof BubbleTextView) {
2190 mWaitingForResume = (BubbleTextView) v;
2191 mWaitingForResume.setStayPressed(true);
2192 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002193 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002194 if (v instanceof FolderIcon) {
2195 FolderIcon fi = (FolderIcon) v;
2196 handleFolderClick(fi);
2197 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002198 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002199 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002200 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002201 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002202 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002203 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 }
2205 }
2206
Michael Jurka0e260592010-06-30 17:07:39 -07002207 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002208 return false;
2209 }
2210
Michael Jurkaaf442092010-06-10 17:01:57 -07002211 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002212 * Event handler for the search button
2213 *
2214 * @param v The view that was clicked.
2215 */
2216 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002217 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2218
Amith Yamasania135ba82011-08-09 17:42:01 -07002219 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002220 }
2221
2222 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002223 * Event handler for the voice button
2224 *
2225 * @param v The view that was clicked.
2226 */
2227 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002228 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002229
Bjorn Bringertc459e522013-06-07 19:36:01 +01002230 startVoice();
2231 }
2232
2233 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002234 try {
2235 final SearchManager searchManager =
2236 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2237 ComponentName activityName = searchManager.getGlobalSearchActivity();
2238 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002239 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002240 if (activityName != null) {
2241 intent.setPackage(activityName.getPackageName());
2242 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002243 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002244 } catch (ActivityNotFoundException e) {
2245 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002246 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002247 startActivitySafely(null, intent, "onClickVoiceButton");
2248 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002249 }
2250
2251 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002252 * Event handler for the "grid" button that appears on the home screen, which
2253 * enters all apps mode.
2254 *
2255 * @param v The view that was clicked.
2256 */
2257 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002258 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002259 }
2260
2261 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002262 // Provide the same haptic feedback that the system offers for virtual keys.
2263 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002264 }
2265
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002266 public void onClickAppMarketButton(View v) {
2267 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002268 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002269 } else {
2270 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002271 }
2272 }
2273
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002274 /**
2275 * Called when the user stops interacting with the launcher.
2276 * This implies that the user is now on the homescreen and is not doing housekeeping.
2277 */
2278 protected void onInteractionEnd() {}
2279
2280 /**
2281 * Called when the user starts interacting with the launcher.
2282 * The possible interactions are:
2283 * - open all apps
2284 * - reorder an app shortcut, or a widget
2285 * - open the overview mode.
2286 * This is a good time to stop doing things that only make sense
2287 * when the user is on the homescreen and not doing housekeeping.
2288 */
2289 protected void onInteractionBegin() {}
2290
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002291 void startApplicationDetailsActivity(ComponentName componentName) {
2292 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002293 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2294 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002295 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002296 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002297 }
2298
Michael Jurka1e2f4652013-07-08 18:03:46 -07002299 // returns true if the activity was started
2300 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002301 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002302 // System applications cannot be installed. For now, show a toast explaining that.
2303 // We may give them the option of disabling apps this way.
2304 int messageId = R.string.uninstall_system_app_text;
2305 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002306 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002307 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002308 String packageName = componentName.getPackageName();
2309 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002310 Intent intent = new Intent(
2311 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002312 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2313 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002314 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002315 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002316 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002317 }
2318
Michael Jurka86a720e2012-05-09 11:23:23 -07002319 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002323 // Only launch using the new animation if the shortcut has not opted out (this is a
2324 // private contract between launcher and may be ignored in the future).
2325 boolean useLaunchAnimation = (v != null) &&
2326 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2327 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002328 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2329 v.getMeasuredWidth(), v.getMeasuredHeight());
2330
2331 startActivity(intent, opts.toBundle());
2332 } else {
2333 startActivity(intent);
2334 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002335 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 } catch (SecurityException e) {
2337 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002338 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002340 "or use the exported attribute for this activity. "
2341 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002343 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002344 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002345
Michael Jurka86a720e2012-05-09 11:23:23 -07002346 boolean startActivitySafely(View v, Intent intent, Object tag) {
2347 boolean success = false;
2348 try {
2349 success = startActivity(v, intent, tag);
2350 } catch (ActivityNotFoundException e) {
2351 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2352 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2353 }
2354 return success;
2355 }
2356
Adam Cohena9cf38f2011-05-02 15:36:58 -07002357 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002358 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002359 Folder openFolder = mWorkspace.getFolderForTag(info);
2360
2361 // If the folder info reports that the associated folder is open, then verify that
2362 // it is actually opened. There have been a few instances where this gets out of sync.
2363 if (info.opened && openFolder == null) {
2364 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002365 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002366 info.opened = false;
2367 }
2368
Adam Cohenfb91f302012-06-11 15:45:18 -07002369 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 // Close any open folder
2371 closeFolder();
2372 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002373 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 } else {
2375 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376 int folderScreen;
2377 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002378 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 // .. and close it
2380 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002381 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 // Close any folder open on the current screen
2383 closeFolder();
2384 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002385 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 }
2387 }
2388 }
2389 }
2390
Adam Cohen268c4752012-06-06 17:47:33 -07002391 /**
2392 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2393 * in the DragLayer in the exact absolute location of the original FolderIcon.
2394 */
2395 private void copyFolderIconToImage(FolderIcon fi) {
2396 final int width = fi.getMeasuredWidth();
2397 final int height = fi.getMeasuredHeight();
2398
2399 // Lazy load ImageView, Bitmap and Canvas
2400 if (mFolderIconImageView == null) {
2401 mFolderIconImageView = new ImageView(this);
2402 }
2403 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2404 mFolderIconBitmap.getHeight() != height) {
2405 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2406 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2407 }
2408
2409 DragLayer.LayoutParams lp;
2410 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2411 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2412 } else {
2413 lp = new DragLayer.LayoutParams(width, height);
2414 }
2415
Adam Cohen307fe232012-08-16 17:55:58 -07002416 // The layout from which the folder is being opened may be scaled, adjust the starting
2417 // view size by this scale factor.
2418 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002419 lp.customPosition = true;
2420 lp.x = mRectForFolderAnimation.left;
2421 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002422 lp.width = (int) (scale * width);
2423 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002424
2425 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2426 fi.draw(mFolderIconCanvas);
2427 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002428 if (fi.getFolder() != null) {
2429 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2430 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002431 }
Adam Cohen268c4752012-06-06 17:47:33 -07002432 // Just in case this image view is still in the drag layer from a previous animation,
2433 // we remove it and re-add it.
2434 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2435 mDragLayer.removeView(mFolderIconImageView);
2436 }
2437 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002438 if (fi.getFolder() != null) {
2439 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002440 }
Adam Cohen268c4752012-06-06 17:47:33 -07002441 }
2442
Adam Cohen2801caf2011-05-13 20:57:39 -07002443 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002444 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002445 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2446 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2447 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2448
Adam Cohenc51934b2011-07-26 21:07:43 -07002449 FolderInfo info = (FolderInfo) fi.getTag();
2450 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2451 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002452 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2453 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002454 }
2455
Adam Cohen268c4752012-06-06 17:47:33 -07002456 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2457 copyFolderIconToImage(fi);
2458 fi.setVisibility(View.INVISIBLE);
2459
Michael Jurka2ecf9952012-06-18 12:52:28 -07002460 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002461 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002462 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2463 oa.start();
2464 }
2465
Adam Cohen268c4752012-06-06 17:47:33 -07002466 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002467 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002468 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2469 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2470 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2471
Adam Cohen268c4752012-06-06 17:47:33 -07002472 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002473
Adam Cohen268c4752012-06-06 17:47:33 -07002474 // We remove and re-draw the FolderIcon in-case it has changed
2475 mDragLayer.removeView(mFolderIconImageView);
2476 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002477 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002478 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002479 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002480 oa.addListener(new AnimatorListenerAdapter() {
2481 @Override
2482 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002483 if (cl != null) {
2484 cl.clearFolderLeaveBehind();
2485 // Remove the ImageView copy of the FolderIcon and make the original visible.
2486 mDragLayer.removeView(mFolderIconImageView);
2487 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002488 }
2489 }
2490 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002491 oa.start();
2492 }
2493
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002494 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002495 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002496 * is animated relative to the specified View. If the View is null, no animation
2497 * is played.
2498 *
2499 * @param folderInfo The FolderInfo describing the folder to open.
2500 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002501 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002502 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002503 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002504
Adam Cohena9cf38f2011-05-02 15:36:58 -07002505 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002506
Adam Cohen4554ee12011-08-03 16:13:21 -07002507 // Just verify that the folder hasn't already been added to the DragLayer.
2508 // There was a one-off crash where the folder had a parent already.
2509 if (folder.getParent() == null) {
2510 mDragLayer.addView(folder);
2511 mDragController.addDropTarget((DropTarget) folder);
2512 } else {
2513 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2514 folder.getParent() + ").");
2515 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002517 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002518
2519 // Notify the accessibility manager that this folder "window" has appeared and occluded
2520 // the workspace items
2521 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2522 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002523 }
2524
2525 public void closeFolder() {
2526 Folder folder = mWorkspace.getOpenFolder();
2527 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002528 if (folder.isEditingName()) {
2529 folder.dismissEditingName();
2530 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002531 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002532
2533 // Dismiss the folder cling
2534 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002535 }
2536 }
2537
2538 void closeFolder(Folder folder) {
2539 folder.getInfo().opened = false;
2540
2541 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2542 if (parent != null) {
2543 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2544 shrinkAndFadeInFolderIcon(fi);
2545 }
2546 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002547
2548 // Notify the accessibility manager that this folder "window" has disappeard and no
2549 // longer occludeds the workspace items
2550 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002551 }
2552
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002553 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002554 if (!isDraggingEnabled()) return false;
2555 if (isWorkspaceLocked()) return false;
2556 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557
Adam Cohen1697b792013-09-17 19:08:21 -07002558 if (v instanceof Workspace) {
2559 if (!mWorkspace.isInOverviewMode()) {
2560 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2561 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2562 mWorkspace.enterOverviewMode();
2563 }
2564 return true;
2565 }
2566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002568 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 }
2570
Michael Jurka0280c3b2010-09-17 15:00:07 -07002571 resetAddInfo();
2572 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002573 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002574 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002575 return true;
2576 }
2577
Winson Chung3d503fb2011-07-13 17:25:49 -07002578 // The hotseat touch handling does not go through Workspace, and we always allow long press
2579 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002580 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002581 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2582 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002583 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002584 // User long pressed on empty space
2585 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2586 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2587 // Disabling reordering until we sort out some issues.
2588 if (mWorkspace.isInOverviewMode()) {
2589 mWorkspace.startReordering(v);
2590 } else {
2591 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002592 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002594 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002595 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002596 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002597 }
2598 }
2599 }
2600 return true;
2601 }
2602
Winson Chung3d503fb2011-07-13 17:25:49 -07002603 boolean isHotseatLayout(View layout) {
2604 return mHotseat != null && layout != null &&
2605 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2606 }
2607 Hotseat getHotseat() {
2608 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002609 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002610 View getOverviewPanel() {
2611 return mOverviewPanel;
2612 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002613 SearchDropTargetBar getSearchBar() {
2614 return mSearchDropTargetBar;
2615 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002616
Winson Chung3d503fb2011-07-13 17:25:49 -07002617 /**
2618 * Returns the CellLayout of the specified container at the specified screen.
2619 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002620 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002621 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2622 if (mHotseat != null) {
2623 return mHotseat.getLayout();
2624 } else {
2625 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002626 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002627 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002628 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002629 }
2630 }
2631
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002632 Workspace getWorkspace() {
2633 return mWorkspace;
2634 }
2635
Daniel Sandler843e8602010-06-07 14:59:01 -04002636 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002637 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002638 }
2639
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002640 /**
2641 * Helper method for the cameraZoomIn/cameraZoomOut animations
2642 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 * @param scaleFactor The scale factor used for the zoom
2644 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002645 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002647 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002648 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002649
Winson Chung18f41f82012-05-09 13:28:10 -07002650 void disableWallpaperIfInAllApps() {
2651 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002652 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002653 if (mAppsCustomizeTabHost != null &&
2654 !mAppsCustomizeTabHost.isTransitioning()) {
2655 updateWallpaperVisibility(false);
2656 }
2657 }
2658 }
2659
Craig Mautner360310b2012-10-26 15:13:08 -07002660 private void setWorkspaceBackground(boolean workspace) {
2661 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002662 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002663 }
2664
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002665 void updateWallpaperVisibility(boolean visible) {
2666 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2667 int curflags = getWindow().getAttributes().flags
2668 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2669 if (wpflags != curflags) {
2670 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2671 }
Craig Mautner360310b2012-10-26 15:13:08 -07002672 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002673 }
2674
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002675 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2676 if (v instanceof LauncherTransitionable) {
2677 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2678 }
2679 }
2680
Michael Jurkabed61d22012-02-14 22:51:29 -08002681 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2682 if (v instanceof LauncherTransitionable) {
2683 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2684 }
Winson Chung70442722012-02-10 15:43:22 -08002685
2686 // Update the workspace transition step as well
2687 dispatchOnLauncherTransitionStep(v, 0f);
2688 }
2689
2690 private void dispatchOnLauncherTransitionStep(View v, float t) {
2691 if (v instanceof LauncherTransitionable) {
2692 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2693 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002694 }
2695
2696 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2697 if (v instanceof LauncherTransitionable) {
2698 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2699 }
Winson Chung70442722012-02-10 15:43:22 -08002700
2701 // Update the workspace transition step as well
2702 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002703 }
2704
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002705 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002706 * Things to test when changing the following seven functions.
2707 * - Home from workspace
2708 * - from center screen
2709 * - from other screens
2710 * - Home from all apps
2711 * - from center screen
2712 * - from other screens
2713 * - Back from all apps
2714 * - from center screen
2715 * - from other screens
2716 * - Launch app from workspace and quit
2717 * - with back
2718 * - with home
2719 * - Launch app from all apps and quit
2720 * - with back
2721 * - with home
2722 * - Go to a screen that's not the default, then all
2723 * apps, and launch and app, and go back
2724 * - with back
2725 * -with home
2726 * - On workspace, long press power and go back
2727 * - with back
2728 * - with home
2729 * - On all apps, long press power and go back
2730 * - with back
2731 * - with home
2732 * - On workspace, power off
2733 * - On all apps, power off
2734 * - Launch an app and turn off the screen while in that app
2735 * - Go back with home key
2736 * - Go back with back key TODO: make this not go to workspace
2737 * - From all apps
2738 * - From workspace
2739 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2740 * - From all apps
2741 * - From the center workspace
2742 * - From another workspace
2743 */
2744
2745 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002746 * Zoom the camera out from the workspace to reveal 'toView'.
2747 * Assumes that the view to show is anchored at either the very top or very bottom
2748 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002749 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002750 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002751 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2752 showAppsCustomizeHelper(animated, springLoaded, contentType);
2753 }
2754 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2755 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002756 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002757 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002758 mStateAnimation.cancel();
2759 mStateAnimation = null;
2760 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002761 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002762
Winson Chungf0ea4d32011-06-06 14:27:16 -07002763 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2764 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2765 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002766 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002767 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002768 final int startDelay =
2769 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002770
Michael Jurkab3e22d92011-10-31 15:58:33 -07002771 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002772
Michael Jurkad74c9842011-07-10 12:44:21 -07002773 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002774 Animator workspaceAnim =
2775 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002776 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2777 // Set the content type for the all apps space
2778 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2779 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002780
2781 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002782 toView.setScaleX(scale);
2783 toView.setScaleY(scale);
2784 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2785 scaleAnim.
2786 scaleX(1f).scaleY(1f).
2787 setDuration(duration).
2788 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002789
Winson Chungf0ea4d32011-06-06 14:27:16 -07002790 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002791 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002792 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002793 .ofFloat(toView, "alpha", 0f, 1f)
2794 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002795 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002796 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2797 @Override
2798 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002799 if (animation == null) {
2800 throw new RuntimeException("animation is null");
2801 }
Winson Chung70442722012-02-10 15:43:22 -08002802 float t = (Float) animation.getAnimatedValue();
2803 dispatchOnLauncherTransitionStep(fromView, t);
2804 dispatchOnLauncherTransitionStep(toView, t);
2805 }
2806 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002807
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002808 // toView should appear right at the end of the workspace shrink
2809 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002810 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002811 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002812 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002813
2814 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002815 boolean animationCancelled = false;
2816
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002817 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002818 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002819 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002820 // Prepare the position
2821 toView.setTranslationX(0.0f);
2822 toView.setTranslationY(0.0f);
2823 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002824 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002825 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002826 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002827 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002828 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2829 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002830
Adam Cohenf4ddea32011-09-12 13:46:42 -07002831 if (!animationCancelled) {
2832 updateWallpaperVisibility(false);
2833 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002834
2835 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002836 if (mSearchDropTargetBar != null) {
2837 mSearchDropTargetBar.hideSearchBar(false);
2838 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002839 }
2840
Adam Cohencff6af82011-09-13 14:51:53 -07002841 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002842 public void onAnimationCancel(Animator animation) {
2843 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002844 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002845 });
2846
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002847 if (workspaceAnim != null) {
2848 mStateAnimation.play(workspaceAnim);
2849 }
Michael Jurka1899a362011-11-03 13:50:45 -07002850
2851 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002852
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002853 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2854 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855
2856 // If any of the objects being animated haven't been measured/laid out
2857 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002858 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002859 (mWorkspace.getMeasuredWidth() == 0) ||
2860 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002861 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002862 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002863
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002864 final AnimatorSet stateAnimation = mStateAnimation;
2865 final Runnable startAnimRunnable = new Runnable() {
2866 public void run() {
2867 // Check that mStateAnimation hasn't changed while
2868 // we waited for a layout/draw pass
2869 if (mStateAnimation != stateAnimation)
2870 return;
2871 setPivotsForZoom(toView, scale);
2872 dispatchOnLauncherTransitionStart(fromView, animated, false);
2873 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002874 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002875 }
2876 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002877 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002878 final ViewTreeObserver observer = toView.getViewTreeObserver();
2879 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2880 public void onGlobalLayout() {
2881 startAnimRunnable.run();
2882 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2883 }
2884 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002885 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002886 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002887 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002888 } else {
2889 toView.setTranslationX(0.0f);
2890 toView.setTranslationY(0.0f);
2891 toView.setScaleX(1.0f);
2892 toView.setScaleY(1.0f);
2893 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002894 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002895
Daniel Sandlere4f98912013-06-25 15:13:26 -04002896 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002897 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002898 if (mSearchDropTargetBar != null) {
2899 mSearchDropTargetBar.hideSearchBar(false);
2900 }
Michael Jurkaabded662011-03-04 12:06:57 -08002901 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002902 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002903 dispatchOnLauncherTransitionStart(fromView, animated, false);
2904 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002905 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002906 dispatchOnLauncherTransitionStart(toView, animated, false);
2907 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002908 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002909 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002910 }
2911
2912 /**
2913 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002914 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002915 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002916 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002917 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2918 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002919
Michael Jurkab3e22d92011-10-31 15:58:33 -07002920 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002921 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002922 mStateAnimation.cancel();
2923 mStateAnimation = null;
2924 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002925 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002926
Winson Chungf0ea4d32011-06-06 14:27:16 -07002927 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002928 final int fadeOutDuration =
2929 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002930 final float scaleFactor = (float)
2931 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2932 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002933 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002934 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002935 if (toState == State.WORKSPACE) {
2936 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2937 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002938 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002939 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2940 workspaceAnim = mWorkspace.getChangeStateAnimation(
2941 Workspace.State.SPRING_LOADED, animated);
2942 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002943
Michael Jurkab3e22d92011-10-31 15:58:33 -07002944 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002945 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002946 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002947 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002948 final LauncherViewPropertyAnimator scaleAnim =
2949 new LauncherViewPropertyAnimator(fromView);
2950 scaleAnim.
2951 scaleX(scaleFactor).scaleY(scaleFactor).
2952 setDuration(duration).
2953 setInterpolator(new Workspace.ZoomInInterpolator());
2954
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002955 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002956 .ofFloat(fromView, "alpha", 1f, 0f)
2957 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002958 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002959 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2960 @Override
2961 public void onAnimationUpdate(ValueAnimator animation) {
2962 float t = 1f - (Float) animation.getAnimatedValue();
2963 dispatchOnLauncherTransitionStep(fromView, t);
2964 dispatchOnLauncherTransitionStep(toView, t);
2965 }
2966 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002967
Michael Jurka2ecf9952012-06-18 12:52:28 -07002968 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002969
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002970 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2971 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002972 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002973
2974 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002975 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002976 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002977 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002978 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002979 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2980 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002981 if (onCompleteRunnable != null) {
2982 onCompleteRunnable.run();
2983 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002984 mAppsCustomizeContent.updateCurrentPageScroll();
2985 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002986 }
2987 });
2988
Winson Chungf0ea4d32011-06-06 14:27:16 -07002989 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002990 if (workspaceAnim != null) {
2991 mStateAnimation.play(workspaceAnim);
2992 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002993 dispatchOnLauncherTransitionStart(fromView, animated, true);
2994 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002995 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002996 } else {
2997 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002998 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002999 dispatchOnLauncherTransitionStart(fromView, animated, true);
3000 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003001 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003002 dispatchOnLauncherTransitionStart(toView, animated, true);
3003 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003004 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003005 }
3006
Michael Jurkae326f182011-11-21 14:05:46 -08003007 @Override
3008 public void onTrimMemory(int level) {
3009 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003010 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003011 mAppsCustomizeTabHost.onTrimMemory();
3012 }
3013 }
3014
Winson Chung18f41f82012-05-09 13:28:10 -07003015 @Override
3016 public void onWindowFocusChanged(boolean hasFocus) {
3017 if (!hasFocus) {
3018 // When another window occludes launcher (like the notification shade, or recents),
3019 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3020 updateWallpaperVisibility(true);
3021 } else {
3022 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003023 mWorkspace.postDelayed(new Runnable() {
3024 @Override
3025 public void run() {
3026 disableWallpaperIfInAllApps();
3027 }
3028 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003029 }
3030 }
3031
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003032 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003033 showWorkspace(animated, null);
3034 }
3035
3036 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003037 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003038 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003039 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003040 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003041
Winson Chungc7d2b602012-05-16 17:02:20 -07003042 // Show the search bar (only animate if we were showing the drop target bar in spring
3043 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003044 if (mSearchDropTargetBar != null) {
3045 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3046 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003047
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 // Set focus to the AppsCustomize button
3049 if (mAllAppsButton != null) {
3050 mAllAppsButton.requestFocus();
3051 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003052 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003053
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003054 // Change the state *after* we've called all the transition code
3055 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003056
Winson Chung5fb63472011-02-02 17:03:37 -08003057 // Resume the auto-advance of widgets
3058 mUserPresent = true;
3059 updateRunning();
3060
alanv1d4fde62012-10-17 13:15:47 -07003061 // Send an accessibility event to announce the context change
3062 getWindow().getDecorView()
3063 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003064
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003065 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003066 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003067 }
3068
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003069 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003070 }
3071
Winson Chungc58497e2013-09-03 17:48:37 -07003072 void showAllApps(boolean animated,
3073 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003074 if (mState != State.WORKSPACE) return;
3075
Winson Chungc58497e2013-09-03 17:48:37 -07003076 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003077 mAppsCustomizeTabHost.requestFocus();
3078
Michael Jurkab3e22d92011-10-31 15:58:33 -07003079 // Change the state *after* we've called all the transition code
3080 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003081 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003082
3083 // Pause the auto-advance of widgets until we are out of AllApps
3084 mUserPresent = false;
3085 updateRunning();
3086 closeFolder();
3087
3088 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003089 getWindow().getDecorView()
3090 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003091 }
3092
Adam Cohen7777d962011-08-18 18:58:38 -07003093 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003094 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003095 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003096 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003097 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003098 }
Adam Cohen7777d962011-08-18 18:58:38 -07003099
Adam Cohened66b2b2012-01-23 17:28:51 -08003100 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3101 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003102 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3103
Winson Chunge7a03942011-08-05 15:05:12 -07003104 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003105 @Override
3106 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003107 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003108 // Before we show workspace, hide all apps again because
3109 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3110 // clean up our state transition functions
3111 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003112 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003113 } else {
3114 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003115 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003116 }
3117 }, (extendedDelay ?
3118 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3119 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3120 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003121
Michael Jurkad3ef3062010-11-23 16:23:58 -08003122 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003123 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003124 final boolean animated = true;
3125 final boolean springLoaded = true;
3126 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003127 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003128 }
3129 // Otherwise, we are not in spring loaded mode, so don't do anything.
3130 }
3131
Michael Jurkab3e22d92011-10-31 15:58:33 -07003132 void lockAllApps() {
3133 // TODO
3134 }
3135
3136 void unlockAllApps() {
3137 // TODO
3138 }
3139
Winson Chungf0ea4d32011-06-06 14:27:16 -07003140 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003142 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003143 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003144 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003145 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003146 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003147 int duration = 0;
3148 if (mSearchDropTargetBar != null) {
3149 duration = mSearchDropTargetBar.getTransitionInDuration();
3150 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003151 mHotseat.animate().alpha(1f).setDuration(duration);
3152 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003154 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003155 }
3156 }
3157 }
3158
3159 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003160 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003161 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003162 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003163 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003164 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003165 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003166 int duration = 0;
3167 if (mSearchDropTargetBar != null) {
3168 duration = mSearchDropTargetBar.getTransitionOutDuration();
3169 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003170 mHotseat.animate().alpha(0f).setDuration(duration);
3171 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003172 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003173 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003174 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003175 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003176 }
3177
Patrick Dubroy5f445422011-02-18 14:35:21 -08003178 /**
3179 * Add an item from all apps or customize onto the given workspace screen.
3180 * If layout is null, add to the current screen.
3181 */
3182 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003183 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003184 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003185 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003186 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003187
Winson Chungdff8ebb2011-09-08 17:25:31 -07003188 /** Maps the current orientation to an index for referencing orientation correct global icons */
3189 private int getCurrentOrientationIndexForGlobalIcons() {
3190 // default - 0, landscape - 1
3191 switch (getResources().getConfiguration().orientation) {
3192 case Configuration.ORIENTATION_LANDSCAPE:
3193 return 1;
3194 default:
3195 return 0;
3196 }
3197 }
3198
Michael Jurkaae65ee32012-04-30 11:45:54 -07003199 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003200 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003201 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003202 // Look for the toolbar icon specified in the activity meta-data
3203 Bundle metaData = packageManager.getActivityInfo(
3204 activityName, PackageManager.GET_META_DATA).metaData;
3205 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003206 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003207 if (iconResId != 0) {
3208 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003209 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003210 }
3211 }
3212 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003213 // This can happen if the activity defines an invalid drawable
3214 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3215 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003216 } catch (Resources.NotFoundException nfe) {
3217 // This can happen if the activity defines an invalid drawable
3218 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3219 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003220 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003221 return null;
3222 }
3223
3224 // if successful in getting icon, return it; otherwise, set button to use default drawable
3225 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003226 int buttonId, ComponentName activityName, int fallbackDrawableId,
3227 String toolbarResourceName) {
3228 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003229 Resources r = getResources();
3230 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3231 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003232
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003233 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003234 // If we were unable to find the icon via the meta-data, use a generic one
3235 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003236 toolbarIcon = r.getDrawable(fallbackDrawableId);
3237 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003238 if (button != null) {
3239 button.setCompoundDrawables(toolbarIcon, null, null, null);
3240 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003241 return null;
3242 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003243 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003244 if (button != null) {
3245 button.setCompoundDrawables(toolbarIcon, null, null, null);
3246 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003247 return toolbarIcon.getConstantState();
3248 }
3249 }
3250
3251 // if successful in getting icon, return it; otherwise, set button to use default drawable
3252 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003253 int buttonId, ComponentName activityName, int fallbackDrawableId,
3254 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003255 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003256 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003257
Michael Jurka19e0fc52011-07-22 18:00:21 -07003258 if (button != null) {
3259 // If we were unable to find the icon via the meta-data, use a
3260 // generic one
3261 if (toolbarIcon == null) {
3262 button.setImageResource(fallbackDrawableId);
3263 } else {
3264 button.setImageDrawable(toolbarIcon);
3265 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003266 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003267
3268 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3269
Michael Jurka0423dcf2010-10-05 14:56:18 -07003270 }
3271
Winson Chung1b884092012-06-08 17:13:02 -07003272 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003273 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003274 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003275 }
3276
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003277 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003278 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003279 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003280 }
3281
Winson Chungbb185bd2011-11-21 12:31:42 -08003282 private void invalidatePressedFocusedStates(View container, View button) {
3283 if (container instanceof HolographicLinearLayout) {
3284 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3285 layout.invalidatePressedFocusedStates();
3286 } else if (button instanceof HolographicImageView) {
3287 HolographicImageView view = (HolographicImageView) button;
3288 view.invalidatePressedFocusedStates();
3289 }
3290 }
3291
Cristina Stancu476493b2013-08-07 17:20:14 +01003292 public View getQsbBar() {
3293 if (mQsbBar == null) {
3294 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3295 }
3296 return mQsbBar;
3297 }
3298
3299 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003300 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003301 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003302 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003303 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003304
Winson Chung1cad91e2011-05-25 17:41:01 -07003305 final SearchManager searchManager =
3306 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3307 ComponentName activityName = searchManager.getGlobalSearchActivity();
3308 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003309 int coi = getCurrentOrientationIndexForGlobalIcons();
3310 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003311 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3312 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3313 if (sGlobalSearchIcon[coi] == null) {
3314 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3315 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3316 TOOLBAR_ICON_METADATA_NAME);
3317 }
3318
Winson Chungc51db6a2011-10-05 11:44:49 -07003319 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3320 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003321 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003322 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003323 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003324 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003325 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3326 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003327 if (searchButton != null) searchButton.setVisibility(View.GONE);
3328 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003329 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003330 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003331 }
3332 }
3333
Cristina Stancu476493b2013-08-07 17:20:14 +01003334 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003335 final View searchButtonContainer = findViewById(R.id.search_button_container);
3336 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003337 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003338 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003339 }
3340
Cristina Stancu476493b2013-08-07 17:20:14 +01003341 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003342 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003343 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003344
Winson Chungc51db6a2011-10-05 11:44:49 -07003345 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003346 final SearchManager searchManager =
3347 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3348 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3349
3350 ComponentName activityName = null;
3351 if (globalSearchActivity != null) {
3352 // Check if the global search activity handles voice search
3353 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3354 intent.setPackage(globalSearchActivity.getPackageName());
3355 activityName = intent.resolveActivity(getPackageManager());
3356 }
3357
3358 if (activityName == null) {
3359 // Fallback: check if an activity other than the global search activity
3360 // resolves this
3361 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3362 activityName = intent.resolveActivity(getPackageManager());
3363 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003364 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003365 int coi = getCurrentOrientationIndexForGlobalIcons();
3366 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003367 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3368 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3369 if (sVoiceSearchIcon[coi] == null) {
3370 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3371 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3372 TOOLBAR_ICON_METADATA_NAME);
3373 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003374 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003375 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003376 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003377 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003378 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003379 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003380 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003381 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003382 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003383 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003384 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003385 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003386
Cristina Stancu476493b2013-08-07 17:20:14 +01003387 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003388 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3389 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003390 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003391 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003392 }
3393
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003394 public void setVoiceButtonProxyVisible(boolean visible) {
3395 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3396 if (voiceButtonProxy != null) {
3397 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3398 }
3399 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003400 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003401 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003402 */
3403 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003404 final View marketButton = findViewById(R.id.market_button);
3405 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3406 // Find the app market activity by resolving an intent.
3407 // (If multiple app markets are installed, it will return the ResolverActivity.)
3408 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003409 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003410 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003411 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003412 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003413 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3414 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003415 marketButton.setVisibility(View.VISIBLE);
3416 } else {
3417 // We should hide and disable the view so that we don't try and restore the visibility
3418 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3419 marketButton.setVisibility(View.GONE);
3420 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003421 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003422 }
3423
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003424 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003425 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3426 Resources r = getResources();
3427 Drawable marketIconDrawable = d.newDrawable(r);
3428 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3429 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3430 marketIconDrawable.setBounds(0, 0, w, h);
3431
3432 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003433 }
3434
Michael Jurkad7c28052012-04-27 15:43:36 -07003435 @Override
3436 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003437 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003438 final List<CharSequence> text = event.getText();
3439 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003440 // Populate event with a fake title based on the current state.
3441 if (mState == State.APPS_CUSTOMIZE) {
3442 text.add(getString(R.string.all_apps_button_label));
3443 } else {
3444 text.add(getString(R.string.all_apps_home_button_label));
3445 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003446 return result;
3447 }
3448
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003449 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003450 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003451 */
3452 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3453 @Override
3454 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003455 closeSystemDialogs();
3456 }
3457 }
3458
3459 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003460 * Receives notifications whenever the appwidgets are reset.
3461 */
3462 private class AppWidgetResetObserver extends ContentObserver {
3463 public AppWidgetResetObserver() {
3464 super(new Handler());
3465 }
3466
3467 @Override
3468 public void onChange(boolean selfChange) {
3469 onAppWidgetReset();
3470 }
3471 }
3472
3473 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003474 * If the activity is currently paused, signal that we need to run the passed Runnable
3475 * in onResume.
3476 *
3477 * This needs to be called from incoming places where resources might have been loaded
3478 * while we are paused. That is becaues the Configuration might be wrong
3479 * when we're not running, and if it comes back to what it was when we
3480 * were paused, we are not restarted.
3481 *
3482 * Implementation of the method from LauncherModel.Callbacks.
3483 *
3484 * @return true if we are currently paused. The caller might be able to
3485 * skip some work in that case since we will come back again.
3486 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003487 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003488 if (mPaused) {
3489 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003490 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003491 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003492 }
3493 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003494 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003495 return true;
3496 } else {
3497 return false;
3498 }
3499 }
3500
Michael Jurkac402cd92013-05-20 15:49:32 +02003501 private boolean waitUntilResume(Runnable run) {
3502 return waitUntilResume(run, false);
3503 }
3504
Michael Jurka1e2f4652013-07-08 18:03:46 -07003505 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003506 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003507 }
3508
Michael Jurka7607c2f2013-04-03 14:33:19 -07003509 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003510 * If the activity is currently paused, signal that we need to re-run the loader
3511 * in onResume.
3512 *
3513 * This needs to be called from incoming places where resources might have been loaded
3514 * while we are paused. That is becaues the Configuration might be wrong
3515 * when we're not running, and if it comes back to what it was when we
3516 * were paused, we are not restarted.
3517 *
3518 * Implementation of the method from LauncherModel.Callbacks.
3519 *
3520 * @return true if we are currently paused. The caller might be able to
3521 * skip some work in that case since we will come back again.
3522 */
3523 public boolean setLoadOnResume() {
3524 if (mPaused) {
3525 Log.i(TAG, "setLoadOnResume");
3526 mOnResumeNeedsLoad = true;
3527 return true;
3528 } else {
3529 return false;
3530 }
3531 }
3532
3533 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003534 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003535 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003536 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003537 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003538 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003539 } else {
3540 return SCREEN_COUNT / 2;
3541 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003542 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003543
Joe Onorato9c1289c2009-08-17 11:03:03 -04003544 /**
3545 * Refreshes the shortcuts shown on the workspace.
3546 *
3547 * Implementation of the method from LauncherModel.Callbacks.
3548 */
3549 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003550 // If we're starting binding all over again, clear any bind calls we'd postponed in
3551 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3552 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003553 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003554
Winson Chungd64d1762013-08-20 14:37:16 -07003555 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003556 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003557 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003558
Michael Jurka05bf6442011-11-30 20:28:53 -08003559 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003560 if (mHotseat != null) {
3561 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003562 }
3563 }
3564
Adam Cohendcd297f2013-06-18 13:13:40 -07003565 @Override
3566 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003567 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003568
Adam Cohen5084cba2013-09-03 12:01:16 -07003569 // If there are no screens, we need to have an empty screen
3570 if (orderedScreenIds.size() == 0) {
3571 mWorkspace.addExtraEmptyScreen();
3572 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003573
3574 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003575 // setCurrentPage() so ensure that all pages are added before calling this).
3576 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003577 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3578 mWorkspace.createCustomContentPage();
3579 }
Winson Chung64359a52013-07-08 17:17:08 -07003580 }
3581
3582 @Override
3583 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003584 int count = orderedScreenIds.size();
3585 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003586 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003587 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003588 }
3589
Adam Cohen39a06042013-07-19 14:30:12 -07003590 private boolean shouldShowWeightWatcher() {
3591 String spKey = LauncherAppState.getSharedPreferencesKey();
3592 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003593 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003594
3595 return show;
3596 }
3597
Adam Cohen4caf2982013-08-20 18:54:31 -07003598 private boolean emailSent() {
3599 String spKey = LauncherAppState.getSharedPreferencesKey();
3600 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3601 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3602 return show;
3603 }
3604
3605 private void setEmailSent(boolean sent) {
3606 String spKey = LauncherAppState.getSharedPreferencesKey();
3607 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3608
3609 SharedPreferences.Editor editor = sp.edit();
3610 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3611 editor.commit();
3612 }
3613
Adam Cohen39a06042013-07-19 14:30:12 -07003614 private void toggleShowWeightWatcher() {
3615 String spKey = LauncherAppState.getSharedPreferencesKey();
3616 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3617 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3618
3619 show = !show;
3620
3621 SharedPreferences.Editor editor = sp.edit();
3622 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3623 editor.commit();
3624
3625 if (mWeightWatcher != null) {
3626 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3627 }
3628 }
3629
Winson Chungd64d1762013-08-20 14:37:16 -07003630 public void bindAppsAdded(final ArrayList<Long> newScreens,
3631 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003632 final ArrayList<ItemInfo> addAnimated,
3633 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003634 Runnable r = new Runnable() {
3635 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003636 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003637 }
3638 };
3639 if (waitUntilResume(r)) {
3640 return;
3641 }
3642
Winson Chungd64d1762013-08-20 14:37:16 -07003643 // Add the new screens
3644 bindAddScreens(newScreens);
3645
3646 // We add the items without animation on non-visible pages, and with
3647 // animations on the new page (which we will try and snap to).
3648 if (!addNotAnimated.isEmpty()) {
3649 bindItems(addNotAnimated, 0,
3650 addNotAnimated.size(), false);
3651 }
3652 if (!addAnimated.isEmpty()) {
3653 bindItems(addAnimated, 0,
3654 addAnimated.size(), true);
3655 }
Winson Chungc58497e2013-09-03 17:48:37 -07003656
3657 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3658 addedApps != null && mAppsCustomizeContent != null) {
3659 mAppsCustomizeContent.addApps(addedApps);
3660 }
Winson Chungd64d1762013-08-20 14:37:16 -07003661 }
3662
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003663 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003664 * Bind the items start-end from the list.
3665 *
3666 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003667 */
Winson Chung64359a52013-07-08 17:17:08 -07003668 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3669 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003670 Runnable r = new Runnable() {
3671 public void run() {
3672 bindItems(shortcuts, start, end, forceAnimateIcons);
3673 }
3674 };
3675 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003676 return;
3677 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003678
Winson Chungf0c6ae02012-03-21 16:10:31 -07003679 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003680 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3681 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003682 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003683 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003684 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003685 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003686 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003687
3688 // Short circuit if we are loading dock items for a configuration which has no dock
3689 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3690 mHotseat == null) {
3691 continue;
3692 }
3693
Joe Onorato9c1289c2009-08-17 11:03:03 -04003694 switch (item.itemType) {
3695 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3696 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003697 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003698 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003699
Winson Chung64359a52013-07-08 17:17:08 -07003700 /*
3701 * TODO: FIX collision case
3702 */
Winson Chungce376632013-07-11 16:12:41 -07003703 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3704 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3705 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3706 throw new RuntimeException("OCCUPIED");
3707 }
Winson Chung64359a52013-07-08 17:17:08 -07003708 }
3709
Adam Cohendcd297f2013-06-18 13:13:40 -07003710 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3711 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003712 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003713 // Animate all the applications up now
3714 shortcut.setAlpha(0f);
3715 shortcut.setScaleX(0f);
3716 shortcut.setScaleY(0f);
3717 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003718 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003719 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003720 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003721 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003722 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003723 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003724 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003725 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3726 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003727 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003728 default:
3729 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003730 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003731 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003732
Winson Chung997a9232013-07-24 15:33:46 -07003733 if (animateIcons) {
3734 // Animate to the correct page
3735 if (newShortcutsScreenId > -1) {
3736 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3737 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3738 if (newShortcutsScreenId != currentScreenId) {
3739 mWorkspace.snapToPage(newScreenIndex);
3740 }
3741 }
3742
Winson Chung64359a52013-07-08 17:17:08 -07003743 // We post the animation slightly delayed to prevent slowdowns when we are loading
3744 // right after we return to launcher.
3745 mWorkspace.postDelayed(new Runnable() {
3746 public void run() {
3747 anim.playTogether(bounceAnims);
3748 anim.start();
3749 }
3750 }, NEW_APPS_ANIMATION_DELAY);
3751 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003752 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003753 }
3754
Joe Onorato9c1289c2009-08-17 11:03:03 -04003755 /**
3756 * Implementation of the method from LauncherModel.Callbacks.
3757 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003758 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003759 Runnable r = new Runnable() {
3760 public void run() {
3761 bindFolders(folders);
3762 }
3763 };
3764 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003765 return;
3766 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003767 sFolders.clear();
3768 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003769 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770
3771 /**
3772 * Add the views for a widget to the workspace.
3773 *
3774 * Implementation of the method from LauncherModel.Callbacks.
3775 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003776 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003777 Runnable r = new Runnable() {
3778 public void run() {
3779 bindAppWidget(item);
3780 }
3781 };
3782 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003783 return;
3784 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003785
Daniel Sandler843e8602010-06-07 14:59:01 -04003786 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3787 if (DEBUG_WIDGETS) {
3788 Log.d(TAG, "bindAppWidget: " + item);
3789 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003790 final Workspace workspace = mWorkspace;
3791
3792 final int appWidgetId = item.appWidgetId;
3793 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003794 if (DEBUG_WIDGETS) {
3795 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3796 }
3797
Joe Onorato9c1289c2009-08-17 11:03:03 -04003798 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3799
Joe Onorato9c1289c2009-08-17 11:03:03 -04003800 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003801 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003802
Adam Cohendcd297f2013-06-18 13:13:40 -07003803 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003804 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003805 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3806
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 workspace.requestLayout();
3808
Daniel Sandler843e8602010-06-07 14:59:01 -04003809 if (DEBUG_WIDGETS) {
3810 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3811 + (SystemClock.uptimeMillis()-start) + "ms");
3812 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003813 }
3814
Adam Cohen1462de32012-07-24 22:34:36 -07003815 public void onPageBoundSynchronously(int page) {
3816 mSynchronouslyBoundPages.add(page);
3817 }
3818
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819 /**
3820 * Callback saying that there aren't any more items to bind.
3821 *
3822 * Implementation of the method from LauncherModel.Callbacks.
3823 */
Adam Cohene25af792013-06-06 23:08:25 -07003824 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003825 Runnable r = new Runnable() {
3826 public void run() {
3827 finishBindingItems(upgradePath);
3828 }
3829 };
3830 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003831 return;
3832 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833 if (mSavedState != null) {
3834 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003835 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003836 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837 mSavedState = null;
3838 }
3839
Adam Cohen1462de32012-07-24 22:34:36 -07003840 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003841
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003842 // If we received the result of any pending adds while the loader was running (e.g. the
3843 // widget configuration forced an orientation change), process them now.
3844 for (int i = 0; i < sPendingAddList.size(); i++) {
3845 completeAdd(sPendingAddList.get(i));
3846 }
3847 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003848
Winson Chungc51db6a2011-10-05 11:44:49 -07003849 // Update the market app icon as necessary (the other icons will be managed in response to
3850 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003851 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003852
Winson Chungf0c6ae02012-03-21 16:10:31 -07003853 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003854 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003855 mWorkspace.getUniqueComponents(true, null);
3856 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003857 }
Adam Cohen99894d92013-06-14 11:22:59 -07003858
Adam Cohen66a01fd2013-06-11 12:48:00 -07003859 mWorkspace.post(new Runnable() {
3860 @Override
3861 public void run() {
3862 onFinishBindingItems();
3863 }
3864 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003865 }
3866
Winson Chunga2413752012-04-03 14:22:34 -07003867 private boolean canRunNewAppsAnimation() {
3868 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3869 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3870 }
3871
Winson Chungc9168342013-06-26 14:54:55 -07003872 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3873 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3874 PropertyValuesHolder.ofFloat("alpha", 1f),
3875 PropertyValuesHolder.ofFloat("scaleX", 1f),
3876 PropertyValuesHolder.ofFloat("scaleY", 1f));
3877 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3878 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3879 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3880 return bounceAnim;
3881 }
3882
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003883 @Override
3884 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003885 boolean searchVisible = updateGlobalSearchIcon();
3886 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003887 if (mSearchDropTargetBar != null) {
3888 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3889 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003890 }
3891
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003892 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003893 * Add the icons for all apps.
3894 *
3895 * Implementation of the method from LauncherModel.Callbacks.
3896 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003897 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003898 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3899 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3900 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3901 getHotseat().addAllAppsFolder(mIconCache, apps,
3902 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3903 }
3904 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003905 }
Winson Chungc58497e2013-09-03 17:48:37 -07003906 } else {
3907 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3908 mAppsCustomizeContent != null) {
3909 mAppsCustomizeContent.setApps(apps);
3910 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003911 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003912 }
3913
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003914 @Override
3915 public boolean shouldShowApp(ResolveInfo app) {
3916 return true;
3917 }
3918
Joe Onorato9c1289c2009-08-17 11:03:03 -04003919 /**
3920 * A package was updated.
3921 *
3922 * Implementation of the method from LauncherModel.Callbacks.
3923 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003924 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003925 Runnable r = new Runnable() {
3926 public void run() {
3927 bindAppsUpdated(apps);
3928 }
3929 };
3930 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003931 return;
3932 }
3933
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003934 if (mWorkspace != null) {
3935 mWorkspace.updateShortcuts(apps);
3936 }
Winson Chungc58497e2013-09-03 17:48:37 -07003937
3938 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3939 mAppsCustomizeContent != null) {
3940 mAppsCustomizeContent.updateApps(apps);
3941 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003942 }
3943
3944 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003945 * A package was uninstalled. We take both the super set of packageNames
3946 * in addition to specific applications to remove, the reason being that
3947 * this can be called when a package is updated as well. In that scenario,
3948 * we only remove specific components from the workspace, where as
3949 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003950 *
3951 * Implementation of the method from LauncherModel.Callbacks.
3952 */
Winson Chung83892cc2013-05-01 16:53:33 -07003953 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003954 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003955 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003956 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003957 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003958 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003959 }
Winson Chungd64d1762013-08-20 14:37:16 -07003960 };
3961 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003962 return;
3963 }
3964
Winson Chung64359a52013-07-08 17:17:08 -07003965 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003966 mWorkspace.removeItemsByPackageName(packageNames);
3967 } else {
3968 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003969 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003970
Winson Chunga1820962011-10-03 16:31:06 -07003971 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003972 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003973
3974 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3975 mAppsCustomizeContent != null) {
3976 mAppsCustomizeContent.removeApps(appInfos);
3977 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003978 }
Joe Onoratobe386092009-11-17 17:32:16 -08003979
3980 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003981 * A number of packages were updated.
3982 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003983 private ArrayList<Object> mWidgetsAndShortcuts;
3984 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003985 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003986 bindPackagesUpdated(mWidgetsAndShortcuts);
3987 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003988 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003989 };
3990
3991 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3992 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3993 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003994 return;
3995 }
3996
Winson Chung64359a52013-07-08 17:17:08 -07003997 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003998 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3999 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004000 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004001 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004002 }
4003
Winson Chung400438b2011-01-16 17:53:48 -08004004 private int mapConfigurationOriActivityInfoOri(int configOri) {
4005 final Display d = getWindowManager().getDefaultDisplay();
4006 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4007 switch (d.getRotation()) {
4008 case Surface.ROTATION_0:
4009 case Surface.ROTATION_180:
4010 // We are currently in the same basic orientation as the natural orientation
4011 naturalOri = configOri;
4012 break;
4013 case Surface.ROTATION_90:
4014 case Surface.ROTATION_270:
4015 // We are currently in the other basic orientation to the natural orientation
4016 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4017 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4018 break;
4019 }
4020
4021 int[] oriMap = {
4022 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4023 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4024 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4025 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4026 };
4027 // Since the map starts at portrait, we need to offset if this device's natural orientation
4028 // is landscape.
4029 int indexOffset = 0;
4030 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4031 indexOffset = 1;
4032 }
4033 return oriMap[(d.getRotation() + indexOffset) % 4];
4034 }
Adam Cohen446e9402011-09-15 18:21:21 -07004035
Winson Chung4b919f82012-05-01 10:44:08 -07004036 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004037 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004038 getResources().getBoolean(R.bool.allow_rotation);
4039 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004040 }
Winson Chung4b919f82012-05-01 10:44:08 -07004041 public void lockScreenOrientation() {
4042 if (isRotationEnabled()) {
4043 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4044 .getConfiguration().orientation));
4045 }
4046 }
4047 public void unlockScreenOrientation(boolean immediate) {
4048 if (isRotationEnabled()) {
4049 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004050 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004051 } else {
4052 mHandler.postDelayed(new Runnable() {
4053 public void run() {
4054 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4055 }
4056 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004057 }
Winson Chung4b919f82012-05-01 10:44:08 -07004058 }
Winson Chung400438b2011-01-16 17:53:48 -08004059 }
4060
Winson Chung82f55532011-08-09 14:14:23 -07004061 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004062 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004063 if (DISABLE_CLINGS) {
4064 return false;
4065 }
4066
Brett Chabot2a9e2282011-08-23 15:03:13 -07004067 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004068 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004069
Michael Jurkae233a8b2013-03-19 13:49:20 +01004070 // Restricted secondary users (child mode) will potentially have very few apps
4071 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004072// boolean supportsLimitedUsers =
4073// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4074// Account[] accounts = AccountManager.get(this).getAccounts();
4075// if (supportsLimitedUsers && accounts.length == 0) {
4076// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4077// Bundle restrictions = um.getUserRestrictions();
4078// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4079// return false;
4080// }
4081// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004082 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004083 }
Michael Jurka22143132012-10-04 17:42:38 +02004084
Winson Chungaf40f202013-09-18 18:26:31 -07004085 private Cling initCling(int clingId, int[] positionData, boolean animate,
4086 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004087 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004088 if (cling != null) {
4089 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004090 cling.show(animate, SHOW_CLING_DURATION);
4091
4092 if (dimNavBarVisibilty) {
4093 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4094 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004095 }
4096 }
4097 return cling;
4098 }
Michael Jurka22143132012-10-04 17:42:38 +02004099
Winson Chungaf40f202013-09-18 18:26:31 -07004100 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4101 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004102 // To catch cases where siblings of top-level views are made invisible, just check whether
4103 // the cling is directly set to GONE before dismissing it.
4104 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004105 final Runnable cleanUpClingCb = new Runnable() {
4106 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004107 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004108 /*
Winson Chung46353de2012-02-16 14:05:10 -08004109 // We should update the shared preferences on a background thread
4110 new Thread("dismissClingThread") {
4111 public void run() {
4112 SharedPreferences.Editor editor = mSharedPrefs.edit();
4113 editor.putBoolean(flag, true);
4114 editor.commit();
4115 }
4116 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004117 */
4118 if (postAnimationCb != null) {
4119 postAnimationCb.run();
4120 }
4121 }
4122 };
4123 if (duration <= 0) {
4124 cleanUpClingCb.run();
4125 } else {
4126 cling.hide(duration, cleanUpClingCb);
4127 }
Michael Jurka22143132012-10-04 17:42:38 +02004128 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004129
4130 if (restoreNavBarVisibilty) {
4131 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4132 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4133 }
Winson Chung82f55532011-08-09 14:14:23 -07004134 }
4135 }
Michael Jurka22143132012-10-04 17:42:38 +02004136
Winson Chung9d9d74f2011-09-19 11:49:12 -07004137 private void removeCling(int id) {
4138 final View cling = findViewById(id);
4139 if (cling != null) {
4140 final ViewGroup parent = (ViewGroup) cling.getParent();
4141 parent.post(new Runnable() {
4142 @Override
4143 public void run() {
4144 parent.removeView(cling);
4145 }
4146 });
Michael Jurka22143132012-10-04 17:42:38 +02004147 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004148 }
4149 }
Michael Jurka974c3862012-05-22 22:00:31 -07004150
4151 private boolean skipCustomClingIfNoAccounts() {
4152 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4153 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4154 if (customCling) {
4155 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004156 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004157 Account[] accounts = am.getAccountsByType("com.google");
4158 return accounts.length == 0;
4159 }
4160 return false;
4161 }
4162
Winson Chungaf40f202013-09-18 18:26:31 -07004163 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004164 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004165 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004166 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004167 // If we're not using the default workspace layout, replace workspace cling
4168 // with a custom workspace cling (usually specified in an overlay)
4169 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004170 if (!DISABLE_CUSTOM_CLINGS) {
4171 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4172 getResources().getBoolean(R.bool.config_useCustomClings)) {
4173 // Use a custom cling
4174 View cling = findViewById(R.id.workspace_cling);
4175 ViewGroup clingParent = (ViewGroup) cling.getParent();
4176 int clingIndex = clingParent.indexOfChild(cling);
4177 clingParent.removeViewAt(clingIndex);
4178 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4179 clingParent.addView(customCling, clingIndex);
4180 customCling.setId(R.id.workspace_cling);
4181 }
4182 }
4183 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4184 if (cling != null) {
4185 String sbHintStr = getFirstRunClingSearchBarHint();
4186 String ccHintStr = getFirstRunCustomContentHint();
4187 if (!sbHintStr.isEmpty()) {
4188 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4189 sbHint.setText(sbHintStr);
4190 sbHint.setVisibility(View.VISIBLE);
4191 }
4192 if (!ccHintStr.isEmpty()) {
4193 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4194 ccHint.setText(ccHintStr);
4195 ccHint.setVisibility(View.VISIBLE);
4196 }
Michael Jurka45355c42012-10-08 13:21:35 +02004197 }
Winson Chungaf40f202013-09-18 18:26:31 -07004198 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004199 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004200 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004201 }
4202 }
Winson Chungaf40f202013-09-18 18:26:31 -07004203
Winson Chunge6eabff2013-09-24 11:01:23 -07004204 protected String getFirstRunClingSearchBarHint() {
4205 return "";
4206 }
4207 protected String getFirstRunCustomContentHint() {
4208 return "";
4209 }
4210
Winson Chungaf40f202013-09-18 18:26:31 -07004211 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004212 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004213 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004214 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4215 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004216 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004217 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004218 }
4219 }
4220 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004221 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004222 if (isClingsEnabled() &&
4223 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004224 Cling cling = initCling(R.id.folder_cling, null, true, true);
4225 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004226 } else {
4227 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004228 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004229 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004230 }
Michael Jurka104c4562013-07-08 18:03:46 -07004231 protected SharedPreferences getSharedPrefs() {
4232 return mSharedPrefs;
4233 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004234 public boolean isFolderClingVisible() {
4235 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004236 if (cling != null) {
4237 return cling.getVisibility() == View.VISIBLE;
4238 }
4239 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004240 }
Winson Chungaf40f202013-09-18 18:26:31 -07004241 public void dismissFirstRunCling(View v) {
4242 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4243 Runnable cb = new Runnable() {
4244 public void run() {
4245 // Show the workspace cling next
4246 showFirstRunWorkspaceCling();
4247 }
4248 };
4249 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4250 DISMISS_CLING_DURATION, false);
4251 }
Winson Chung82f55532011-08-09 14:14:23 -07004252 public void dismissWorkspaceCling(View v) {
4253 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004254 Runnable cb = null;
4255 if (v == null) {
4256 cb = new Runnable() {
4257 public void run() {
4258 mWorkspace.enterOverviewMode();
4259 }
4260 };
4261 }
4262 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4263 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004264 }
4265 public void dismissFolderCling(View v) {
4266 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004267 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4268 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004269 }
4270
Winson Chung80baf5a2010-08-09 16:03:15 -07004271 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004272 * Prints out out state for debugging.
4273 */
4274 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004275 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004276 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004277 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4278 Log.d(TAG, "mRestoring=" + mRestoring);
4279 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4280 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004281 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004282 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004283
Winson Chung785d2eb2011-04-14 16:08:02 -07004284 if (mAppsCustomizeContent != null) {
4285 mAppsCustomizeContent.dumpState();
4286 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004287 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004288 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004289
4290 @Override
4291 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4292 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004293 synchronized (sDumpLogs) {
4294 writer.println(" ");
4295 writer.println("Debug logs: ");
4296 for (int i = 0; i < sDumpLogs.size(); i++) {
4297 writer.println(" " + sDumpLogs.get(i));
4298 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004299 }
4300 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004301
4302 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004303 if (DEBUG_DUMP_LOG) {
4304 synchronized (sDumpLogs) {
4305 Log.d(TAG, "");
4306 Log.d(TAG, "*********************");
4307 Log.d(TAG, "Launcher debug logs: ");
4308 for (int i = 0; i < sDumpLogs.size(); i++) {
4309 Log.d(TAG, " " + sDumpLogs.get(i));
4310 }
4311 Log.d(TAG, "*********************");
4312 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004313 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004314 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004315 }
4316
4317 public static void addDumpLog(String tag, String log, boolean debugLog) {
4318 if (debugLog) {
4319 Log.d(tag, log);
4320 }
Winson Chungede41292013-09-19 16:27:36 -07004321 if (DEBUG_DUMP_LOG) {
4322 sDateStamp.setTime(System.currentTimeMillis());
4323 synchronized (sDumpLogs) {
4324 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004325 }
Winson Chungede41292013-09-19 16:27:36 -07004326 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004327 }
4328
Winson Chungede41292013-09-19 16:27:36 -07004329 public void dumpLogsToLocalData() {
4330 if (DEBUG_DUMP_LOG) {
4331 new Thread("DumpLogsToLocalData") {
4332 @Override
4333 public void run() {
4334 boolean success = false;
4335 sDateStamp.setTime(sRunStart);
4336 String FILENAME = sDateStamp.getMonth() + "-"
4337 + sDateStamp.getDay() + "_"
4338 + sDateStamp.getHours() + "-"
4339 + sDateStamp.getMinutes() + "_"
4340 + sDateStamp.getSeconds() + ".txt";
4341
4342 FileOutputStream fos = null;
4343 File outFile = null;
4344 try {
4345 outFile = new File(getFilesDir(), FILENAME);
4346 outFile.createNewFile();
4347 fos = new FileOutputStream(outFile);
4348 } catch (Exception e) {
4349 e.printStackTrace();
4350 }
4351 if (fos != null) {
4352 PrintWriter writer = new PrintWriter(fos);
4353
4354 writer.println(" ");
4355 writer.println("Debug logs: ");
4356 synchronized (sDumpLogs) {
4357 for (int i = 0; i < sDumpLogs.size(); i++) {
4358 writer.println(" " + sDumpLogs.get(i));
4359 }
4360 }
4361 writer.close();
4362 }
4363 try {
4364 if (fos != null) {
4365 fos.close();
4366 success = true;
4367 }
4368 } catch (IOException e) {
4369 e.printStackTrace();
4370 }
4371 }
4372 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004373 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004374 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004375}
Michael Jurka2763be32011-02-24 11:19:57 -08004376
Michael Jurkaabded662011-03-04 12:06:57 -08004377interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004378 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004379 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004380 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004381 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004382 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004383}