blob: 7e91ffe579aada029bed2b0d55ab1f6f8fda98c4 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700205 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700206 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
212 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700213 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700214
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800215 private final BroadcastReceiver mCloseSystemDialogsReceiver
216 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800217 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private LayoutInflater mInflater;
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700222 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800223 private DragLayer mDragLayer;
224 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700225 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700227 private AppWidgetManager mAppWidgetManager;
228 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700229
Michael Jurkac9d95c52011-08-29 14:03:34 -0700230 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700231 private AppWidgetProviderInfo mPendingAddWidgetInfo;
232
Michael Jurka0280c3b2010-09-17 15:00:07 -0700233 private int[] mTmpAddItemCellCoordinates = new int[2];
234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private FolderInfo mFolderInfo;
236
Winson Chung3d503fb2011-07-13 17:25:49 -0700237 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700238 private View mOverviewPanel;
239
Michael Jurka838a4ca2011-02-07 13:33:06 -0800240 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700241
Winson Chungc51db6a2011-10-05 11:44:49 -0700242 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700243 private AppsCustomizeTabHost mAppsCustomizeTabHost;
244 private AppsCustomizePagedView mAppsCustomizeContent;
245 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100246 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700249 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
250 // scroll issues (because the workspace may not have been measured yet) and extra work.
251 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
252 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
254 private SpannableStringBuilder mDefaultKeySsb = null;
255
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256 private boolean mWorkspaceLoading = true;
257
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800258 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private boolean mRestoring;
260 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700261 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262
Michael Jurka1e2f4652013-07-08 18:03:46 -0700263 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700264 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
265
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // Keep track of whether the user has left launcher
267 private static boolean sPausedFromUserAction = false;
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private Bundle mSavedInstanceState;
270
Joe Onorato9c1289c2009-08-17 11:03:03 -0400271 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800272 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800273 private boolean mUserPresent = true;
274 private boolean mVisible = false;
275 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700276 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static LocaleConfiguration sLocaleConfiguration = null;
279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700282 private Intent mAppMarketIntent = null;
283
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Craig Mautner360310b2012-10-26 15:13:08 -0700302 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700303
Adam Cohen1462de32012-07-24 22:34:36 -0700304 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
305
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700306 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700307 static Date sDateStamp = new Date();
308 static DateFormat sDateFormat =
309 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
310 static long sRunStart = System.currentTimeMillis();
311 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700312
Winson Chung46353de2012-02-16 14:05:10 -0800313 // We only want to get the SharedPreferences once since it does an FS stat each time we get
314 // it from the context.
315 private SharedPreferences mSharedPrefs;
316
Adam Cohene25af792013-06-06 23:08:25 -0700317 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
318
Winson Chungf0c6ae02012-03-21 16:10:31 -0700319 // Holds the page that we need to animate to, and the icon views that we need to animate up
320 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700321 private ImageView mFolderIconImageView;
322 private Bitmap mFolderIconBitmap;
323 private Canvas mFolderIconCanvas;
324 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700325
Michael Jurkaddd62e92011-02-16 17:49:14 -0800326 private BubbleTextView mWaitingForResume;
327
Michael Jurka22143132012-10-04 17:42:38 +0200328 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
329 = new HideFromAccessibilityHelper();
330
Michael Jurkac1f5d262011-09-30 19:32:27 -0700331 private Runnable mBuildLayersRunnable = new Runnable() {
332 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700333 if (mWorkspace != null) {
334 mWorkspace.buildPageHardwareLayers();
335 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 }
337 };
338
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800339 private static ArrayList<PendingAddArguments> sPendingAddList
340 = new ArrayList<PendingAddArguments>();
341
Michael Jurka0a457bf2012-11-19 14:05:05 -0800342 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static class PendingAddArguments {
345 int requestCode;
346 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700347 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700348 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 int cellX;
350 int cellY;
351 }
352
Daniel Sandlerff02d492013-08-05 02:12:05 -0400353 private Stats mStats;
354
Michael Jurka0a457bf2012-11-19 14:05:05 -0800355 private static boolean isPropertyEnabled(String propertyName) {
356 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700357 }
358
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 @Override
360 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700361 if (DEBUG_STRICT_MODE) {
362 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
363 .detectDiskReads()
364 .detectDiskWrites()
365 .detectNetwork() // or .detectAll() for all detectable problems
366 .penaltyLog()
367 .build());
368 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
369 .detectLeakedSqlLiteObjects()
370 .detectLeakedClosableObjects()
371 .penaltyLog()
372 .penaltyDeath()
373 .build());
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400377
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400378 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400379 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700380
381 // Determine the dynamic grid properties
382 Point smallestSize = new Point();
383 Point largestSize = new Point();
384 Point realSize = new Point();
385 Display display = getWindowManager().getDefaultDisplay();
386 display.getCurrentSizeRange(smallestSize, largestSize);
387 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700388 DisplayMetrics dm = new DisplayMetrics();
389 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700390 // Lazy-initialize the dynamic grid
391 DeviceProfile grid = app.initDynamicGrid(this,
392 Math.min(smallestSize.x, smallestSize.y),
393 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700394 realSize.x, realSize.y,
395 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700396
397 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400398 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700399 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800400 mModel = app.setLauncher(this);
401 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400402 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700404
Daniel Sandlerff02d492013-08-05 02:12:05 -0400405 mStats = new Stats(this);
406
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700407 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700408 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
409 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700410
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700411 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
412 // this also ensures that any synchronous binding below doesn't re-trigger another
413 // LauncherModel load.
414 mPaused = false;
415
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200417 android.os.Debug.startMethodTracing(
418 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 }
420
421 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 setContentView(R.layout.launcher);
423 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100424 grid.layout(this);
Winson Chung7d7541e2011-09-16 20:14:36 -0700425 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800427 registerContentObservers();
428
Joe Onorato7c312c12009-08-13 21:36:53 -0700429 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700430
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 mSavedState = savedInstanceState;
432 restoreState(mSavedState);
433
Winson Chunga12a2502010-12-20 14:41:35 -0800434 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700435 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200436 mAppsCustomizeContent.onPackagesUpdated(
437 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700438 }
Winson Chunga12a2502010-12-20 14:41:35 -0800439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
441 android.os.Debug.stopMethodTracing();
442 }
443
444 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700445 if (sPausedFromUserAction) {
446 // If the user leaves launcher, then we should just load items asynchronously when
447 // they return.
448 mModel.startLoader(true, -1);
449 } else {
450 // We only load the page synchronously if the user rotates (or triggers a
451 // configuration change) while launcher is in the foreground
452 mModel.startLoader(true, mWorkspace.getCurrentPage());
453 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 }
455
456 // For handling default keys
457 mDefaultKeySsb = new SpannableStringBuilder();
458 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800459
460 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
461 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800462
Adam Cohenf9426d52012-06-04 17:26:21 -0700463 updateGlobalIcons();
464
465 // On large interfaces, we want the screen to auto-rotate based on the current orientation
466 unlockScreenOrientation(true);
467 }
468
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 protected void onUserLeaveHint() {
470 super.onUserLeaveHint();
471 sPausedFromUserAction = true;
472 }
473
Winson Chung98ca0f72013-07-29 12:58:51 -0700474 /** To be overriden by subclasses to hint to Launcher that we have custom content */
475 protected boolean hasCustomContentToLeft() {
476 return false;
477 }
478
Dave Hawkeya8881582013-09-17 15:55:33 -0600479 /**
480 * To be overridden by subclasses to create the custom content and call
481 * {@link #addToCustomContentPage}. This will only be invoked if
482 * {@link #hasCustomContentToLeft()} is {@code true}.
483 */
484 protected void addCustomContentToLeft() {
485 }
486
487 /**
488 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
489 * ensure the custom content page is added or removed if necessary.
490 */
491 protected void invalidateHasCustomContentToLeft() {
492 if (mWorkspace.getScreenOrder().isEmpty()) {
493 // Not bound yet, wait for bindScreens to be called.
494 return;
495 }
496
497 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
498 // Create the custom content page and call the subclass to populate it.
499 mWorkspace.createCustomContentPage();
500 addCustomContentToLeft();
501 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
502 mWorkspace.removeCustomContentPage();
503 }
504 }
505
Adam Cohenf9426d52012-06-04 17:26:21 -0700506 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700507 boolean searchVisible = false;
508 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800509 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700510 int coi = getCurrentOrientationIndexForGlobalIcons();
511 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
512 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700513 updateAppMarketIcon();
514 searchVisible = updateGlobalSearchIcon();
515 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700516 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700517 if (sGlobalSearchIcon[coi] != null) {
518 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700519 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700520 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700521 if (sVoiceSearchIcon[coi] != null) {
522 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700523 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700524 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700525 if (sAppMarketIcon[coi] != null) {
526 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800527 }
Winson Chungadf0c182012-08-23 14:59:07 -0700528 if (mSearchDropTargetBar != null) {
529 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
530 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 }
Romain Guycbb89e42009-06-08 15:52:54 -0700532
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800533 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700534 if (sLocaleConfiguration == null) {
535 new AsyncTask<Void, Void, LocaleConfiguration>() {
536 @Override
537 protected LocaleConfiguration doInBackground(Void... unused) {
538 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
539 readConfiguration(Launcher.this, localeConfiguration);
540 return localeConfiguration;
541 }
542
543 @Override
544 protected void onPostExecute(LocaleConfiguration result) {
545 sLocaleConfiguration = result;
546 checkForLocaleChange(); // recursive, but now with a locale configuration
547 }
548 }.execute();
549 return;
550 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700551
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800552 final Configuration configuration = getResources().getConfiguration();
553
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700554 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800555 final String locale = configuration.locale.toString();
556
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700557 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800558 final int mcc = configuration.mcc;
559
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700560 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 final int mnc = configuration.mnc;
562
Romain Guy84f296c2009-11-04 15:00:44 -0800563 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564
Romain Guy84f296c2009-11-04 15:00:44 -0800565 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700566 sLocaleConfiguration.locale = locale;
567 sLocaleConfiguration.mcc = mcc;
568 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700569
Joe Onorato0589f0f2010-02-08 13:44:00 -0800570 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700571
572 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
573 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700574 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700575 public void run() {
576 writeConfiguration(Launcher.this, localeConfiguration);
577 }
578 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700579 }
580 }
581
582 private static class LocaleConfiguration {
583 public String locale;
584 public int mcc = -1;
585 public int mnc = -1;
586 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700587
Romain Guy98d01652009-06-30 16:21:04 -0700588 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
589 DataInputStream in = null;
590 try {
591 in = new DataInputStream(context.openFileInput(PREFERENCES));
592 configuration.locale = in.readUTF();
593 configuration.mcc = in.readInt();
594 configuration.mnc = in.readInt();
595 } catch (FileNotFoundException e) {
596 // Ignore
597 } catch (IOException e) {
598 // Ignore
599 } finally {
600 if (in != null) {
601 try {
602 in.close();
603 } catch (IOException e) {
604 // Ignore
605 }
606 }
607 }
608 }
609
610 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
611 DataOutputStream out = null;
612 try {
613 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
614 out.writeUTF(configuration.locale);
615 out.writeInt(configuration.mcc);
616 out.writeInt(configuration.mnc);
617 out.flush();
618 } catch (FileNotFoundException e) {
619 // Ignore
620 } catch (IOException e) {
621 //noinspection ResultOfMethodCallIgnored
622 context.getFileStreamPath(PREFERENCES).delete();
623 } finally {
624 if (out != null) {
625 try {
626 out.close();
627 } catch (IOException e) {
628 // Ignore
629 }
630 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800631 }
632 }
633
Bjorn Bringertc459e522013-06-07 19:36:01 +0100634 public LayoutInflater getInflater() {
635 return mInflater;
636 }
637
Adam Cohen716b51e2011-06-30 12:09:54 -0700638 public DragLayer getDragLayer() {
639 return mDragLayer;
640 }
641
Winson Chung36a62fe2012-05-06 18:04:42 -0700642 boolean isDraggingEnabled() {
643 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
644 // that is subsequently removed from the workspace in startBinding().
645 return !mModel.isLoadingWorkspace();
646 }
647
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 static int getScreen() {
649 synchronized (sLock) {
650 return sScreen;
651 }
652 }
653
654 static void setScreen(int screen) {
655 synchronized (sLock) {
656 sScreen = screen;
657 }
658 }
659
Winson Chung557d6ed2011-07-08 15:34:52 -0700660 /**
661 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
662 * a configuration step, this allows the proper animations to run after other transitions.
663 */
664 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700665 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800666 switch (args.requestCode) {
667 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700668 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700669 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800670 break;
671 case REQUEST_PICK_SHORTCUT:
672 processShortcut(args.intent);
673 break;
674 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700675 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700676 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700677 result = true;
678 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800679 case REQUEST_CREATE_APPWIDGET:
680 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700681 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700682 result = true;
683 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800684 }
Michael Jurka27614d22012-04-02 06:40:22 -0700685 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
686 // if you turned the screen off and then back while in All Apps, Launcher would not
687 // return to the workspace. Clearing mAddInfo.container here fixes this issue
688 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800690 }
691
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700693 protected void onActivityResult(
694 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700695 // Reset the startActivity waiting flag
696 mWaitingForResult = false;
697
Michael Jurka8b805b12012-04-18 14:23:14 -0700698 if (requestCode == REQUEST_BIND_APPWIDGET) {
699 int appWidgetId = data != null ?
700 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
701 if (resultCode == RESULT_CANCELED) {
702 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
703 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700704 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 }
706 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200707 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
708 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
709 mWorkspace.exitOverviewMode(false);
710 }
711 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200713
Winson Chung557d6ed2011-07-08 15:34:52 -0700714 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800715 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
716 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700717
Adam Cohened66b2b2012-01-23 17:28:51 -0800718 // We have special handling for widgets
719 if (isWidgetDrop) {
720 int appWidgetId = data != null ?
721 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700722 if (appWidgetId < 0) {
723 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
724 "widget configuration activity.");
725 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
726 } else {
727 completeTwoStageWidgetDrop(resultCode, appWidgetId);
728 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800729 return;
730 }
731
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 // The pattern used here is that a user PICKs a specific application,
733 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700734
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
736 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700737 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 final PendingAddArguments args = new PendingAddArguments();
739 args.requestCode = requestCode;
740 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700741 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700742 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700743 args.cellX = mPendingAddInfo.cellX;
744 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 if (isWorkspaceLocked()) {
746 sPendingAddList.add(args);
747 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700748 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800751 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700752 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800753 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
754 null);
755 }
756
757 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700758 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700759 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800760 Runnable onCompleteRunnable = null;
761 int animationType = 0;
762
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700763 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800764 if (resultCode == RESULT_OK) {
765 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
766 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700767 mPendingAddWidgetInfo);
768 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800769 onCompleteRunnable = new Runnable() {
770 @Override
771 public void run() {
772 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700773 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800774 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
775 null);
776 }
777 };
778 } else if (resultCode == RESULT_CANCELED) {
779 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
780 onCompleteRunnable = new Runnable() {
781 @Override
782 public void run() {
783 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
784 null);
785 }
786 };
787 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700788 if (mDragLayer.getAnimatedView() != null) {
789 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
790 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
791 animationType, boundWidget, true);
792 } else {
793 // The animated view may be null in the case of a rotation during widget configuration
794 onCompleteRunnable.run();
795 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 }
797
798 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700799 protected void onStop() {
800 super.onStop();
801 FirstFrameAnimatorHelper.setIsVisible(false);
802 }
803
804 @Override
805 protected void onStart() {
806 super.onStart();
807 FirstFrameAnimatorHelper.setIsVisible(true);
808 }
809
810 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200812 long startTime = 0;
813 if (DEBUG_RESUME_TIME) {
814 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400815 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700818
Winson Chung4a2afa32012-07-19 14:53:05 -0700819 // Restore the previous launcher state
820 if (mOnResumeState == State.WORKSPACE) {
821 showWorkspace(false);
822 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700823 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700824 }
825 mOnResumeState = State.NONE;
826
Craig Mautner360310b2012-10-26 15:13:08 -0700827 // Background was set to gradient in onPause(), restore to black if in all apps.
828 setWorkspaceBackground(mState == State.WORKSPACE);
829
Winson Chungde0fb8f2012-05-08 14:37:08 -0700830 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700831 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700832
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800833 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700834 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700835 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400836 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700837 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400838 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700839 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700841 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200842 // We might have postponed some bind calls until onResume (see waitUntilResume) --
843 // execute them here
844 long startTimeCallbacks = 0;
845 if (DEBUG_RESUME_TIME) {
846 startTimeCallbacks = System.currentTimeMillis();
847 }
848
849 if (mAppsCustomizeContent != null) {
850 mAppsCustomizeContent.setBulkBind(true);
851 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700852 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
853 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200854 }
855 if (mAppsCustomizeContent != null) {
856 mAppsCustomizeContent.setBulkBind(false);
857 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700858 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200859 if (DEBUG_RESUME_TIME) {
860 Log.d(TAG, "Time spent processing callbacks in onResume: " +
861 (System.currentTimeMillis() - startTimeCallbacks));
862 }
Michael Jurka447bf842013-05-15 14:52:15 +0200863 }
Michael Jurka54554252013-08-01 12:52:23 +0200864 if (mOnResumeCallbacks.size() > 0) {
865 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
866 mOnResumeCallbacks.get(i).run();
867 }
868 mOnResumeCallbacks.clear();
869 }
Winson Chunge4e50662012-01-23 14:45:13 -0800870
871 // Reset the pressed state of icons that were locked in the press state while activities
872 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800873 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800874 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800875 mWaitingForResume.setStayPressed(false);
876 }
Winson Chunge4e50662012-01-23 14:45:13 -0800877 if (mAppsCustomizeContent != null) {
878 // Resets the previous all apps icon press state
879 mAppsCustomizeContent.resetDrawableState();
880 }
Adam Cohen06dff352012-06-01 17:17:08 -0700881 // It is possible that widgets can receive updates while launcher is not in the foreground.
882 // Consequently, the widgets will be inflated in the orientation of the foreground activity
883 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
884 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700885 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700886
887 // Again, as with the above scenario, it's possible that one or more of the global icons
888 // were updated in the wrong orientation.
889 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200890 if (DEBUG_RESUME_TIME) {
891 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
892 }
Adam Cohen06dff352012-06-01 17:17:08 -0700893 }
894
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800895 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700896 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700897 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
898 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
899 // when Launcher resumes and we are still in AllApps.
900 updateWallpaperVisibility(true);
901
Winson Chung997a9232013-07-24 15:33:46 -0700902 // Ensure that items added to Launcher are queued until Launcher returns
903 InstallShortcutReceiver.enableInstallQueue();
904
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700905 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700906 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800907 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700908 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700909 }
Romain Guycbb89e42009-06-08 15:52:54 -0700910
Adam Cohen66a01fd2013-06-11 12:48:00 -0700911 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600912 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
913 addCustomContentToLeft();
914 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700915 }
916
Adam Cohenbffe7452013-07-22 18:21:45 -0700917 QSBScroller mQsbScroller = new QSBScroller() {
918 int scrollY = 0;
919
920 @Override
921 public void setScrollY(int scroll) {
922 scrollY = scroll;
923
924 if (mWorkspace.isOnOrMovingToCustomContent()) {
925 mSearchDropTargetBar.setTranslationY(- scrollY);
926 }
927 }
928 };
929
930 public void resetQSBScroll() {
931 mSearchDropTargetBar.animate().translationY(0).start();
932 }
933
934 public interface CustomContentCallbacks {
935 // Custom content is completely shown
936 public void onShow();
937
938 // Custom content is completely hidden
939 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700940
941 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
942 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700943 }
944
Adam Cohen30bacb22013-08-29 14:25:25 -0700945 protected void startSettings() {
946 }
947
Adam Cohenbffe7452013-07-22 18:21:45 -0700948 public interface QSBScroller {
949 public void setScrollY(int scrollY);
950 }
951
Adam Cohen66a01fd2013-06-11 12:48:00 -0700952 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700953 public QSBScroller addToCustomContentPage(View customContent) {
954 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700955 }
956
Winson Chung98ca0f72013-07-29 12:58:51 -0700957 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700958 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700959 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700960 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700961 }
962
Adam Cohenedb40762013-07-18 16:45:45 -0700963 // The custom content needs to offset its content to account for the QSB
964 public int getTopOffsetForCustomContent() {
965 return mWorkspace.getPaddingTop();
966 }
967
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700968 @Override
969 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400970 // Flag the loader to stop early before switching
971 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700972 if (mAppsCustomizeContent != null) {
973 mAppsCustomizeContent.surrender();
974 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800975 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700976 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700977
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800978 // We can't hide the IME if it was forced open. So don't bother
979 /*
980 @Override
981 public void onWindowFocusChanged(boolean hasFocus) {
982 super.onWindowFocusChanged(hasFocus);
983
984 if (hasFocus) {
985 final InputMethodManager inputManager = (InputMethodManager)
986 getSystemService(Context.INPUT_METHOD_SERVICE);
987 WindowManager.LayoutParams lp = getWindow().getAttributes();
988 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
989 android.os.Handler()) {
990 protected void onReceiveResult(int resultCode, Bundle resultData) {
991 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
992 }
993 });
994 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
995 }
996 }
997 */
998
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800999 private boolean acceptFilter() {
1000 final InputMethodManager inputManager = (InputMethodManager)
1001 getSystemService(Context.INPUT_METHOD_SERVICE);
1002 return !inputManager.isFullscreenMode();
1003 }
1004
1005 @Override
1006 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001007 final int uniChar = event.getUnicodeChar();
1008 final boolean handled = super.onKeyDown(keyCode, event);
1009 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1010 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1012 keyCode, event);
1013 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001014 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001015 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001016 // showSearchDialog()
1017 // If there are multiple keystrokes before the search dialog takes focus,
1018 // onSearchRequested() will be called for every keystroke,
1019 // but it is idempotent, so it's fine.
1020 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 }
1022 }
1023
Joe Onorato8a9625e2010-01-28 15:55:35 -08001024 // Eat the long press event so the keyboard doesn't come up.
1025 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1026 return true;
1027 }
1028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 return handled;
1030 }
1031
Karl Rosaen138a0412009-04-23 19:00:21 -07001032 private String getTypedText() {
1033 return mDefaultKeySsb.toString();
1034 }
1035
1036 private void clearTypedText() {
1037 mDefaultKeySsb.clear();
1038 mDefaultKeySsb.clearSpans();
1039 Selection.setSelection(mDefaultKeySsb, 0);
1040 }
1041
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001042 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001043 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1044 * State
1045 */
1046 private static State intToState(int stateOrdinal) {
1047 State state = State.WORKSPACE;
1048 final State[] stateValues = State.values();
1049 for (int i = 0; i < stateValues.length; i++) {
1050 if (stateValues[i].ordinal() == stateOrdinal) {
1051 state = stateValues[i];
1052 break;
1053 }
1054 }
1055 return state;
1056 }
1057
1058 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 * Restores the previous state, if it exists.
1060 *
1061 * @param savedState The previous state.
1062 */
1063 private void restoreState(Bundle savedState) {
1064 if (savedState == null) {
1065 return;
1066 }
1067
Michael Jurka883f55b2010-10-21 15:47:14 -07001068 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001069 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001070 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001071 }
1072
Winson Chungf0c6ae02012-03-21 16:10:31 -07001073 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001075 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 }
1077
Winson Chung3d503fb2011-07-13 17:25:49 -07001078 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001079 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001080
Winson Chung3d503fb2011-07-13 17:25:49 -07001081 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1082 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001083 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001084 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1085 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001086 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1087 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1088 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001089 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090 mRestoring = true;
1091 }
1092
1093 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1094 if (renameFolder) {
1095 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001096 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 mRestoring = true;
1098 }
Winson Chunga12a2502010-12-20 14:41:35 -08001099
Winson Chung785d2eb2011-04-14 16:08:02 -07001100 // Restore the AppsCustomize tab
1101 if (mAppsCustomizeTabHost != null) {
1102 String curTab = savedState.getString("apps_customize_currentTab");
1103 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001104 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001105 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001106 mAppsCustomizeContent.loadAssociatedPages(
1107 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001108 }
1109
Winson Chung5afbf7b2011-07-25 11:53:08 -07001110 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1111 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 }
1114
1115 /**
1116 * Finds all the views we need and configure them properly.
1117 */
1118 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001119 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001120
Craig Mautner360310b2012-10-26 15:13:08 -07001121 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001122 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1123 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001124
John Spurlock77e1f472013-09-11 10:09:51 -04001125 mLauncherView.setSystemUiVisibility(
1126 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001127 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128
Winson Chung4c98d922011-05-31 16:50:48 -07001129 // Setup the drag layer
1130 mDragLayer.setup(this, dragController);
1131
Winson Chung3d503fb2011-07-13 17:25:49 -07001132 // Setup the hotseat
1133 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1134 if (mHotseat != null) {
1135 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001136 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001137 }
1138
Adam Cohenf358a4b2013-07-23 16:47:31 -07001139 mOverviewPanel = findViewById(R.id.overview_panel);
1140 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1141 @Override
1142 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001143 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001144 }
1145 });
1146 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1147 @Override
1148 public void onClick(View arg0) {
1149 startWallpaper();
1150 }
1151 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001152 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1153 @Override
1154 public void onClick(View arg0) {
1155 startSettings();
1156 }
1157 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001158 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001159
Winson Chung4c98d922011-05-31 16:50:48 -07001160 // Setup the workspace
1161 mWorkspace.setHapticFeedbackEnabled(false);
1162 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001163 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001164 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001165
Winson Chungf0ea4d32011-06-06 14:27:16 -07001166 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001167 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001168
Winson Chungf0ea4d32011-06-06 14:27:16 -07001169 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001170 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001171 mAppsCustomizeContent = (AppsCustomizePagedView)
1172 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1173 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001174
Winson Chung3d503fb2011-07-13 17:25:49 -07001175 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001176 dragController.setDragScoller(mWorkspace);
1177 dragController.setScrollView(mDragLayer);
1178 dragController.setMoveTarget(mWorkspace);
1179 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001180 if (mSearchDropTargetBar != null) {
1181 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001182 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001183
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001184 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001185 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001186 mWeightWatcher = new WeightWatcher(this);
1187 mWeightWatcher.setAlpha(0.5f);
1188 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001189 new FrameLayout.LayoutParams(
1190 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001191 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001192 Gravity.BOTTOM)
1193 );
Adam Cohen39a06042013-07-19 14:30:12 -07001194
1195 boolean show = shouldShowWeightWatcher();
1196 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001197 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 }
1199
1200 /**
1201 * Creates a view representing a shortcut.
1202 *
1203 * @param info The data structure describing the shortcut.
1204 *
1205 * @return A View inflated from R.layout.application.
1206 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001207 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001209 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 }
1211
1212 /**
1213 * Creates a view representing a shortcut inflated from the specified resource.
1214 *
1215 * @param layoutResId The id of the XML layout used to create the shortcut.
1216 * @param parent The group the shortcut belongs to.
1217 * @param info The data structure describing the shortcut.
1218 *
1219 * @return A View inflated from layoutResId.
1220 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001221 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001222 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1223 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225 return favorite;
1226 }
1227
1228 /**
1229 * Add an application shortcut to the workspace.
1230 *
1231 * @param data The intent describing the application.
1232 * @param cellInfo The position on screen where to create the shortcut.
1233 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001234 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001235 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001236 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001237
Adam Cohenfbba09b2011-07-18 21:43:05 -07001238 // First we check if we already know the exact location where we want to add this item.
1239 if (cellX >= 0 && cellY >= 0) {
1240 cellXY[0] = cellX;
1241 cellXY[1] = cellY;
1242 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001243 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001244 return;
1245 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001246
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001247 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001248
Romain Guy73b979d2009-06-09 12:57:21 -07001249 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001250 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001252 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001253 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001254 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001255 } else {
1256 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 }
1258 }
Romain Guycbb89e42009-06-08 15:52:54 -07001259
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 /**
1261 * Add a shortcut to the workspace.
1262 *
1263 * @param data The intent describing the shortcut.
1264 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001266 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001267 int cellY) {
1268 int[] cellXY = mTmpAddItemCellCoordinates;
1269 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001270 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001271
Michael Jurkad3ef3062010-11-23 16:23:58 -08001272 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001273
Adam Cohen558baaf2011-08-15 15:22:57 -07001274 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001275 if (info == null) {
1276 return;
1277 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001278 final View view = createShortcut(info);
1279
Adam Cohenfbba09b2011-07-18 21:43:05 -07001280 // First we check if we already know the exact location where we want to add this item.
1281 if (cellX >= 0 && cellY >= 0) {
1282 cellXY[0] = cellX;
1283 cellXY[1] = cellY;
1284 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001285
1286 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001287 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001288 true, null,null)) {
1289 return;
1290 }
1291 DragObject dragObject = new DragObject();
1292 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001293 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1294 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001295 return;
1296 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001297 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001298 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001299 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001300 foundCellSpan = (result != null);
1301 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001302 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001303 }
1304
1305 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001306 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001307 return;
1308 }
1309
Adam Cohendcd297f2013-06-18 13:13:40 -07001310 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311
1312 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001313 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001314 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 }
1316 }
1317
Adam Cohen2f093b62012-04-30 18:59:53 -07001318 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1319 int minHeight) {
1320 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001321 // We want to account for the extra amount of padding that we are adding to the widget
1322 // to ensure that it gets the full amount of space that it has requested
1323 int requiredWidth = minWidth + padding.left + padding.right;
1324 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001325 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001326 }
1327
Adam Cohen2f093b62012-04-30 18:59:53 -07001328 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1329 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001330 }
1331
Adam Cohen2f093b62012-04-30 18:59:53 -07001332 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1333 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001334 }
1335
Adam Cohen2f093b62012-04-30 18:59:53 -07001336 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1337 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001338 }
1339
Adam Cohen2f093b62012-04-30 18:59:53 -07001340 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1341 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001342 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001343 }
1344
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001346 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001348 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001349 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001351 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001352 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1353 if (appWidgetInfo == null) {
1354 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1355 }
Romain Guycbb89e42009-06-08 15:52:54 -07001356
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001357 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001358 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001359
Adam Cohen2f093b62012-04-30 18:59:53 -07001360 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1361 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001362
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001364 // We have saved the position to which the widget was dragged-- this really only matters
1365 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001366 int[] cellXY = mTmpAddItemCellCoordinates;
1367 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001368 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001369 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1371 cellXY[0] = mPendingAddInfo.cellX;
1372 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001373 spanXY[0] = mPendingAddInfo.spanX;
1374 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001375 foundCellSpan = true;
1376 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001377 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001379 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1380 spanXY[1], cellXY, finalSpan);
1381 spanXY[0] = finalSpan[0];
1382 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001383 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001384 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001385 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001386 }
1387
Michael Jurka0280c3b2010-09-17 15:00:07 -07001388 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001389 if (appWidgetId != -1) {
1390 // Deleting an app widget ID is a void call but writes to disk before returning
1391 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001392 new Thread("deleteAppWidgetId") {
1393 public void run() {
1394 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1395 }
1396 }.start();
1397 }
Winson Chung93eef082012-03-23 15:59:27 -07001398 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001399 return;
1400 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001402 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001403 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1404 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001405 launcherInfo.spanX = spanXY[0];
1406 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001407 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1408 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001409
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001411 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412
1413 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001414 if (hostView == null) {
1415 // Perform actual inflation because we're live
1416 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1417 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1418 } else {
1419 // The AppWidgetHostView has already been inflated and instantiated
1420 launcherInfo.hostView = hostView;
1421 }
Romain Guycbb89e42009-06-08 15:52:54 -07001422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001424 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001425 launcherInfo.notifyWidgetSizeChanged(this);
1426
Adam Cohendcd297f2013-06-18 13:13:40 -07001427 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001428 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001429
1430 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001432 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 }
Romain Guycbb89e42009-06-08 15:52:54 -07001434
Adam Cohended9f8d2010-11-03 13:25:16 -07001435 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1436 @Override
1437 public void onReceive(Context context, Intent intent) {
1438 final String action = intent.getAction();
1439 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1440 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001441 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001442 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001443
Winson Chungc100e8e2011-08-09 16:02:43 -07001444 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001445 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001446 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1447 mAppsCustomizeTabHost.reset();
Adam Cohen040a5d22013-09-16 17:09:33 -07001448 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001449 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001450 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1451 mUserPresent = true;
1452 updateRunning();
1453 }
1454 }
1455 };
1456
1457 @Override
1458 public void onAttachedToWindow() {
1459 super.onAttachedToWindow();
1460
1461 // Listen for broadcasts related to user-presence
1462 final IntentFilter filter = new IntentFilter();
1463 filter.addAction(Intent.ACTION_SCREEN_OFF);
1464 filter.addAction(Intent.ACTION_USER_PRESENT);
1465 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001466 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001467 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001468 mVisible = true;
1469 }
1470
1471 @Override
1472 public void onDetachedFromWindow() {
1473 super.onDetachedFromWindow();
1474 mVisible = false;
1475
Adam Cohend113e0c2010-11-11 10:48:05 -08001476 if (mAttached) {
1477 unregisterReceiver(mReceiver);
1478 mAttached = false;
1479 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001480 updateRunning();
1481 }
1482
1483 public void onWindowVisibilityChanged(int visibility) {
1484 mVisible = visibility == View.VISIBLE;
1485 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001486 // The following code used to be in onResume, but it turns out onResume is called when
1487 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1488 // is a more appropriate event to handle
1489 if (mVisible) {
1490 mAppsCustomizeTabHost.onWindowVisible();
1491 if (!mWorkspaceLoading) {
1492 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001493 // We want to let Launcher draw itself at least once before we force it to build
1494 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001495 // apps is nice and speedy.
1496 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001497 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001498 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001499 if (mStarted) return;
1500 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001501 // We delay the layer building a bit in order to give
1502 // other message processing a time to run. In particular
1503 // this avoids a delay in hiding the IME if it was
1504 // currently shown, because doing that may involve
1505 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001506 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001507 final ViewTreeObserver.OnDrawListener listener = this;
1508 mWorkspace.post(new Runnable() {
1509 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001510 if (mWorkspace != null &&
1511 mWorkspace.getViewTreeObserver() != null) {
1512 mWorkspace.getViewTreeObserver().
1513 removeOnDrawListener(listener);
1514 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001515 }
1516 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001517 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001518 }
1519 });
1520 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001521 // When Launcher comes back to foreground, a different Activity might be responsible for
1522 // the app market intent, so refresh the icon
1523 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001524 clearTypedText();
1525 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001526 }
1527
1528 private void sendAdvanceMessage(long delay) {
1529 mHandler.removeMessages(ADVANCE_MSG);
1530 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1531 mHandler.sendMessageDelayed(msg, delay);
1532 mAutoAdvanceSentTime = System.currentTimeMillis();
1533 }
1534
1535 private void updateRunning() {
1536 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1537 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1538 mAutoAdvanceRunning = autoAdvanceRunning;
1539 if (autoAdvanceRunning) {
1540 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1541 sendAdvanceMessage(delay);
1542 } else {
1543 if (!mWidgetsToAdvance.isEmpty()) {
1544 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1545 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1546 }
1547 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001548 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001549 }
1550 }
1551 }
1552
1553 private final Handler mHandler = new Handler() {
1554 @Override
1555 public void handleMessage(Message msg) {
1556 if (msg.what == ADVANCE_MSG) {
1557 int i = 0;
1558 for (View key: mWidgetsToAdvance.keySet()) {
1559 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1560 final int delay = mAdvanceStagger * i;
1561 if (v instanceof Advanceable) {
1562 postDelayed(new Runnable() {
1563 public void run() {
1564 ((Advanceable) v).advance();
1565 }
1566 }, delay);
1567 }
1568 i++;
1569 }
1570 sendAdvanceMessage(mAdvanceInterval);
1571 }
1572 }
1573 };
1574
1575 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001576 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001577 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1578 if (v instanceof Advanceable) {
1579 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001580 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001581 updateRunning();
1582 }
1583 }
1584
1585 void removeWidgetToAutoAdvance(View hostView) {
1586 if (mWidgetsToAdvance.containsKey(hostView)) {
1587 mWidgetsToAdvance.remove(hostView);
1588 updateRunning();
1589 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001590 }
1591
Joe Onorato9c1289c2009-08-17 11:03:03 -04001592 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001593 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001594 launcherInfo.hostView = null;
1595 }
1596
Winson Chung93eef082012-03-23 15:59:27 -07001597 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1598 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1599 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 }
1601
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001602 public LauncherAppWidgetHost getAppWidgetHost() {
1603 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 }
Romain Guycbb89e42009-06-08 15:52:54 -07001605
Winson Chunga9abd0e2010-10-27 17:18:37 -07001606 public LauncherModel getModel() {
1607 return mModel;
1608 }
1609
Bjorn Bringertc459e522013-06-07 19:36:01 +01001610 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001611 getWindow().closeAllPanels();
1612
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001613 // Whatever we were doing is hereby canceled.
1614 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001615 }
1616
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001617 @Override
1618 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001619 long startTime = 0;
1620 if (DEBUG_RESUME_TIME) {
1621 startTime = System.currentTimeMillis();
1622 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001623 super.onNewIntent(intent);
1624
1625 // Close the menu
1626 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001627 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001628 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001629
Jamie Genniscb222e82012-10-23 15:44:26 -07001630 final boolean alreadyOnHome =
1631 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001632 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001633
Jamie Genniscb222e82012-10-23 15:44:26 -07001634 Runnable processIntent = new Runnable() {
1635 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001636 if (mWorkspace == null) {
1637 // Can be cases where mWorkspace is null, this prevents a NPE
1638 return;
1639 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001640 Folder openFolder = mWorkspace.getOpenFolder();
1641 // In all these cases, only animate if we're already on home
1642 mWorkspace.exitWidgetResizeMode();
1643 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1644 openFolder == null) {
1645 mWorkspace.moveToDefaultScreen(true);
1646 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001647
Jamie Genniscb222e82012-10-23 15:44:26 -07001648 closeFolder();
1649 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001650
Jamie Genniscb222e82012-10-23 15:44:26 -07001651 // If we are already on home, then just animate back to the workspace,
1652 // otherwise, just wait until onResume to set the state back to Workspace
1653 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001654 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001655 } else {
1656 mOnResumeState = State.WORKSPACE;
1657 }
1658
1659 final View v = getWindow().peekDecorView();
1660 if (v != null && v.getWindowToken() != null) {
1661 InputMethodManager imm = (InputMethodManager)getSystemService(
1662 INPUT_METHOD_SERVICE);
1663 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1664 }
1665
1666 // Reset AllApps to its initial state
1667 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1668 mAppsCustomizeTabHost.reset();
1669 }
1670 }
1671 };
1672
1673 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1674 // Delay processing of the intent to allow the status bar animation to finish
1675 // first in order to avoid janky animations.
1676 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001677 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001678 // Process the intent immediately.
1679 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001680 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001681
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682 }
Michael Jurka447bf842013-05-15 14:52:15 +02001683 if (DEBUG_RESUME_TIME) {
1684 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1685 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001686 }
1687
Adam Cohen040a5d22013-09-16 17:09:33 -07001688 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1689 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001690 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001691 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001692 }
1693 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001694 protected void showWorkspaceAndExitOverviewMode() {
1695 showWorkspaceAndExitOverviewMode(true);
1696 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001697
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001699 public void onRestoreInstanceState(Bundle state) {
1700 super.onRestoreInstanceState(state);
1701 for (int page: mSynchronouslyBoundPages) {
1702 mWorkspace.restoreInstanceStateForChild(page);
1703 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 }
1705
1706 @Override
1707 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001708 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001709 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710
Michael Jurka883f55b2010-10-21 15:47:14 -07001711 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001712 // We close any open folder since it will not be re-opened, and we need to make sure
1713 // this state is reflected.
1714 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715
Adam Cohendcd297f2013-06-18 13:13:40 -07001716 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001717 mWaitingForResult) {
1718 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001719 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001720 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1721 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001722 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1723 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1724 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 }
1726
1727 if (mFolderInfo != null && mWaitingForResult) {
1728 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1729 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1730 }
Michael Jurka946ad472010-07-09 18:05:18 -07001731
Winson Chung785d2eb2011-04-14 16:08:02 -07001732 // Save the current AppsCustomize tab
1733 if (mAppsCustomizeTabHost != null) {
1734 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1735 if (currentTabTag != null) {
1736 outState.putString("apps_customize_currentTab", currentTabTag);
1737 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001738 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1739 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 }
1742
1743 @Override
1744 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001745 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001746
Winson Chunge7a03942011-08-05 15:05:12 -07001747 // Remove all pending runnables
1748 mHandler.removeMessages(ADVANCE_MSG);
1749 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001750 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001751
Winson Chungcd2b0142011-06-08 16:02:26 -07001752 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001753 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001754 mModel.stopLoader();
1755 app.setLauncher(null);
1756
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001758 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001760 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001761 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001762 mAppWidgetHost = null;
1763
1764 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765
1766 TextKeyListener.getInstance().release();
1767
Winson Chung81b52252012-08-27 15:34:29 -07001768 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1769 // to prevent leaking Launcher activities on orientation change.
1770 if (mModel != null) {
1771 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1772 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001773
1774 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001775 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001776
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001777 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001778 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1779 mWorkspace.removeAllViews();
1780 mWorkspace = null;
1781 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001782
Michael Jurka2ecf9952012-06-18 12:52:28 -07001783 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 }
1785
Adam Cohena9cf38f2011-05-02 15:36:58 -07001786 public DragController getDragController() {
1787 return mDragController;
1788 }
1789
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 @Override
1791 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001792 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 super.startActivityForResult(intent, requestCode);
1794 }
1795
Winson Chung70d72102011-08-12 11:24:35 -07001796 /**
1797 * Indicates that we want global search for this activity by setting the globalSearch
1798 * argument for {@link #startSearch} to true.
1799 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001801 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001803
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001804 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001805
Karl Rosaen138a0412009-04-23 19:00:21 -07001806 if (initialQuery == null) {
1807 // Use any text typed in the launcher as the initial query
1808 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001809 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001810 if (appSearchData == null) {
1811 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001812 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001813 }
Winson Chungadf0c182012-08-23 14:59:07 -07001814 Rect sourceBounds = new Rect();
1815 if (mSearchDropTargetBar != null) {
1816 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1817 }
Romain Guycbb89e42009-06-08 15:52:54 -07001818
Bjorn Bringertc459e522013-06-07 19:36:01 +01001819 startSearch(initialQuery, selectInitialQuery,
1820 appSearchData, sourceBounds);
1821 }
1822
1823 public void startSearch(String initialQuery,
1824 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001825 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001826 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001827 }
1828
1829 /**
1830 * Starts the global search activity. This code is a copied from SearchManager
1831 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001832 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001833 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001834 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001835 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1836 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1837 if (globalSearchActivity == null) {
1838 Log.w(TAG, "No global search activity found.");
1839 return;
1840 }
1841 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1842 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1843 intent.setComponent(globalSearchActivity);
1844 // Make sure that we have a Bundle to put source in
1845 if (appSearchData == null) {
1846 appSearchData = new Bundle();
1847 } else {
1848 appSearchData = new Bundle(appSearchData);
1849 }
1850 // Set source to package name of app that starts global search, if not set already.
1851 if (!appSearchData.containsKey("source")) {
1852 appSearchData.putString("source", getPackageName());
1853 }
1854 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1855 if (!TextUtils.isEmpty(initialQuery)) {
1856 intent.putExtra(SearchManager.QUERY, initialQuery);
1857 }
1858 if (selectInitialQuery) {
1859 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1860 }
1861 intent.setSourceBounds(sourceBounds);
1862 try {
1863 startActivity(intent);
1864 } catch (ActivityNotFoundException ex) {
1865 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1866 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001867 }
1868
Winson Chung70d72102011-08-12 11:24:35 -07001869 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001870 public boolean onPrepareOptionsMenu(Menu menu) {
1871 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001872 if (!mWorkspace.isInOverviewMode()) {
1873 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001874 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001875 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001878 @Override
1879 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001880 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001881 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001882 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001883 }
1884
Joe Onorato9c1289c2009-08-17 11:03:03 -04001885 public boolean isWorkspaceLocked() {
1886 return mWorkspaceLoading || mWaitingForResult;
1887 }
1888
Michael Jurka0280c3b2010-09-17 15:00:07 -07001889 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001890 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001891 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001892 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1893 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001894 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001895 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001896 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001897
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001898 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1899 AppWidgetProviderInfo appWidgetInfo) {
1900 if (appWidgetInfo.configure != null) {
1901 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001902
Bjorn Bringert7984c942009-12-09 15:38:25 +00001903 // Launch over to configure widget, if needed
1904 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001905 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001906 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001907 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001909 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001910 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001911 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001912 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001913 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 }
1915 }
Romain Guycbb89e42009-06-08 15:52:54 -07001916
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001917 protected void moveToCustomContentScreen(boolean animate) {
1918 mWorkspace.moveToCustomContentScreen(animate);
1919 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001920 /**
1921 * Process a shortcut drop.
1922 *
1923 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001924 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001925 * @param cell The cell it should be added to, optional
1926 * @param position The location on the screen where it was dropped, optional
1927 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001928 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001929 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001930 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001931 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001932 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001933 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001934
1935 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001936 mPendingAddInfo.cellX = cell[0];
1937 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001938 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001939
1940 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1941 createShortcutIntent.setComponent(componentName);
1942 processShortcut(createShortcutIntent);
1943 }
1944
Adam Cohenfbba09b2011-07-18 21:43:05 -07001945 /**
1946 * Process a widget drop.
1947 *
1948 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001949 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001950 * @param cell The cell it should be added to, optional
1951 * @param position The location on the screen where it was dropped, optional
1952 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001953 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001954 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001955 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001957 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001958 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001959 mPendingAddInfo.minSpanX = info.minSpanX;
1960 mPendingAddInfo.minSpanY = info.minSpanY;
1961
Adam Cohenfbba09b2011-07-18 21:43:05 -07001962 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.cellX = cell[0];
1964 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001965 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001966 if (span != null) {
1967 mPendingAddInfo.spanX = span[0];
1968 mPendingAddInfo.spanY = span[1];
1969 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001970
Adam Cohened66b2b2012-01-23 17:28:51 -08001971 AppWidgetHostView hostView = info.boundWidget;
1972 int appWidgetId;
1973 if (hostView != null) {
1974 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001975 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001976 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001977 // In this case, we either need to start an activity to get permission to bind
1978 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001979 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001980 Bundle options = info.bindOptions;
1981
1982 boolean success = false;
1983 if (options != null) {
1984 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1985 info.componentName, options);
1986 } else {
1987 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1988 info.componentName);
1989 }
1990 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001991 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001992 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001993 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001994 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1995 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1996 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001997 // TODO: we need to make sure that this accounts for the options bundle.
1998 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001999 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2000 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002001 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002002 }
2003
Joe Onoratodeb98af2010-02-19 14:59:39 -08002004 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002005 // Handle case where user selected "Applications"
2006 String applicationName = getResources().getString(R.string.group_applications);
2007 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002008
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002009 if (applicationName != null && applicationName.equals(shortcutName)) {
2010 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2011 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002012
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002013 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2014 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002015 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002016 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002017 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002018 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002019 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 }
2021
Winson Chung24ab2f12010-09-16 14:10:47 -07002022 void processWallpaper(Intent intent) {
2023 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2024 }
2025
Adam Cohendcd297f2013-06-18 13:13:40 -07002026 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002027 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002028 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 folderInfo.title = getText(R.string.folder_name);
2030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002032 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002033 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002034 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002035
2036 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002037 FolderIcon newFolder =
2038 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002039 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002041 // Force measure the new folder icon
2042 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2043 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002044 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 }
Romain Guycbb89e42009-06-08 15:52:54 -07002046
Joe Onorato9c1289c2009-08-17 11:03:03 -04002047 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002048 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002049 }
2050
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002051 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002052 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002054 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002055 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 }
2057
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002058 protected ComponentName getWallpaperPickerComponent() {
2059 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2060 }
2061
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002062 /**
2063 * Registers various content observers. The current implementation registers
2064 * only a favorites observer to keep track of the favorites applications.
2065 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002066 private void registerContentObservers() {
2067 ContentResolver resolver = getContentResolver();
2068 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2069 true, mWidgetObserver);
2070 }
2071
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002072 @Override
2073 public boolean dispatchKeyEvent(KeyEvent event) {
2074 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2075 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002077 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002078 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002079 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002080 dumpState();
2081 return true;
2082 }
2083 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002084 }
2085 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2086 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002087 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 return true;
2089 }
2090 }
2091
2092 return super.dispatchKeyEvent(event);
2093 }
2094
Joe Onorato88ec0992009-11-19 13:16:06 -08002095 @Override
2096 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002097 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002098 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002099 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002100 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002101 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002102 Folder openFolder = mWorkspace.getOpenFolder();
2103 if (openFolder.isEditingName()) {
2104 openFolder.dismissEditingName();
2105 } else {
2106 closeFolder();
2107 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002108 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002109 mWorkspace.exitWidgetResizeMode();
2110
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002111 // Back button is a no-op here, but give at least some feedback for the button press
2112 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002113 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002114 }
2115
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002117 * Re-listen when widgets are reset.
2118 */
2119 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002120 if (mAppWidgetHost != null) {
2121 mAppWidgetHost.startListening();
2122 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002123 }
2124
2125 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002126 * Launches the intent referred by the clicked shortcut.
2127 *
2128 * @param v The view representing the clicked shortcut.
2129 */
2130 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002131 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2132 // view has detached (it's possible for this to happen if the view is removed mid touch).
2133 if (v.getWindowToken() == null) {
2134 return;
2135 }
2136
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002137 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002138 return;
2139 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002140
Adam Cohen1697b792013-09-17 19:08:21 -07002141 if (v instanceof Workspace) {
2142 if (mWorkspace.isInOverviewMode()) {
2143 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002144 }
2145 return;
2146 }
2147
2148 if (v instanceof CellLayout) {
2149 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002150 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002151 }
2152 }
2153
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002154 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002155 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002157 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2158 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002159
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002160 // Check for special shortcuts
2161 if (intent.getComponent() != null) {
2162 final String shortcutClass = intent.getComponent().getClassName();
2163
2164 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002165 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002166 return;
2167 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2168 MemoryDumpActivity.startDump(this);
2169 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002170 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2171 toggleShowWeightWatcher();
2172 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002173 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002174 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002175
2176 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002177 int[] pos = new int[2];
2178 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002179 intent.setSourceBounds(new Rect(pos[0], pos[1],
2180 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002181
2182 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002183
Daniel Sandlerff02d492013-08-05 02:12:05 -04002184 mStats.recordLaunch(intent, shortcut);
2185
Michael Jurkaddd62e92011-02-16 17:49:14 -08002186 if (success && v instanceof BubbleTextView) {
2187 mWaitingForResume = (BubbleTextView) v;
2188 mWaitingForResume.setStayPressed(true);
2189 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002190 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002191 if (v instanceof FolderIcon) {
2192 FolderIcon fi = (FolderIcon) v;
2193 handleFolderClick(fi);
2194 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002195 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002196 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002197 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002198 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002199 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002200 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 }
2202 }
2203
Michael Jurka0e260592010-06-30 17:07:39 -07002204 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002205 return false;
2206 }
2207
Michael Jurkaaf442092010-06-10 17:01:57 -07002208 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002209 * Event handler for the search button
2210 *
2211 * @param v The view that was clicked.
2212 */
2213 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002214 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2215
Amith Yamasania135ba82011-08-09 17:42:01 -07002216 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002217 }
2218
2219 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002220 * Event handler for the voice button
2221 *
2222 * @param v The view that was clicked.
2223 */
2224 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002225 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002226
Bjorn Bringertc459e522013-06-07 19:36:01 +01002227 startVoice();
2228 }
2229
2230 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002231 try {
2232 final SearchManager searchManager =
2233 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2234 ComponentName activityName = searchManager.getGlobalSearchActivity();
2235 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002236 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002237 if (activityName != null) {
2238 intent.setPackage(activityName.getPackageName());
2239 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002240 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002241 } catch (ActivityNotFoundException e) {
2242 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002243 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002244 startActivitySafely(null, intent, "onClickVoiceButton");
2245 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002246 }
2247
2248 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002249 * Event handler for the "grid" button that appears on the home screen, which
2250 * enters all apps mode.
2251 *
2252 * @param v The view that was clicked.
2253 */
2254 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002255 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002256 }
2257
2258 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002259 // Provide the same haptic feedback that the system offers for virtual keys.
2260 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002261 }
2262
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002263 public void onClickAppMarketButton(View v) {
2264 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002265 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002266 } else {
2267 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002268 }
2269 }
2270
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002271 /**
2272 * Called when the user stops interacting with the launcher.
2273 * This implies that the user is now on the homescreen and is not doing housekeeping.
2274 */
2275 protected void onInteractionEnd() {}
2276
2277 /**
2278 * Called when the user starts interacting with the launcher.
2279 * The possible interactions are:
2280 * - open all apps
2281 * - reorder an app shortcut, or a widget
2282 * - open the overview mode.
2283 * This is a good time to stop doing things that only make sense
2284 * when the user is on the homescreen and not doing housekeeping.
2285 */
2286 protected void onInteractionBegin() {}
2287
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002288 void startApplicationDetailsActivity(ComponentName componentName) {
2289 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002290 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2291 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002292 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002293 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002294 }
2295
Michael Jurka1e2f4652013-07-08 18:03:46 -07002296 // returns true if the activity was started
2297 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002298 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002299 // System applications cannot be installed. For now, show a toast explaining that.
2300 // We may give them the option of disabling apps this way.
2301 int messageId = R.string.uninstall_system_app_text;
2302 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002303 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002304 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002305 String packageName = componentName.getPackageName();
2306 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002307 Intent intent = new Intent(
2308 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002309 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2310 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002311 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002312 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002313 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002314 }
2315
Michael Jurka86a720e2012-05-09 11:23:23 -07002316 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002318
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002320 // Only launch using the new animation if the shortcut has not opted out (this is a
2321 // private contract between launcher and may be ignored in the future).
2322 boolean useLaunchAnimation = (v != null) &&
2323 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2324 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002325 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2326 v.getMeasuredWidth(), v.getMeasuredHeight());
2327
2328 startActivity(intent, opts.toBundle());
2329 } else {
2330 startActivity(intent);
2331 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002332 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002333 } catch (SecurityException e) {
2334 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002335 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002337 "or use the exported attribute for this activity. "
2338 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002340 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002342
Michael Jurka86a720e2012-05-09 11:23:23 -07002343 boolean startActivitySafely(View v, Intent intent, Object tag) {
2344 boolean success = false;
2345 try {
2346 success = startActivity(v, intent, tag);
2347 } catch (ActivityNotFoundException e) {
2348 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2349 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2350 }
2351 return success;
2352 }
2353
Adam Cohena9cf38f2011-05-02 15:36:58 -07002354 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002355 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002356 Folder openFolder = mWorkspace.getFolderForTag(info);
2357
2358 // If the folder info reports that the associated folder is open, then verify that
2359 // it is actually opened. There have been a few instances where this gets out of sync.
2360 if (info.opened && openFolder == null) {
2361 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002362 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002363 info.opened = false;
2364 }
2365
Adam Cohenfb91f302012-06-11 15:45:18 -07002366 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002367 // Close any open folder
2368 closeFolder();
2369 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002370 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 } else {
2372 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 int folderScreen;
2374 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002375 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376 // .. and close it
2377 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002378 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 // Close any folder open on the current screen
2380 closeFolder();
2381 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002382 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 }
2384 }
2385 }
2386 }
2387
Adam Cohen268c4752012-06-06 17:47:33 -07002388 /**
2389 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2390 * in the DragLayer in the exact absolute location of the original FolderIcon.
2391 */
2392 private void copyFolderIconToImage(FolderIcon fi) {
2393 final int width = fi.getMeasuredWidth();
2394 final int height = fi.getMeasuredHeight();
2395
2396 // Lazy load ImageView, Bitmap and Canvas
2397 if (mFolderIconImageView == null) {
2398 mFolderIconImageView = new ImageView(this);
2399 }
2400 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2401 mFolderIconBitmap.getHeight() != height) {
2402 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2403 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2404 }
2405
2406 DragLayer.LayoutParams lp;
2407 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2408 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2409 } else {
2410 lp = new DragLayer.LayoutParams(width, height);
2411 }
2412
Adam Cohen307fe232012-08-16 17:55:58 -07002413 // The layout from which the folder is being opened may be scaled, adjust the starting
2414 // view size by this scale factor.
2415 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002416 lp.customPosition = true;
2417 lp.x = mRectForFolderAnimation.left;
2418 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002419 lp.width = (int) (scale * width);
2420 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002421
2422 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2423 fi.draw(mFolderIconCanvas);
2424 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002425 if (fi.getFolder() != null) {
2426 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2427 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002428 }
Adam Cohen268c4752012-06-06 17:47:33 -07002429 // Just in case this image view is still in the drag layer from a previous animation,
2430 // we remove it and re-add it.
2431 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2432 mDragLayer.removeView(mFolderIconImageView);
2433 }
2434 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002435 if (fi.getFolder() != null) {
2436 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002437 }
Adam Cohen268c4752012-06-06 17:47:33 -07002438 }
2439
Adam Cohen2801caf2011-05-13 20:57:39 -07002440 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002441 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002442 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2443 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2444 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2445
Adam Cohenc51934b2011-07-26 21:07:43 -07002446 FolderInfo info = (FolderInfo) fi.getTag();
2447 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2448 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002449 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2450 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002451 }
2452
Adam Cohen268c4752012-06-06 17:47:33 -07002453 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2454 copyFolderIconToImage(fi);
2455 fi.setVisibility(View.INVISIBLE);
2456
Michael Jurka2ecf9952012-06-18 12:52:28 -07002457 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002458 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002459 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2460 oa.start();
2461 }
2462
Adam Cohen268c4752012-06-06 17:47:33 -07002463 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002464 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002465 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2466 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2467 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2468
Adam Cohen268c4752012-06-06 17:47:33 -07002469 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002470
Adam Cohen268c4752012-06-06 17:47:33 -07002471 // We remove and re-draw the FolderIcon in-case it has changed
2472 mDragLayer.removeView(mFolderIconImageView);
2473 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002474 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002475 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002476 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002477 oa.addListener(new AnimatorListenerAdapter() {
2478 @Override
2479 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002480 if (cl != null) {
2481 cl.clearFolderLeaveBehind();
2482 // Remove the ImageView copy of the FolderIcon and make the original visible.
2483 mDragLayer.removeView(mFolderIconImageView);
2484 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002485 }
2486 }
2487 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002488 oa.start();
2489 }
2490
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002491 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002492 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002493 * is animated relative to the specified View. If the View is null, no animation
2494 * is played.
2495 *
2496 * @param folderInfo The FolderInfo describing the folder to open.
2497 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002498 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002499 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002500 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002501
Adam Cohena9cf38f2011-05-02 15:36:58 -07002502 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002503
Adam Cohen4554ee12011-08-03 16:13:21 -07002504 // Just verify that the folder hasn't already been added to the DragLayer.
2505 // There was a one-off crash where the folder had a parent already.
2506 if (folder.getParent() == null) {
2507 mDragLayer.addView(folder);
2508 mDragController.addDropTarget((DropTarget) folder);
2509 } else {
2510 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2511 folder.getParent() + ").");
2512 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002513 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002514 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002515
2516 // Notify the accessibility manager that this folder "window" has appeared and occluded
2517 // the workspace items
2518 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2519 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002520 }
2521
2522 public void closeFolder() {
2523 Folder folder = mWorkspace.getOpenFolder();
2524 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002525 if (folder.isEditingName()) {
2526 folder.dismissEditingName();
2527 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002528 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002529
2530 // Dismiss the folder cling
2531 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002532 }
2533 }
2534
2535 void closeFolder(Folder folder) {
2536 folder.getInfo().opened = false;
2537
2538 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2539 if (parent != null) {
2540 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2541 shrinkAndFadeInFolderIcon(fi);
2542 }
2543 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002544
2545 // Notify the accessibility manager that this folder "window" has disappeard and no
2546 // longer occludeds the workspace items
2547 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002548 }
2549
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002550 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002551 if (!isDraggingEnabled()) return false;
2552 if (isWorkspaceLocked()) return false;
2553 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002554
Adam Cohen1697b792013-09-17 19:08:21 -07002555 if (v instanceof Workspace) {
2556 if (!mWorkspace.isInOverviewMode()) {
2557 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2558 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2559 mWorkspace.enterOverviewMode();
2560 }
2561 return true;
2562 }
2563
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002565 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 }
2567
Michael Jurka0280c3b2010-09-17 15:00:07 -07002568 resetAddInfo();
2569 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002570 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002571 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 return true;
2573 }
2574
Winson Chung3d503fb2011-07-13 17:25:49 -07002575 // The hotseat touch handling does not go through Workspace, and we always allow long press
2576 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002577 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002578 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2579 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002580 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002581 // User long pressed on empty space
2582 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2583 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2584 // Disabling reordering until we sort out some issues.
2585 if (mWorkspace.isInOverviewMode()) {
2586 mWorkspace.startReordering(v);
2587 } else {
2588 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002589 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002590 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002591 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002592 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002593 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002594 }
2595 }
2596 }
2597 return true;
2598 }
2599
Winson Chung3d503fb2011-07-13 17:25:49 -07002600 boolean isHotseatLayout(View layout) {
2601 return mHotseat != null && layout != null &&
2602 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2603 }
2604 Hotseat getHotseat() {
2605 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002606 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002607 View getOverviewPanel() {
2608 return mOverviewPanel;
2609 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002610 SearchDropTargetBar getSearchBar() {
2611 return mSearchDropTargetBar;
2612 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002613
Winson Chung3d503fb2011-07-13 17:25:49 -07002614 /**
2615 * Returns the CellLayout of the specified container at the specified screen.
2616 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002617 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002618 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2619 if (mHotseat != null) {
2620 return mHotseat.getLayout();
2621 } else {
2622 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002623 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002624 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002625 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002626 }
2627 }
2628
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002629 Workspace getWorkspace() {
2630 return mWorkspace;
2631 }
2632
Daniel Sandler843e8602010-06-07 14:59:01 -04002633 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002634 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002635 }
2636
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002637 /**
2638 * Helper method for the cameraZoomIn/cameraZoomOut animations
2639 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002640 * @param scaleFactor The scale factor used for the zoom
2641 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002642 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002644 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002645 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002646
Winson Chung18f41f82012-05-09 13:28:10 -07002647 void disableWallpaperIfInAllApps() {
2648 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002649 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002650 if (mAppsCustomizeTabHost != null &&
2651 !mAppsCustomizeTabHost.isTransitioning()) {
2652 updateWallpaperVisibility(false);
2653 }
2654 }
2655 }
2656
Craig Mautner360310b2012-10-26 15:13:08 -07002657 private void setWorkspaceBackground(boolean workspace) {
2658 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002659 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002660 }
2661
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002662 void updateWallpaperVisibility(boolean visible) {
2663 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2664 int curflags = getWindow().getAttributes().flags
2665 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2666 if (wpflags != curflags) {
2667 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2668 }
Craig Mautner360310b2012-10-26 15:13:08 -07002669 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002670 }
2671
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002672 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2673 if (v instanceof LauncherTransitionable) {
2674 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2675 }
2676 }
2677
Michael Jurkabed61d22012-02-14 22:51:29 -08002678 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2679 if (v instanceof LauncherTransitionable) {
2680 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2681 }
Winson Chung70442722012-02-10 15:43:22 -08002682
2683 // Update the workspace transition step as well
2684 dispatchOnLauncherTransitionStep(v, 0f);
2685 }
2686
2687 private void dispatchOnLauncherTransitionStep(View v, float t) {
2688 if (v instanceof LauncherTransitionable) {
2689 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2690 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002691 }
2692
2693 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2694 if (v instanceof LauncherTransitionable) {
2695 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2696 }
Winson Chung70442722012-02-10 15:43:22 -08002697
2698 // Update the workspace transition step as well
2699 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002700 }
2701
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002702 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002703 * Things to test when changing the following seven functions.
2704 * - Home from workspace
2705 * - from center screen
2706 * - from other screens
2707 * - Home from all apps
2708 * - from center screen
2709 * - from other screens
2710 * - Back from all apps
2711 * - from center screen
2712 * - from other screens
2713 * - Launch app from workspace and quit
2714 * - with back
2715 * - with home
2716 * - Launch app from all apps and quit
2717 * - with back
2718 * - with home
2719 * - Go to a screen that's not the default, then all
2720 * apps, and launch and app, and go back
2721 * - with back
2722 * -with home
2723 * - On workspace, long press power and go back
2724 * - with back
2725 * - with home
2726 * - On all apps, long press power and go back
2727 * - with back
2728 * - with home
2729 * - On workspace, power off
2730 * - On all apps, power off
2731 * - Launch an app and turn off the screen while in that app
2732 * - Go back with home key
2733 * - Go back with back key TODO: make this not go to workspace
2734 * - From all apps
2735 * - From workspace
2736 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2737 * - From all apps
2738 * - From the center workspace
2739 * - From another workspace
2740 */
2741
2742 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002743 * Zoom the camera out from the workspace to reveal 'toView'.
2744 * Assumes that the view to show is anchored at either the very top or very bottom
2745 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002746 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002747 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002748 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2749 showAppsCustomizeHelper(animated, springLoaded, contentType);
2750 }
2751 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2752 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002753 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002754 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002755 mStateAnimation.cancel();
2756 mStateAnimation = null;
2757 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002758 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002759
Winson Chungf0ea4d32011-06-06 14:27:16 -07002760 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2761 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2762 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002763 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002764 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002765 final int startDelay =
2766 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002767
Michael Jurkab3e22d92011-10-31 15:58:33 -07002768 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002769
Michael Jurkad74c9842011-07-10 12:44:21 -07002770 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002771 Animator workspaceAnim =
2772 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002773 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2774 // Set the content type for the all apps space
2775 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2776 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002777
2778 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002779 toView.setScaleX(scale);
2780 toView.setScaleY(scale);
2781 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2782 scaleAnim.
2783 scaleX(1f).scaleY(1f).
2784 setDuration(duration).
2785 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002786
Winson Chungf0ea4d32011-06-06 14:27:16 -07002787 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002788 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002789 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002790 .ofFloat(toView, "alpha", 0f, 1f)
2791 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002792 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002793 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2794 @Override
2795 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002796 if (animation == null) {
2797 throw new RuntimeException("animation is null");
2798 }
Winson Chung70442722012-02-10 15:43:22 -08002799 float t = (Float) animation.getAnimatedValue();
2800 dispatchOnLauncherTransitionStep(fromView, t);
2801 dispatchOnLauncherTransitionStep(toView, t);
2802 }
2803 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002804
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002805 // toView should appear right at the end of the workspace shrink
2806 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002807 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002808 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002809 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002810
2811 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002812 boolean animationCancelled = false;
2813
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002814 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002815 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002816 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002817 // Prepare the position
2818 toView.setTranslationX(0.0f);
2819 toView.setTranslationY(0.0f);
2820 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002821 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002822 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002823 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002824 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002825 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2826 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002827
Adam Cohenf4ddea32011-09-12 13:46:42 -07002828 if (!animationCancelled) {
2829 updateWallpaperVisibility(false);
2830 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002831
2832 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002833 if (mSearchDropTargetBar != null) {
2834 mSearchDropTargetBar.hideSearchBar(false);
2835 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002836 }
2837
Adam Cohencff6af82011-09-13 14:51:53 -07002838 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002839 public void onAnimationCancel(Animator animation) {
2840 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002841 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002842 });
2843
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002844 if (workspaceAnim != null) {
2845 mStateAnimation.play(workspaceAnim);
2846 }
Michael Jurka1899a362011-11-03 13:50:45 -07002847
2848 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002850 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2851 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002852
2853 // If any of the objects being animated haven't been measured/laid out
2854 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002855 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002856 (mWorkspace.getMeasuredWidth() == 0) ||
2857 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002858 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002859 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002860
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002861 final AnimatorSet stateAnimation = mStateAnimation;
2862 final Runnable startAnimRunnable = new Runnable() {
2863 public void run() {
2864 // Check that mStateAnimation hasn't changed while
2865 // we waited for a layout/draw pass
2866 if (mStateAnimation != stateAnimation)
2867 return;
2868 setPivotsForZoom(toView, scale);
2869 dispatchOnLauncherTransitionStart(fromView, animated, false);
2870 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002871 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002872 }
2873 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002874 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002875 final ViewTreeObserver observer = toView.getViewTreeObserver();
2876 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2877 public void onGlobalLayout() {
2878 startAnimRunnable.run();
2879 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2880 }
2881 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002882 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002883 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002884 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002885 } else {
2886 toView.setTranslationX(0.0f);
2887 toView.setTranslationY(0.0f);
2888 toView.setScaleX(1.0f);
2889 toView.setScaleY(1.0f);
2890 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002891 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002892
Daniel Sandlere4f98912013-06-25 15:13:26 -04002893 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002894 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002895 if (mSearchDropTargetBar != null) {
2896 mSearchDropTargetBar.hideSearchBar(false);
2897 }
Michael Jurkaabded662011-03-04 12:06:57 -08002898 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002899 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002900 dispatchOnLauncherTransitionStart(fromView, animated, false);
2901 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002902 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002903 dispatchOnLauncherTransitionStart(toView, animated, false);
2904 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002905 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002906 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002907 }
2908
2909 /**
2910 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002911 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002912 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002913 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002914 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2915 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002916
Michael Jurkab3e22d92011-10-31 15:58:33 -07002917 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002918 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002919 mStateAnimation.cancel();
2920 mStateAnimation = null;
2921 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002922 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002923
Winson Chungf0ea4d32011-06-06 14:27:16 -07002924 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002925 final int fadeOutDuration =
2926 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002927 final float scaleFactor = (float)
2928 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2929 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002930 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002931 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002932 if (toState == State.WORKSPACE) {
2933 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2934 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002935 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002936 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2937 workspaceAnim = mWorkspace.getChangeStateAnimation(
2938 Workspace.State.SPRING_LOADED, animated);
2939 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002940
Michael Jurkab3e22d92011-10-31 15:58:33 -07002941 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002942 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002943 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002944 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002945 final LauncherViewPropertyAnimator scaleAnim =
2946 new LauncherViewPropertyAnimator(fromView);
2947 scaleAnim.
2948 scaleX(scaleFactor).scaleY(scaleFactor).
2949 setDuration(duration).
2950 setInterpolator(new Workspace.ZoomInInterpolator());
2951
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002952 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002953 .ofFloat(fromView, "alpha", 1f, 0f)
2954 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002955 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002956 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2957 @Override
2958 public void onAnimationUpdate(ValueAnimator animation) {
2959 float t = 1f - (Float) animation.getAnimatedValue();
2960 dispatchOnLauncherTransitionStep(fromView, t);
2961 dispatchOnLauncherTransitionStep(toView, t);
2962 }
2963 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002964
Michael Jurka2ecf9952012-06-18 12:52:28 -07002965 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002966
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002967 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2968 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002969 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002970
2971 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002972 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002973 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002974 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002975 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002976 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2977 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002978 if (onCompleteRunnable != null) {
2979 onCompleteRunnable.run();
2980 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002981 mAppsCustomizeContent.updateCurrentPageScroll();
2982 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002983 }
2984 });
2985
Winson Chungf0ea4d32011-06-06 14:27:16 -07002986 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002987 if (workspaceAnim != null) {
2988 mStateAnimation.play(workspaceAnim);
2989 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002990 dispatchOnLauncherTransitionStart(fromView, animated, true);
2991 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002992 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002993 } else {
2994 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002995 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002996 dispatchOnLauncherTransitionStart(fromView, animated, true);
2997 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002998 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002999 dispatchOnLauncherTransitionStart(toView, animated, true);
3000 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003001 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003002 }
3003
Michael Jurkae326f182011-11-21 14:05:46 -08003004 @Override
3005 public void onTrimMemory(int level) {
3006 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003007 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003008 mAppsCustomizeTabHost.onTrimMemory();
3009 }
3010 }
3011
Winson Chung18f41f82012-05-09 13:28:10 -07003012 @Override
3013 public void onWindowFocusChanged(boolean hasFocus) {
3014 if (!hasFocus) {
3015 // When another window occludes launcher (like the notification shade, or recents),
3016 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3017 updateWallpaperVisibility(true);
3018 } else {
3019 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003020 mWorkspace.postDelayed(new Runnable() {
3021 @Override
3022 public void run() {
3023 disableWallpaperIfInAllApps();
3024 }
3025 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003026 }
3027 }
3028
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003029 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003030 showWorkspace(animated, null);
3031 }
3032
3033 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003034 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003035 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003036 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003037 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003038
Winson Chungc7d2b602012-05-16 17:02:20 -07003039 // Show the search bar (only animate if we were showing the drop target bar in spring
3040 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003041 if (mSearchDropTargetBar != null) {
3042 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3043 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003044
Michael Jurkab3e22d92011-10-31 15:58:33 -07003045 // Set focus to the AppsCustomize button
3046 if (mAllAppsButton != null) {
3047 mAllAppsButton.requestFocus();
3048 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003049 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003050
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003051 // Change the state *after* we've called all the transition code
3052 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003053
Winson Chung5fb63472011-02-02 17:03:37 -08003054 // Resume the auto-advance of widgets
3055 mUserPresent = true;
3056 updateRunning();
3057
alanv1d4fde62012-10-17 13:15:47 -07003058 // Send an accessibility event to announce the context change
3059 getWindow().getDecorView()
3060 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003061
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003062 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003063 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003064 }
3065
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003066 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003067 }
3068
Winson Chungc58497e2013-09-03 17:48:37 -07003069 void showAllApps(boolean animated,
3070 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003071 if (mState != State.WORKSPACE) return;
3072
Winson Chungc58497e2013-09-03 17:48:37 -07003073 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003074 mAppsCustomizeTabHost.requestFocus();
3075
Michael Jurkab3e22d92011-10-31 15:58:33 -07003076 // Change the state *after* we've called all the transition code
3077 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003078 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003079
3080 // Pause the auto-advance of widgets until we are out of AllApps
3081 mUserPresent = false;
3082 updateRunning();
3083 closeFolder();
3084
3085 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003086 getWindow().getDecorView()
3087 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003088 }
3089
Adam Cohen7777d962011-08-18 18:58:38 -07003090 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003091 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003092 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003093 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003094 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003095 }
Adam Cohen7777d962011-08-18 18:58:38 -07003096
Adam Cohened66b2b2012-01-23 17:28:51 -08003097 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3098 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003099 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3100
Winson Chunge7a03942011-08-05 15:05:12 -07003101 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003102 @Override
3103 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003104 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003105 // Before we show workspace, hide all apps again because
3106 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3107 // clean up our state transition functions
3108 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003109 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003110 } else {
3111 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003112 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003113 }
3114 }, (extendedDelay ?
3115 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3116 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3117 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003118
Michael Jurkad3ef3062010-11-23 16:23:58 -08003119 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003120 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003121 final boolean animated = true;
3122 final boolean springLoaded = true;
3123 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003124 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003125 }
3126 // Otherwise, we are not in spring loaded mode, so don't do anything.
3127 }
3128
Michael Jurkab3e22d92011-10-31 15:58:33 -07003129 void lockAllApps() {
3130 // TODO
3131 }
3132
3133 void unlockAllApps() {
3134 // TODO
3135 }
3136
Winson Chungf0ea4d32011-06-06 14:27:16 -07003137 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003138 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003139 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003140 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003141 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003142 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003143 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003144 int duration = 0;
3145 if (mSearchDropTargetBar != null) {
3146 duration = mSearchDropTargetBar.getTransitionInDuration();
3147 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003148 mHotseat.animate().alpha(1f).setDuration(duration);
3149 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003150 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003151 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003152 }
3153 }
3154 }
3155
3156 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003157 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003158 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003159 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003160 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003161 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003162 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003163 int duration = 0;
3164 if (mSearchDropTargetBar != null) {
3165 duration = mSearchDropTargetBar.getTransitionOutDuration();
3166 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003167 mHotseat.animate().alpha(0f).setDuration(duration);
3168 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003169 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003170 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003171 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003172 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003173 }
3174
Patrick Dubroy5f445422011-02-18 14:35:21 -08003175 /**
3176 * Add an item from all apps or customize onto the given workspace screen.
3177 * If layout is null, add to the current screen.
3178 */
3179 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003180 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003181 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003182 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003183 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003184
Winson Chungdff8ebb2011-09-08 17:25:31 -07003185 /** Maps the current orientation to an index for referencing orientation correct global icons */
3186 private int getCurrentOrientationIndexForGlobalIcons() {
3187 // default - 0, landscape - 1
3188 switch (getResources().getConfiguration().orientation) {
3189 case Configuration.ORIENTATION_LANDSCAPE:
3190 return 1;
3191 default:
3192 return 0;
3193 }
3194 }
3195
Michael Jurkaae65ee32012-04-30 11:45:54 -07003196 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003197 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003198 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003199 // Look for the toolbar icon specified in the activity meta-data
3200 Bundle metaData = packageManager.getActivityInfo(
3201 activityName, PackageManager.GET_META_DATA).metaData;
3202 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003203 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003204 if (iconResId != 0) {
3205 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003206 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003207 }
3208 }
3209 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003210 // This can happen if the activity defines an invalid drawable
3211 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3212 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003213 } catch (Resources.NotFoundException nfe) {
3214 // This can happen if the activity defines an invalid drawable
3215 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3216 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003217 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003218 return null;
3219 }
3220
3221 // if successful in getting icon, return it; otherwise, set button to use default drawable
3222 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003223 int buttonId, ComponentName activityName, int fallbackDrawableId,
3224 String toolbarResourceName) {
3225 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003226 Resources r = getResources();
3227 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3228 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003229
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003230 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003231 // If we were unable to find the icon via the meta-data, use a generic one
3232 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003233 toolbarIcon = r.getDrawable(fallbackDrawableId);
3234 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003235 if (button != null) {
3236 button.setCompoundDrawables(toolbarIcon, null, null, null);
3237 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003238 return null;
3239 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003240 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003241 if (button != null) {
3242 button.setCompoundDrawables(toolbarIcon, null, null, null);
3243 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003244 return toolbarIcon.getConstantState();
3245 }
3246 }
3247
3248 // if successful in getting icon, return it; otherwise, set button to use default drawable
3249 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003250 int buttonId, ComponentName activityName, int fallbackDrawableId,
3251 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003252 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003253 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003254
Michael Jurka19e0fc52011-07-22 18:00:21 -07003255 if (button != null) {
3256 // If we were unable to find the icon via the meta-data, use a
3257 // generic one
3258 if (toolbarIcon == null) {
3259 button.setImageResource(fallbackDrawableId);
3260 } else {
3261 button.setImageDrawable(toolbarIcon);
3262 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003263 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003264
3265 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3266
Michael Jurka0423dcf2010-10-05 14:56:18 -07003267 }
3268
Winson Chung1b884092012-06-08 17:13:02 -07003269 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003270 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003271 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003272 }
3273
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003274 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003275 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003276 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003277 }
3278
Winson Chungbb185bd2011-11-21 12:31:42 -08003279 private void invalidatePressedFocusedStates(View container, View button) {
3280 if (container instanceof HolographicLinearLayout) {
3281 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3282 layout.invalidatePressedFocusedStates();
3283 } else if (button instanceof HolographicImageView) {
3284 HolographicImageView view = (HolographicImageView) button;
3285 view.invalidatePressedFocusedStates();
3286 }
3287 }
3288
Cristina Stancu476493b2013-08-07 17:20:14 +01003289 public View getQsbBar() {
3290 if (mQsbBar == null) {
3291 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3292 }
3293 return mQsbBar;
3294 }
3295
3296 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003297 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003298 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003299 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003300 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003301
Winson Chung1cad91e2011-05-25 17:41:01 -07003302 final SearchManager searchManager =
3303 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3304 ComponentName activityName = searchManager.getGlobalSearchActivity();
3305 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003306 int coi = getCurrentOrientationIndexForGlobalIcons();
3307 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003308 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3309 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3310 if (sGlobalSearchIcon[coi] == null) {
3311 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3312 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3313 TOOLBAR_ICON_METADATA_NAME);
3314 }
3315
Winson Chungc51db6a2011-10-05 11:44:49 -07003316 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3317 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003318 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003319 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003320 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003321 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003322 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3323 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003324 if (searchButton != null) searchButton.setVisibility(View.GONE);
3325 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003326 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003327 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003328 }
3329 }
3330
Cristina Stancu476493b2013-08-07 17:20:14 +01003331 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003332 final View searchButtonContainer = findViewById(R.id.search_button_container);
3333 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003334 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003335 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003336 }
3337
Cristina Stancu476493b2013-08-07 17:20:14 +01003338 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003339 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003340 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003341
Winson Chungc51db6a2011-10-05 11:44:49 -07003342 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003343 final SearchManager searchManager =
3344 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3345 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3346
3347 ComponentName activityName = null;
3348 if (globalSearchActivity != null) {
3349 // Check if the global search activity handles voice search
3350 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3351 intent.setPackage(globalSearchActivity.getPackageName());
3352 activityName = intent.resolveActivity(getPackageManager());
3353 }
3354
3355 if (activityName == null) {
3356 // Fallback: check if an activity other than the global search activity
3357 // resolves this
3358 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3359 activityName = intent.resolveActivity(getPackageManager());
3360 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003361 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003362 int coi = getCurrentOrientationIndexForGlobalIcons();
3363 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003364 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3365 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3366 if (sVoiceSearchIcon[coi] == null) {
3367 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3368 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3369 TOOLBAR_ICON_METADATA_NAME);
3370 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003371 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003372 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003373 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003374 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003375 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003376 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003377 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003378 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003379 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003380 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003381 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003382 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003383
Cristina Stancu476493b2013-08-07 17:20:14 +01003384 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003385 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3386 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003387 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003388 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003389 }
3390
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003391 public void setVoiceButtonProxyVisible(boolean visible) {
3392 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3393 if (voiceButtonProxy != null) {
3394 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3395 }
3396 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003397 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003398 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003399 */
3400 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003401 final View marketButton = findViewById(R.id.market_button);
3402 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3403 // Find the app market activity by resolving an intent.
3404 // (If multiple app markets are installed, it will return the ResolverActivity.)
3405 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003406 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003407 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003408 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003409 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003410 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3411 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003412 marketButton.setVisibility(View.VISIBLE);
3413 } else {
3414 // We should hide and disable the view so that we don't try and restore the visibility
3415 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3416 marketButton.setVisibility(View.GONE);
3417 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003418 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003419 }
3420
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003421 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003422 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3423 Resources r = getResources();
3424 Drawable marketIconDrawable = d.newDrawable(r);
3425 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3426 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3427 marketIconDrawable.setBounds(0, 0, w, h);
3428
3429 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003430 }
3431
Michael Jurkad7c28052012-04-27 15:43:36 -07003432 @Override
3433 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003434 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003435 final List<CharSequence> text = event.getText();
3436 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003437 // Populate event with a fake title based on the current state.
3438 if (mState == State.APPS_CUSTOMIZE) {
3439 text.add(getString(R.string.all_apps_button_label));
3440 } else {
3441 text.add(getString(R.string.all_apps_home_button_label));
3442 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003443 return result;
3444 }
3445
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003446 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003447 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003448 */
3449 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3450 @Override
3451 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003452 closeSystemDialogs();
3453 }
3454 }
3455
3456 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003457 * Receives notifications whenever the appwidgets are reset.
3458 */
3459 private class AppWidgetResetObserver extends ContentObserver {
3460 public AppWidgetResetObserver() {
3461 super(new Handler());
3462 }
3463
3464 @Override
3465 public void onChange(boolean selfChange) {
3466 onAppWidgetReset();
3467 }
3468 }
3469
3470 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003471 * If the activity is currently paused, signal that we need to run the passed Runnable
3472 * in onResume.
3473 *
3474 * This needs to be called from incoming places where resources might have been loaded
3475 * while we are paused. That is becaues the Configuration might be wrong
3476 * when we're not running, and if it comes back to what it was when we
3477 * were paused, we are not restarted.
3478 *
3479 * Implementation of the method from LauncherModel.Callbacks.
3480 *
3481 * @return true if we are currently paused. The caller might be able to
3482 * skip some work in that case since we will come back again.
3483 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003484 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003485 if (mPaused) {
3486 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003487 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003488 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003489 }
3490 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003491 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003492 return true;
3493 } else {
3494 return false;
3495 }
3496 }
3497
Michael Jurkac402cd92013-05-20 15:49:32 +02003498 private boolean waitUntilResume(Runnable run) {
3499 return waitUntilResume(run, false);
3500 }
3501
Michael Jurka1e2f4652013-07-08 18:03:46 -07003502 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003503 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003504 }
3505
Michael Jurka7607c2f2013-04-03 14:33:19 -07003506 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003507 * If the activity is currently paused, signal that we need to re-run the loader
3508 * in onResume.
3509 *
3510 * This needs to be called from incoming places where resources might have been loaded
3511 * while we are paused. That is becaues the Configuration might be wrong
3512 * when we're not running, and if it comes back to what it was when we
3513 * were paused, we are not restarted.
3514 *
3515 * Implementation of the method from LauncherModel.Callbacks.
3516 *
3517 * @return true if we are currently paused. The caller might be able to
3518 * skip some work in that case since we will come back again.
3519 */
3520 public boolean setLoadOnResume() {
3521 if (mPaused) {
3522 Log.i(TAG, "setLoadOnResume");
3523 mOnResumeNeedsLoad = true;
3524 return true;
3525 } else {
3526 return false;
3527 }
3528 }
3529
3530 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003531 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003532 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003533 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003534 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003535 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003536 } else {
3537 return SCREEN_COUNT / 2;
3538 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003539 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003540
Joe Onorato9c1289c2009-08-17 11:03:03 -04003541 /**
3542 * Refreshes the shortcuts shown on the workspace.
3543 *
3544 * Implementation of the method from LauncherModel.Callbacks.
3545 */
3546 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003547 // If we're starting binding all over again, clear any bind calls we'd postponed in
3548 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3549 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003550 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003551
Winson Chungd64d1762013-08-20 14:37:16 -07003552 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003553 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003554 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003555
Michael Jurka05bf6442011-11-30 20:28:53 -08003556 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003557 if (mHotseat != null) {
3558 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003559 }
3560 }
3561
Adam Cohendcd297f2013-06-18 13:13:40 -07003562 @Override
3563 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003564 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003565
Adam Cohen5084cba2013-09-03 12:01:16 -07003566 // If there are no screens, we need to have an empty screen
3567 if (orderedScreenIds.size() == 0) {
3568 mWorkspace.addExtraEmptyScreen();
3569 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003570
3571 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003572 // setCurrentPage() so ensure that all pages are added before calling this).
3573 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003574 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3575 mWorkspace.createCustomContentPage();
3576 }
Winson Chung64359a52013-07-08 17:17:08 -07003577 }
3578
3579 @Override
3580 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003581 int count = orderedScreenIds.size();
3582 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003583 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003584 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003585 }
3586
Adam Cohen39a06042013-07-19 14:30:12 -07003587 private boolean shouldShowWeightWatcher() {
3588 String spKey = LauncherAppState.getSharedPreferencesKey();
3589 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003590 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003591
3592 return show;
3593 }
3594
Adam Cohen4caf2982013-08-20 18:54:31 -07003595 private boolean emailSent() {
3596 String spKey = LauncherAppState.getSharedPreferencesKey();
3597 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3598 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3599 return show;
3600 }
3601
3602 private void setEmailSent(boolean sent) {
3603 String spKey = LauncherAppState.getSharedPreferencesKey();
3604 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3605
3606 SharedPreferences.Editor editor = sp.edit();
3607 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3608 editor.commit();
3609 }
3610
Adam Cohen39a06042013-07-19 14:30:12 -07003611 private void toggleShowWeightWatcher() {
3612 String spKey = LauncherAppState.getSharedPreferencesKey();
3613 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3614 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3615
3616 show = !show;
3617
3618 SharedPreferences.Editor editor = sp.edit();
3619 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3620 editor.commit();
3621
3622 if (mWeightWatcher != null) {
3623 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3624 }
3625 }
3626
Winson Chungd64d1762013-08-20 14:37:16 -07003627 public void bindAppsAdded(final ArrayList<Long> newScreens,
3628 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003629 final ArrayList<ItemInfo> addAnimated,
3630 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003631 Runnable r = new Runnable() {
3632 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003633 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003634 }
3635 };
3636 if (waitUntilResume(r)) {
3637 return;
3638 }
3639
Winson Chungd64d1762013-08-20 14:37:16 -07003640 // Add the new screens
3641 bindAddScreens(newScreens);
3642
3643 // We add the items without animation on non-visible pages, and with
3644 // animations on the new page (which we will try and snap to).
3645 if (!addNotAnimated.isEmpty()) {
3646 bindItems(addNotAnimated, 0,
3647 addNotAnimated.size(), false);
3648 }
3649 if (!addAnimated.isEmpty()) {
3650 bindItems(addAnimated, 0,
3651 addAnimated.size(), true);
3652 }
Winson Chungc58497e2013-09-03 17:48:37 -07003653
3654 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3655 addedApps != null && mAppsCustomizeContent != null) {
3656 mAppsCustomizeContent.addApps(addedApps);
3657 }
Winson Chungd64d1762013-08-20 14:37:16 -07003658 }
3659
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003660 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003661 * Bind the items start-end from the list.
3662 *
3663 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003664 */
Winson Chung64359a52013-07-08 17:17:08 -07003665 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3666 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003667 Runnable r = new Runnable() {
3668 public void run() {
3669 bindItems(shortcuts, start, end, forceAnimateIcons);
3670 }
3671 };
3672 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003673 return;
3674 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003675
Winson Chungf0c6ae02012-03-21 16:10:31 -07003676 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003677 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3678 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003679 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003680 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003681 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003682 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003683 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003684
3685 // Short circuit if we are loading dock items for a configuration which has no dock
3686 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3687 mHotseat == null) {
3688 continue;
3689 }
3690
Joe Onorato9c1289c2009-08-17 11:03:03 -04003691 switch (item.itemType) {
3692 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3693 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003694 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003695 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003696
Winson Chung64359a52013-07-08 17:17:08 -07003697 /*
3698 * TODO: FIX collision case
3699 */
Winson Chungce376632013-07-11 16:12:41 -07003700 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3701 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3702 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3703 throw new RuntimeException("OCCUPIED");
3704 }
Winson Chung64359a52013-07-08 17:17:08 -07003705 }
3706
Adam Cohendcd297f2013-06-18 13:13:40 -07003707 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3708 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003709 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003710 // Animate all the applications up now
3711 shortcut.setAlpha(0f);
3712 shortcut.setScaleX(0f);
3713 shortcut.setScaleY(0f);
3714 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003715 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003716 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003717 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003718 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003719 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003720 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003721 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003722 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3723 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003724 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003725 default:
3726 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003727 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003728 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003729
Winson Chung997a9232013-07-24 15:33:46 -07003730 if (animateIcons) {
3731 // Animate to the correct page
3732 if (newShortcutsScreenId > -1) {
3733 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3734 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3735 if (newShortcutsScreenId != currentScreenId) {
3736 mWorkspace.snapToPage(newScreenIndex);
3737 }
3738 }
3739
Winson Chung64359a52013-07-08 17:17:08 -07003740 // We post the animation slightly delayed to prevent slowdowns when we are loading
3741 // right after we return to launcher.
3742 mWorkspace.postDelayed(new Runnable() {
3743 public void run() {
3744 anim.playTogether(bounceAnims);
3745 anim.start();
3746 }
3747 }, NEW_APPS_ANIMATION_DELAY);
3748 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003749 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003750 }
3751
Joe Onorato9c1289c2009-08-17 11:03:03 -04003752 /**
3753 * Implementation of the method from LauncherModel.Callbacks.
3754 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003755 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003756 Runnable r = new Runnable() {
3757 public void run() {
3758 bindFolders(folders);
3759 }
3760 };
3761 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003762 return;
3763 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003764 sFolders.clear();
3765 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003766 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767
3768 /**
3769 * Add the views for a widget to the workspace.
3770 *
3771 * Implementation of the method from LauncherModel.Callbacks.
3772 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003773 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003774 Runnable r = new Runnable() {
3775 public void run() {
3776 bindAppWidget(item);
3777 }
3778 };
3779 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003780 return;
3781 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003782
Daniel Sandler843e8602010-06-07 14:59:01 -04003783 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3784 if (DEBUG_WIDGETS) {
3785 Log.d(TAG, "bindAppWidget: " + item);
3786 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787 final Workspace workspace = mWorkspace;
3788
3789 final int appWidgetId = item.appWidgetId;
3790 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003791 if (DEBUG_WIDGETS) {
3792 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3793 }
3794
Joe Onorato9c1289c2009-08-17 11:03:03 -04003795 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3796
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003798 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003799
Adam Cohendcd297f2013-06-18 13:13:40 -07003800 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003801 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003802 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3803
Joe Onorato9c1289c2009-08-17 11:03:03 -04003804 workspace.requestLayout();
3805
Daniel Sandler843e8602010-06-07 14:59:01 -04003806 if (DEBUG_WIDGETS) {
3807 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3808 + (SystemClock.uptimeMillis()-start) + "ms");
3809 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003810 }
3811
Adam Cohen1462de32012-07-24 22:34:36 -07003812 public void onPageBoundSynchronously(int page) {
3813 mSynchronouslyBoundPages.add(page);
3814 }
3815
Joe Onorato9c1289c2009-08-17 11:03:03 -04003816 /**
3817 * Callback saying that there aren't any more items to bind.
3818 *
3819 * Implementation of the method from LauncherModel.Callbacks.
3820 */
Adam Cohene25af792013-06-06 23:08:25 -07003821 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003822 Runnable r = new Runnable() {
3823 public void run() {
3824 finishBindingItems(upgradePath);
3825 }
3826 };
3827 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003828 return;
3829 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830 if (mSavedState != null) {
3831 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003832 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003834 mSavedState = null;
3835 }
3836
Adam Cohen1462de32012-07-24 22:34:36 -07003837 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003838
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003839 // If we received the result of any pending adds while the loader was running (e.g. the
3840 // widget configuration forced an orientation change), process them now.
3841 for (int i = 0; i < sPendingAddList.size(); i++) {
3842 completeAdd(sPendingAddList.get(i));
3843 }
3844 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003845
Winson Chungc51db6a2011-10-05 11:44:49 -07003846 // Update the market app icon as necessary (the other icons will be managed in response to
3847 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003848 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003849
Winson Chungf0c6ae02012-03-21 16:10:31 -07003850 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003851 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003852 mWorkspace.getUniqueComponents(true, null);
3853 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003854 }
Adam Cohen99894d92013-06-14 11:22:59 -07003855
Adam Cohen66a01fd2013-06-11 12:48:00 -07003856 mWorkspace.post(new Runnable() {
3857 @Override
3858 public void run() {
3859 onFinishBindingItems();
3860 }
3861 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003862 }
3863
Winson Chunga2413752012-04-03 14:22:34 -07003864 private boolean canRunNewAppsAnimation() {
3865 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3866 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3867 }
3868
Winson Chungc9168342013-06-26 14:54:55 -07003869 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3870 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3871 PropertyValuesHolder.ofFloat("alpha", 1f),
3872 PropertyValuesHolder.ofFloat("scaleX", 1f),
3873 PropertyValuesHolder.ofFloat("scaleY", 1f));
3874 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3875 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3876 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3877 return bounceAnim;
3878 }
3879
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003880 @Override
3881 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003882 boolean searchVisible = updateGlobalSearchIcon();
3883 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003884 if (mSearchDropTargetBar != null) {
3885 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3886 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003887 }
3888
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003889 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003890 * Add the icons for all apps.
3891 *
3892 * Implementation of the method from LauncherModel.Callbacks.
3893 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003894 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003895 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3896 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3897 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3898 getHotseat().addAllAppsFolder(mIconCache, apps,
3899 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3900 }
3901 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003902 }
Winson Chungc58497e2013-09-03 17:48:37 -07003903 } else {
3904 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3905 mAppsCustomizeContent != null) {
3906 mAppsCustomizeContent.setApps(apps);
3907 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003908 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003909 }
3910
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003911 @Override
3912 public boolean shouldShowApp(ResolveInfo app) {
3913 return true;
3914 }
3915
Joe Onorato9c1289c2009-08-17 11:03:03 -04003916 /**
3917 * A package was updated.
3918 *
3919 * Implementation of the method from LauncherModel.Callbacks.
3920 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003921 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003922 Runnable r = new Runnable() {
3923 public void run() {
3924 bindAppsUpdated(apps);
3925 }
3926 };
3927 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003928 return;
3929 }
3930
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003931 if (mWorkspace != null) {
3932 mWorkspace.updateShortcuts(apps);
3933 }
Winson Chungc58497e2013-09-03 17:48:37 -07003934
3935 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3936 mAppsCustomizeContent != null) {
3937 mAppsCustomizeContent.updateApps(apps);
3938 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003939 }
3940
3941 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003942 * A package was uninstalled. We take both the super set of packageNames
3943 * in addition to specific applications to remove, the reason being that
3944 * this can be called when a package is updated as well. In that scenario,
3945 * we only remove specific components from the workspace, where as
3946 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003947 *
3948 * Implementation of the method from LauncherModel.Callbacks.
3949 */
Winson Chung83892cc2013-05-01 16:53:33 -07003950 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003951 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003952 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003953 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003954 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003955 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003956 }
Winson Chungd64d1762013-08-20 14:37:16 -07003957 };
3958 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003959 return;
3960 }
3961
Winson Chung64359a52013-07-08 17:17:08 -07003962 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003963 mWorkspace.removeItemsByPackageName(packageNames);
3964 } else {
3965 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003966 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003967
Winson Chunga1820962011-10-03 16:31:06 -07003968 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003969 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003970
3971 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3972 mAppsCustomizeContent != null) {
3973 mAppsCustomizeContent.removeApps(appInfos);
3974 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003975 }
Joe Onoratobe386092009-11-17 17:32:16 -08003976
3977 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003978 * A number of packages were updated.
3979 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003980 private ArrayList<Object> mWidgetsAndShortcuts;
3981 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003982 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003983 bindPackagesUpdated(mWidgetsAndShortcuts);
3984 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003985 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003986 };
3987
3988 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3989 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3990 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003991 return;
3992 }
3993
Winson Chung64359a52013-07-08 17:17:08 -07003994 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003995 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3996 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003997 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003998 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003999 }
4000
Winson Chung400438b2011-01-16 17:53:48 -08004001 private int mapConfigurationOriActivityInfoOri(int configOri) {
4002 final Display d = getWindowManager().getDefaultDisplay();
4003 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4004 switch (d.getRotation()) {
4005 case Surface.ROTATION_0:
4006 case Surface.ROTATION_180:
4007 // We are currently in the same basic orientation as the natural orientation
4008 naturalOri = configOri;
4009 break;
4010 case Surface.ROTATION_90:
4011 case Surface.ROTATION_270:
4012 // We are currently in the other basic orientation to the natural orientation
4013 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4014 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4015 break;
4016 }
4017
4018 int[] oriMap = {
4019 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4020 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4021 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4022 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4023 };
4024 // Since the map starts at portrait, we need to offset if this device's natural orientation
4025 // is landscape.
4026 int indexOffset = 0;
4027 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4028 indexOffset = 1;
4029 }
4030 return oriMap[(d.getRotation() + indexOffset) % 4];
4031 }
Adam Cohen446e9402011-09-15 18:21:21 -07004032
Winson Chung4b919f82012-05-01 10:44:08 -07004033 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004034 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004035 getResources().getBoolean(R.bool.allow_rotation);
4036 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004037 }
Winson Chung4b919f82012-05-01 10:44:08 -07004038 public void lockScreenOrientation() {
4039 if (isRotationEnabled()) {
4040 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4041 .getConfiguration().orientation));
4042 }
4043 }
4044 public void unlockScreenOrientation(boolean immediate) {
4045 if (isRotationEnabled()) {
4046 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004047 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004048 } else {
4049 mHandler.postDelayed(new Runnable() {
4050 public void run() {
4051 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4052 }
4053 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004054 }
Winson Chung4b919f82012-05-01 10:44:08 -07004055 }
Winson Chung400438b2011-01-16 17:53:48 -08004056 }
4057
Winson Chung82f55532011-08-09 14:14:23 -07004058 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004059 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004060 if (DISABLE_CLINGS) {
4061 return false;
4062 }
4063
Brett Chabot2a9e2282011-08-23 15:03:13 -07004064 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004065 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004066
Michael Jurkae233a8b2013-03-19 13:49:20 +01004067 // Restricted secondary users (child mode) will potentially have very few apps
4068 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004069// boolean supportsLimitedUsers =
4070// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4071// Account[] accounts = AccountManager.get(this).getAccounts();
4072// if (supportsLimitedUsers && accounts.length == 0) {
4073// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4074// Bundle restrictions = um.getUserRestrictions();
4075// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4076// return false;
4077// }
4078// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004079 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004080 }
Michael Jurka22143132012-10-04 17:42:38 +02004081
Winson Chung7d7541e2011-09-16 20:14:36 -07004082 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02004083 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004084 if (cling != null) {
4085 cling.init(this, positionData);
4086 cling.setVisibility(View.VISIBLE);
4087 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
4088 if (animate) {
4089 cling.buildLayer();
4090 cling.setAlpha(0f);
4091 cling.animate()
4092 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07004093 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07004094 .setDuration(SHOW_CLING_DURATION)
4095 .setStartDelay(delay)
4096 .start();
4097 } else {
4098 cling.setAlpha(1f);
4099 }
Michael Jurka22143132012-10-04 17:42:38 +02004100 cling.setFocusableInTouchMode(true);
4101 cling.post(new Runnable() {
4102 public void run() {
4103 cling.setFocusable(true);
4104 cling.requestFocus();
4105 }
4106 });
4107 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
4108 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004109 }
4110 return cling;
4111 }
Michael Jurka22143132012-10-04 17:42:38 +02004112
Winson Chung7d7541e2011-09-16 20:14:36 -07004113 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08004114 // To catch cases where siblings of top-level views are made invisible, just check whether
4115 // the cling is directly set to GONE before dismissing it.
4116 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07004117 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07004118 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07004119 anim.addListener(new AnimatorListenerAdapter() {
4120 public void onAnimationEnd(Animator animation) {
4121 cling.setVisibility(View.GONE);
4122 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004123 // We should update the shared preferences on a background thread
4124 new Thread("dismissClingThread") {
4125 public void run() {
4126 SharedPreferences.Editor editor = mSharedPrefs.edit();
4127 editor.putBoolean(flag, true);
4128 editor.commit();
4129 }
4130 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07004131 };
4132 });
4133 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02004134 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07004135 }
4136 }
Michael Jurka22143132012-10-04 17:42:38 +02004137
Winson Chung9d9d74f2011-09-19 11:49:12 -07004138 private void removeCling(int id) {
4139 final View cling = findViewById(id);
4140 if (cling != null) {
4141 final ViewGroup parent = (ViewGroup) cling.getParent();
4142 parent.post(new Runnable() {
4143 @Override
4144 public void run() {
4145 parent.removeView(cling);
4146 }
4147 });
Michael Jurka22143132012-10-04 17:42:38 +02004148 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004149 }
4150 }
Michael Jurka974c3862012-05-22 22:00:31 -07004151
4152 private boolean skipCustomClingIfNoAccounts() {
4153 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4154 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4155 if (customCling) {
4156 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004157 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004158 Account[] accounts = am.getAccountsByType("com.google");
4159 return accounts.length == 0;
4160 }
4161 return false;
4162 }
4163
Winson Chung7d7541e2011-09-16 20:14:36 -07004164 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004165 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004166 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07004167 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
4168 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004169 // If we're not using the default workspace layout, replace workspace cling
4170 // with a custom workspace cling (usually specified in an overlay)
4171 // For now, only do this on tablets
4172 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004173 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004174 // Use a custom cling
4175 View cling = findViewById(R.id.workspace_cling);
4176 ViewGroup clingParent = (ViewGroup) cling.getParent();
4177 int clingIndex = clingParent.indexOfChild(cling);
4178 clingParent.removeViewAt(clingIndex);
4179 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4180 clingParent.addView(customCling, clingIndex);
4181 customCling.setId(R.id.workspace_cling);
4182 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004183 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004184 } else {
4185 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004186 }
4187 }
4188 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004189 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004190 if (isClingsEnabled() &&
4191 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004192 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004193 } else {
4194 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004195 }
4196 }
4197 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004198 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004199 if (isClingsEnabled() &&
4200 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4201 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004202 } else {
4203 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004204 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004205 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004206 }
Michael Jurka104c4562013-07-08 18:03:46 -07004207 protected SharedPreferences getSharedPrefs() {
4208 return mSharedPrefs;
4209 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004210 public boolean isFolderClingVisible() {
4211 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004212 if (cling != null) {
4213 return cling.getVisibility() == View.VISIBLE;
4214 }
4215 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004216 }
Winson Chung82f55532011-08-09 14:14:23 -07004217 public void dismissWorkspaceCling(View v) {
4218 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004219 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004220 }
4221 public void dismissAllAppsCling(View v) {
4222 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004223 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4224 }
4225 public void dismissFolderCling(View v) {
4226 Cling cling = (Cling) findViewById(R.id.folder_cling);
4227 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004228 }
4229
Winson Chung80baf5a2010-08-09 16:03:15 -07004230 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004231 * Prints out out state for debugging.
4232 */
4233 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004234 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004235 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004236 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4237 Log.d(TAG, "mRestoring=" + mRestoring);
4238 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4239 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004240 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004241 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004242
Winson Chung785d2eb2011-04-14 16:08:02 -07004243 if (mAppsCustomizeContent != null) {
4244 mAppsCustomizeContent.dumpState();
4245 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004246 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004247 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004248
4249 @Override
4250 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4251 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004252 synchronized (sDumpLogs) {
4253 writer.println(" ");
4254 writer.println("Debug logs: ");
4255 for (int i = 0; i < sDumpLogs.size(); i++) {
4256 writer.println(" " + sDumpLogs.get(i));
4257 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004258 }
4259 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004260
4261 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004262 if (DEBUG_DUMP_LOG) {
4263 synchronized (sDumpLogs) {
4264 Log.d(TAG, "");
4265 Log.d(TAG, "*********************");
4266 Log.d(TAG, "Launcher debug logs: ");
4267 for (int i = 0; i < sDumpLogs.size(); i++) {
4268 Log.d(TAG, " " + sDumpLogs.get(i));
4269 }
4270 Log.d(TAG, "*********************");
4271 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004272 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004273 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004274 }
4275
4276 public static void addDumpLog(String tag, String log, boolean debugLog) {
4277 if (debugLog) {
4278 Log.d(tag, log);
4279 }
Winson Chungede41292013-09-19 16:27:36 -07004280 if (DEBUG_DUMP_LOG) {
4281 sDateStamp.setTime(System.currentTimeMillis());
4282 synchronized (sDumpLogs) {
4283 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004284 }
Winson Chungede41292013-09-19 16:27:36 -07004285 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004286 }
4287
Winson Chungede41292013-09-19 16:27:36 -07004288 public void dumpLogsToLocalData() {
4289 if (DEBUG_DUMP_LOG) {
4290 new Thread("DumpLogsToLocalData") {
4291 @Override
4292 public void run() {
4293 boolean success = false;
4294 sDateStamp.setTime(sRunStart);
4295 String FILENAME = sDateStamp.getMonth() + "-"
4296 + sDateStamp.getDay() + "_"
4297 + sDateStamp.getHours() + "-"
4298 + sDateStamp.getMinutes() + "_"
4299 + sDateStamp.getSeconds() + ".txt";
4300
4301 FileOutputStream fos = null;
4302 File outFile = null;
4303 try {
4304 outFile = new File(getFilesDir(), FILENAME);
4305 outFile.createNewFile();
4306 fos = new FileOutputStream(outFile);
4307 } catch (Exception e) {
4308 e.printStackTrace();
4309 }
4310 if (fos != null) {
4311 PrintWriter writer = new PrintWriter(fos);
4312
4313 writer.println(" ");
4314 writer.println("Debug logs: ");
4315 synchronized (sDumpLogs) {
4316 for (int i = 0; i < sDumpLogs.size(); i++) {
4317 writer.println(" " + sDumpLogs.get(i));
4318 }
4319 }
4320 writer.close();
4321 }
4322 try {
4323 if (fos != null) {
4324 fos.close();
4325 success = true;
4326 }
4327 } catch (IOException e) {
4328 e.printStackTrace();
4329 }
4330 }
4331 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004332 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004333 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004334}
Michael Jurka2763be32011-02-24 11:19:57 -08004335
Michael Jurkaabded662011-03-04 12:06:57 -08004336interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004337 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004338 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004339 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004340 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004341 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004342}