blob: 84d5a09f7c0007292e87ea66b2b0b67f53c88907 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
212 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700213 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700214
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800215 private final BroadcastReceiver mCloseSystemDialogsReceiver
216 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800217 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private LayoutInflater mInflater;
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700222 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800223 private DragLayer mDragLayer;
224 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700225 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700227 private AppWidgetManager mAppWidgetManager;
228 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700229
Michael Jurkac9d95c52011-08-29 14:03:34 -0700230 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700231 private AppWidgetProviderInfo mPendingAddWidgetInfo;
232
Michael Jurka0280c3b2010-09-17 15:00:07 -0700233 private int[] mTmpAddItemCellCoordinates = new int[2];
234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private FolderInfo mFolderInfo;
236
Winson Chung3d503fb2011-07-13 17:25:49 -0700237 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700238 private View mOverviewPanel;
239
Michael Jurka838a4ca2011-02-07 13:33:06 -0800240 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700241
Winson Chungc51db6a2011-10-05 11:44:49 -0700242 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700243 private AppsCustomizeTabHost mAppsCustomizeTabHost;
244 private AppsCustomizePagedView mAppsCustomizeContent;
245 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100246 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700249 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
250 // scroll issues (because the workspace may not have been measured yet) and extra work.
251 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
252 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
254 private SpannableStringBuilder mDefaultKeySsb = null;
255
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256 private boolean mWorkspaceLoading = true;
257
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800258 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private boolean mRestoring;
260 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700261 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262
Michael Jurka1e2f4652013-07-08 18:03:46 -0700263 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700264 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
265
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // Keep track of whether the user has left launcher
267 private static boolean sPausedFromUserAction = false;
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private Bundle mSavedInstanceState;
270
Joe Onorato9c1289c2009-08-17 11:03:03 -0400271 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800272 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800273 private boolean mUserPresent = true;
274 private boolean mVisible = false;
275 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700276 private static final boolean DISABLE_CLINGS = true;
Winson Chunge6eabff2013-09-24 11:01:23 -0700277 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400278
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700279 private static LocaleConfiguration sLocaleConfiguration = null;
280
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700281 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700282
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700283 private Intent mAppMarketIntent = null;
284
Adam Cohended9f8d2010-11-03 13:25:16 -0700285 // Related to the auto-advancing of widgets
286 private final int ADVANCE_MSG = 1;
287 private final int mAdvanceInterval = 20000;
288 private final int mAdvanceStagger = 250;
289 private long mAutoAdvanceSentTime;
290 private long mAutoAdvanceTimeLeft = -1;
291 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
292 new HashMap<View, AppWidgetProviderInfo>();
293
Winson Chung400438b2011-01-16 17:53:48 -0800294 // Determines how long to wait after a rotation before restoring the screen orientation to
295 // match the sensor state.
296 private final int mRestoreScreenOrientationDelay = 500;
297
Michael Jurka4ef207b2010-11-29 17:05:45 -0800298 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700299 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
301 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800302
Craig Mautner360310b2012-10-26 15:13:08 -0700303 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700304
Adam Cohen1462de32012-07-24 22:34:36 -0700305 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
306
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700307 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700308 static Date sDateStamp = new Date();
309 static DateFormat sDateFormat =
310 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
311 static long sRunStart = System.currentTimeMillis();
312 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Adam Cohene25af792013-06-06 23:08:25 -0700318 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
319
Winson Chungf0c6ae02012-03-21 16:10:31 -0700320 // Holds the page that we need to animate to, and the icon views that we need to animate up
321 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700322 private ImageView mFolderIconImageView;
323 private Bitmap mFolderIconBitmap;
324 private Canvas mFolderIconCanvas;
325 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700326
Michael Jurkaddd62e92011-02-16 17:49:14 -0800327 private BubbleTextView mWaitingForResume;
328
Michael Jurka22143132012-10-04 17:42:38 +0200329 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
330 = new HideFromAccessibilityHelper();
331
Michael Jurkac1f5d262011-09-30 19:32:27 -0700332 private Runnable mBuildLayersRunnable = new Runnable() {
333 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700334 if (mWorkspace != null) {
335 mWorkspace.buildPageHardwareLayers();
336 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700337 }
338 };
339
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800340 private static ArrayList<PendingAddArguments> sPendingAddList
341 = new ArrayList<PendingAddArguments>();
342
Michael Jurka0a457bf2012-11-19 14:05:05 -0800343 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
344
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800345 private static class PendingAddArguments {
346 int requestCode;
347 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700348 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700349 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800350 int cellX;
351 int cellY;
352 }
353
Daniel Sandlerff02d492013-08-05 02:12:05 -0400354 private Stats mStats;
355
Michael Jurka0a457bf2012-11-19 14:05:05 -0800356 private static boolean isPropertyEnabled(String propertyName) {
357 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700358 }
359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 @Override
361 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700362 if (DEBUG_STRICT_MODE) {
363 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
364 .detectDiskReads()
365 .detectDiskWrites()
366 .detectNetwork() // or .detectAll() for all detectable problems
367 .penaltyLog()
368 .build());
369 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
370 .detectLeakedSqlLiteObjects()
371 .detectLeakedClosableObjects()
372 .penaltyLog()
373 .penaltyDeath()
374 .build());
375 }
376
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400378
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400379 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400380 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700381
382 // Determine the dynamic grid properties
383 Point smallestSize = new Point();
384 Point largestSize = new Point();
385 Point realSize = new Point();
386 Display display = getWindowManager().getDefaultDisplay();
387 display.getCurrentSizeRange(smallestSize, largestSize);
388 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700389 DisplayMetrics dm = new DisplayMetrics();
390 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700391 // Lazy-initialize the dynamic grid
392 DeviceProfile grid = app.initDynamicGrid(this,
393 Math.min(smallestSize.x, smallestSize.y),
394 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700395 realSize.x, realSize.y,
396 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700397
398 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400399 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700400 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800401 mModel = app.setLauncher(this);
402 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400403 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700405
Daniel Sandlerff02d492013-08-05 02:12:05 -0400406 mStats = new Stats(this);
407
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700408 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700409 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
410 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700411
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700412 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
413 // this also ensures that any synchronous binding below doesn't re-trigger another
414 // LauncherModel load.
415 mPaused = false;
416
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800417 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200418 android.os.Debug.startMethodTracing(
419 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 }
421
422 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800423 setContentView(R.layout.launcher);
424 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100425 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800427 registerContentObservers();
428
Joe Onorato7c312c12009-08-13 21:36:53 -0700429 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700430
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 mSavedState = savedInstanceState;
432 restoreState(mSavedState);
433
Winson Chunga12a2502010-12-20 14:41:35 -0800434 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700435 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200436 mAppsCustomizeContent.onPackagesUpdated(
437 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700438 }
Winson Chunga12a2502010-12-20 14:41:35 -0800439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
441 android.os.Debug.stopMethodTracing();
442 }
443
444 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700445 if (sPausedFromUserAction) {
446 // If the user leaves launcher, then we should just load items asynchronously when
447 // they return.
448 mModel.startLoader(true, -1);
449 } else {
450 // We only load the page synchronously if the user rotates (or triggers a
451 // configuration change) while launcher is in the foreground
452 mModel.startLoader(true, mWorkspace.getCurrentPage());
453 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 }
455
456 // For handling default keys
457 mDefaultKeySsb = new SpannableStringBuilder();
458 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800459
460 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
461 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800462
Adam Cohenf9426d52012-06-04 17:26:21 -0700463 updateGlobalIcons();
464
465 // On large interfaces, we want the screen to auto-rotate based on the current orientation
466 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700467
468 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700469 }
470
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 protected void onUserLeaveHint() {
472 super.onUserLeaveHint();
473 sPausedFromUserAction = true;
474 }
475
Winson Chung98ca0f72013-07-29 12:58:51 -0700476 /** To be overriden by subclasses to hint to Launcher that we have custom content */
477 protected boolean hasCustomContentToLeft() {
478 return false;
479 }
480
Dave Hawkeya8881582013-09-17 15:55:33 -0600481 /**
482 * To be overridden by subclasses to create the custom content and call
483 * {@link #addToCustomContentPage}. This will only be invoked if
484 * {@link #hasCustomContentToLeft()} is {@code true}.
485 */
486 protected void addCustomContentToLeft() {
487 }
488
489 /**
490 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
491 * ensure the custom content page is added or removed if necessary.
492 */
493 protected void invalidateHasCustomContentToLeft() {
494 if (mWorkspace.getScreenOrder().isEmpty()) {
495 // Not bound yet, wait for bindScreens to be called.
496 return;
497 }
498
499 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
500 // Create the custom content page and call the subclass to populate it.
501 mWorkspace.createCustomContentPage();
502 addCustomContentToLeft();
503 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
504 mWorkspace.removeCustomContentPage();
505 }
506 }
507
Adam Cohenf9426d52012-06-04 17:26:21 -0700508 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700509 boolean searchVisible = false;
510 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800511 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700512 int coi = getCurrentOrientationIndexForGlobalIcons();
513 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
514 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700515 updateAppMarketIcon();
516 searchVisible = updateGlobalSearchIcon();
517 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700518 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700519 if (sGlobalSearchIcon[coi] != null) {
520 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700521 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700522 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700523 if (sVoiceSearchIcon[coi] != null) {
524 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700525 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700526 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700527 if (sAppMarketIcon[coi] != null) {
528 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800529 }
Winson Chungadf0c182012-08-23 14:59:07 -0700530 if (mSearchDropTargetBar != null) {
531 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
532 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800533 }
Romain Guycbb89e42009-06-08 15:52:54 -0700534
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800535 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700536 if (sLocaleConfiguration == null) {
537 new AsyncTask<Void, Void, LocaleConfiguration>() {
538 @Override
539 protected LocaleConfiguration doInBackground(Void... unused) {
540 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
541 readConfiguration(Launcher.this, localeConfiguration);
542 return localeConfiguration;
543 }
544
545 @Override
546 protected void onPostExecute(LocaleConfiguration result) {
547 sLocaleConfiguration = result;
548 checkForLocaleChange(); // recursive, but now with a locale configuration
549 }
550 }.execute();
551 return;
552 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700553
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800554 final Configuration configuration = getResources().getConfiguration();
555
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700556 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800557 final String locale = configuration.locale.toString();
558
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700559 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 final int mcc = configuration.mcc;
561
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700562 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 final int mnc = configuration.mnc;
564
Romain Guy84f296c2009-11-04 15:00:44 -0800565 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566
Romain Guy84f296c2009-11-04 15:00:44 -0800567 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 sLocaleConfiguration.locale = locale;
569 sLocaleConfiguration.mcc = mcc;
570 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700571
Joe Onorato0589f0f2010-02-08 13:44:00 -0800572 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700573
574 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
575 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700576 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700577 public void run() {
578 writeConfiguration(Launcher.this, localeConfiguration);
579 }
580 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700581 }
582 }
583
584 private static class LocaleConfiguration {
585 public String locale;
586 public int mcc = -1;
587 public int mnc = -1;
588 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700589
Romain Guy98d01652009-06-30 16:21:04 -0700590 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
591 DataInputStream in = null;
592 try {
593 in = new DataInputStream(context.openFileInput(PREFERENCES));
594 configuration.locale = in.readUTF();
595 configuration.mcc = in.readInt();
596 configuration.mnc = in.readInt();
597 } catch (FileNotFoundException e) {
598 // Ignore
599 } catch (IOException e) {
600 // Ignore
601 } finally {
602 if (in != null) {
603 try {
604 in.close();
605 } catch (IOException e) {
606 // Ignore
607 }
608 }
609 }
610 }
611
612 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
613 DataOutputStream out = null;
614 try {
615 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
616 out.writeUTF(configuration.locale);
617 out.writeInt(configuration.mcc);
618 out.writeInt(configuration.mnc);
619 out.flush();
620 } catch (FileNotFoundException e) {
621 // Ignore
622 } catch (IOException e) {
623 //noinspection ResultOfMethodCallIgnored
624 context.getFileStreamPath(PREFERENCES).delete();
625 } finally {
626 if (out != null) {
627 try {
628 out.close();
629 } catch (IOException e) {
630 // Ignore
631 }
632 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 }
634 }
635
Bjorn Bringertc459e522013-06-07 19:36:01 +0100636 public LayoutInflater getInflater() {
637 return mInflater;
638 }
639
Adam Cohen716b51e2011-06-30 12:09:54 -0700640 public DragLayer getDragLayer() {
641 return mDragLayer;
642 }
643
Winson Chung36a62fe2012-05-06 18:04:42 -0700644 boolean isDraggingEnabled() {
645 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
646 // that is subsequently removed from the workspace in startBinding().
647 return !mModel.isLoadingWorkspace();
648 }
649
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650 static int getScreen() {
651 synchronized (sLock) {
652 return sScreen;
653 }
654 }
655
656 static void setScreen(int screen) {
657 synchronized (sLock) {
658 sScreen = screen;
659 }
660 }
661
Winson Chung557d6ed2011-07-08 15:34:52 -0700662 /**
663 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
664 * a configuration step, this allows the proper animations to run after other transitions.
665 */
666 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700667 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800668 switch (args.requestCode) {
669 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700670 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700671 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800672 break;
673 case REQUEST_PICK_SHORTCUT:
674 processShortcut(args.intent);
675 break;
676 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700677 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700678 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700679 result = true;
680 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800681 case REQUEST_CREATE_APPWIDGET:
682 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700683 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700684 result = true;
685 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 }
Michael Jurka27614d22012-04-02 06:40:22 -0700687 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
688 // if you turned the screen off and then back while in All Apps, Launcher would not
689 // return to the workspace. Clearing mAddInfo.container here fixes this issue
690 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700691 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800692 }
693
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700695 protected void onActivityResult(
696 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700697 // Reset the startActivity waiting flag
698 mWaitingForResult = false;
699
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 if (requestCode == REQUEST_BIND_APPWIDGET) {
701 int appWidgetId = data != null ?
702 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
703 if (resultCode == RESULT_CANCELED) {
704 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
705 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700706 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700707 }
708 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200709 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
710 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
711 mWorkspace.exitOverviewMode(false);
712 }
713 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700714 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200715
Winson Chung557d6ed2011-07-08 15:34:52 -0700716 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800717 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
718 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700719
Adam Cohened66b2b2012-01-23 17:28:51 -0800720 // We have special handling for widgets
721 if (isWidgetDrop) {
722 int appWidgetId = data != null ?
723 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700724 if (appWidgetId < 0) {
725 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
726 "widget configuration activity.");
727 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
728 } else {
729 completeTwoStageWidgetDrop(resultCode, appWidgetId);
730 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800731 return;
732 }
733
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 // The pattern used here is that a user PICKs a specific application,
735 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700736
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
738 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700739 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 final PendingAddArguments args = new PendingAddArguments();
741 args.requestCode = requestCode;
742 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700743 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700744 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700745 args.cellX = mPendingAddInfo.cellX;
746 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 if (isWorkspaceLocked()) {
748 sPendingAddList.add(args);
749 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700750 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800753 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700754 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800755 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
756 null);
757 }
758
759 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700761 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800762 Runnable onCompleteRunnable = null;
763 int animationType = 0;
764
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700765 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800766 if (resultCode == RESULT_OK) {
767 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
768 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700769 mPendingAddWidgetInfo);
770 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800771 onCompleteRunnable = new Runnable() {
772 @Override
773 public void run() {
774 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700775 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
777 null);
778 }
779 };
780 } else if (resultCode == RESULT_CANCELED) {
781 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
782 onCompleteRunnable = new Runnable() {
783 @Override
784 public void run() {
785 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
786 null);
787 }
788 };
789 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700790 if (mDragLayer.getAnimatedView() != null) {
791 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
792 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
793 animationType, boundWidget, true);
794 } else {
795 // The animated view may be null in the case of a rotation during widget configuration
796 onCompleteRunnable.run();
797 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800798 }
799
800 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700801 protected void onStop() {
802 super.onStop();
803 FirstFrameAnimatorHelper.setIsVisible(false);
804 }
805
806 @Override
807 protected void onStart() {
808 super.onStart();
809 FirstFrameAnimatorHelper.setIsVisible(true);
810 }
811
812 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200814 long startTime = 0;
815 if (DEBUG_RESUME_TIME) {
816 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400817 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200818 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700820
Winson Chung4a2afa32012-07-19 14:53:05 -0700821 // Restore the previous launcher state
822 if (mOnResumeState == State.WORKSPACE) {
823 showWorkspace(false);
824 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700825 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700826 }
827 mOnResumeState = State.NONE;
828
Craig Mautner360310b2012-10-26 15:13:08 -0700829 // Background was set to gradient in onPause(), restore to black if in all apps.
830 setWorkspaceBackground(mState == State.WORKSPACE);
831
Winson Chungde0fb8f2012-05-08 14:37:08 -0700832 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700833 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700834
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800835 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700836 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700837 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400838 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700839 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400840 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700841 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700843 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200844 // We might have postponed some bind calls until onResume (see waitUntilResume) --
845 // execute them here
846 long startTimeCallbacks = 0;
847 if (DEBUG_RESUME_TIME) {
848 startTimeCallbacks = System.currentTimeMillis();
849 }
850
851 if (mAppsCustomizeContent != null) {
852 mAppsCustomizeContent.setBulkBind(true);
853 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700854 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
855 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200856 }
857 if (mAppsCustomizeContent != null) {
858 mAppsCustomizeContent.setBulkBind(false);
859 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700860 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200861 if (DEBUG_RESUME_TIME) {
862 Log.d(TAG, "Time spent processing callbacks in onResume: " +
863 (System.currentTimeMillis() - startTimeCallbacks));
864 }
Michael Jurka447bf842013-05-15 14:52:15 +0200865 }
Michael Jurka54554252013-08-01 12:52:23 +0200866 if (mOnResumeCallbacks.size() > 0) {
867 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
868 mOnResumeCallbacks.get(i).run();
869 }
870 mOnResumeCallbacks.clear();
871 }
Winson Chunge4e50662012-01-23 14:45:13 -0800872
873 // Reset the pressed state of icons that were locked in the press state while activities
874 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800875 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800876 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800877 mWaitingForResume.setStayPressed(false);
878 }
Winson Chunge4e50662012-01-23 14:45:13 -0800879 if (mAppsCustomizeContent != null) {
880 // Resets the previous all apps icon press state
881 mAppsCustomizeContent.resetDrawableState();
882 }
Adam Cohen06dff352012-06-01 17:17:08 -0700883 // It is possible that widgets can receive updates while launcher is not in the foreground.
884 // Consequently, the widgets will be inflated in the orientation of the foreground activity
885 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
886 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700887 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700888
889 // Again, as with the above scenario, it's possible that one or more of the global icons
890 // were updated in the wrong orientation.
891 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200892 if (DEBUG_RESUME_TIME) {
893 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
894 }
Adam Cohen06dff352012-06-01 17:17:08 -0700895 }
896
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700898 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700899 // Ensure that items added to Launcher are queued until Launcher returns
900 InstallShortcutReceiver.enableInstallQueue();
901
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700902 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700903 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800904 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700905 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700906 }
Romain Guycbb89e42009-06-08 15:52:54 -0700907
Adam Cohen66a01fd2013-06-11 12:48:00 -0700908 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600909 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
910 addCustomContentToLeft();
911 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700912 }
913
Adam Cohenbffe7452013-07-22 18:21:45 -0700914 QSBScroller mQsbScroller = new QSBScroller() {
915 int scrollY = 0;
916
917 @Override
918 public void setScrollY(int scroll) {
919 scrollY = scroll;
920
921 if (mWorkspace.isOnOrMovingToCustomContent()) {
922 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100923 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700924 }
925 }
926 };
927
928 public void resetQSBScroll() {
929 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100930 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700931 }
932
933 public interface CustomContentCallbacks {
934 // Custom content is completely shown
935 public void onShow();
936
937 // Custom content is completely hidden
938 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700939
940 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
941 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700942 }
943
Adam Cohen30bacb22013-08-29 14:25:25 -0700944 protected void startSettings() {
945 }
946
Adam Cohenbffe7452013-07-22 18:21:45 -0700947 public interface QSBScroller {
948 public void setScrollY(int scrollY);
949 }
950
Adam Cohen66a01fd2013-06-11 12:48:00 -0700951 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700952 public QSBScroller addToCustomContentPage(View customContent) {
953 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700954 }
955
Winson Chung98ca0f72013-07-29 12:58:51 -0700956 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700957 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700958 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700959 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700960 }
961
Adam Cohenedb40762013-07-18 16:45:45 -0700962 // The custom content needs to offset its content to account for the QSB
963 public int getTopOffsetForCustomContent() {
964 return mWorkspace.getPaddingTop();
965 }
966
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700967 @Override
968 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400969 // Flag the loader to stop early before switching
970 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700971 if (mAppsCustomizeContent != null) {
972 mAppsCustomizeContent.surrender();
973 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800974 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700975 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700976
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800977 // We can't hide the IME if it was forced open. So don't bother
978 /*
979 @Override
980 public void onWindowFocusChanged(boolean hasFocus) {
981 super.onWindowFocusChanged(hasFocus);
982
983 if (hasFocus) {
984 final InputMethodManager inputManager = (InputMethodManager)
985 getSystemService(Context.INPUT_METHOD_SERVICE);
986 WindowManager.LayoutParams lp = getWindow().getAttributes();
987 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
988 android.os.Handler()) {
989 protected void onReceiveResult(int resultCode, Bundle resultData) {
990 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
991 }
992 });
993 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
994 }
995 }
996 */
997
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998 private boolean acceptFilter() {
999 final InputMethodManager inputManager = (InputMethodManager)
1000 getSystemService(Context.INPUT_METHOD_SERVICE);
1001 return !inputManager.isFullscreenMode();
1002 }
1003
1004 @Override
1005 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001006 final int uniChar = event.getUnicodeChar();
1007 final boolean handled = super.onKeyDown(keyCode, event);
1008 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1009 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1011 keyCode, event);
1012 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001013 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001014 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001015 // showSearchDialog()
1016 // If there are multiple keystrokes before the search dialog takes focus,
1017 // onSearchRequested() will be called for every keystroke,
1018 // but it is idempotent, so it's fine.
1019 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 }
1021 }
1022
Joe Onorato8a9625e2010-01-28 15:55:35 -08001023 // Eat the long press event so the keyboard doesn't come up.
1024 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1025 return true;
1026 }
1027
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 return handled;
1029 }
1030
Karl Rosaen138a0412009-04-23 19:00:21 -07001031 private String getTypedText() {
1032 return mDefaultKeySsb.toString();
1033 }
1034
1035 private void clearTypedText() {
1036 mDefaultKeySsb.clear();
1037 mDefaultKeySsb.clearSpans();
1038 Selection.setSelection(mDefaultKeySsb, 0);
1039 }
1040
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001042 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1043 * State
1044 */
1045 private static State intToState(int stateOrdinal) {
1046 State state = State.WORKSPACE;
1047 final State[] stateValues = State.values();
1048 for (int i = 0; i < stateValues.length; i++) {
1049 if (stateValues[i].ordinal() == stateOrdinal) {
1050 state = stateValues[i];
1051 break;
1052 }
1053 }
1054 return state;
1055 }
1056
1057 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 * Restores the previous state, if it exists.
1059 *
1060 * @param savedState The previous state.
1061 */
1062 private void restoreState(Bundle savedState) {
1063 if (savedState == null) {
1064 return;
1065 }
1066
Michael Jurka883f55b2010-10-21 15:47:14 -07001067 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001068 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001069 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001070 }
1071
Winson Chungf0c6ae02012-03-21 16:10:31 -07001072 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001074 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 }
1076
Winson Chung3d503fb2011-07-13 17:25:49 -07001077 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001078 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001079
Winson Chung3d503fb2011-07-13 17:25:49 -07001080 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1081 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001082 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001083 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1084 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001085 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1086 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1087 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001088 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001089 mRestoring = true;
1090 }
1091
1092 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1093 if (renameFolder) {
1094 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001095 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001096 mRestoring = true;
1097 }
Winson Chunga12a2502010-12-20 14:41:35 -08001098
Winson Chung785d2eb2011-04-14 16:08:02 -07001099 // Restore the AppsCustomize tab
1100 if (mAppsCustomizeTabHost != null) {
1101 String curTab = savedState.getString("apps_customize_currentTab");
1102 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001103 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001104 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001105 mAppsCustomizeContent.loadAssociatedPages(
1106 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001107 }
1108
Winson Chung5afbf7b2011-07-25 11:53:08 -07001109 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1110 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001111 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 }
1113
1114 /**
1115 * Finds all the views we need and configure them properly.
1116 */
1117 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001118 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001119
Craig Mautner360310b2012-10-26 15:13:08 -07001120 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001121 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1122 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001123
John Spurlock77e1f472013-09-11 10:09:51 -04001124 mLauncherView.setSystemUiVisibility(
1125 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001126 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127
Winson Chung4c98d922011-05-31 16:50:48 -07001128 // Setup the drag layer
1129 mDragLayer.setup(this, dragController);
1130
Winson Chung3d503fb2011-07-13 17:25:49 -07001131 // Setup the hotseat
1132 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1133 if (mHotseat != null) {
1134 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001135 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001136 }
1137
Adam Cohenf358a4b2013-07-23 16:47:31 -07001138 mOverviewPanel = findViewById(R.id.overview_panel);
1139 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1140 @Override
1141 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001142 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001143 }
1144 });
1145 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1146 @Override
1147 public void onClick(View arg0) {
1148 startWallpaper();
1149 }
1150 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001151 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1152 @Override
1153 public void onClick(View arg0) {
1154 startSettings();
1155 }
1156 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001157 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001158
Winson Chung4c98d922011-05-31 16:50:48 -07001159 // Setup the workspace
1160 mWorkspace.setHapticFeedbackEnabled(false);
1161 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001162 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001163 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001164
Winson Chungf0ea4d32011-06-06 14:27:16 -07001165 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001166 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001167
Winson Chungf0ea4d32011-06-06 14:27:16 -07001168 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001169 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001170 mAppsCustomizeContent = (AppsCustomizePagedView)
1171 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1172 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001173
Winson Chung3d503fb2011-07-13 17:25:49 -07001174 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001175 dragController.setDragScoller(mWorkspace);
1176 dragController.setScrollView(mDragLayer);
1177 dragController.setMoveTarget(mWorkspace);
1178 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001179 if (mSearchDropTargetBar != null) {
1180 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001181 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001182
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001183 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001184 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001185 mWeightWatcher = new WeightWatcher(this);
1186 mWeightWatcher.setAlpha(0.5f);
1187 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001188 new FrameLayout.LayoutParams(
1189 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001190 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001191 Gravity.BOTTOM)
1192 );
Adam Cohen39a06042013-07-19 14:30:12 -07001193
1194 boolean show = shouldShowWeightWatcher();
1195 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 }
1198
1199 /**
1200 * Creates a view representing a shortcut.
1201 *
1202 * @param info The data structure describing the shortcut.
1203 *
1204 * @return A View inflated from R.layout.application.
1205 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001206 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001208 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 /**
1212 * Creates a view representing a shortcut inflated from the specified resource.
1213 *
1214 * @param layoutResId The id of the XML layout used to create the shortcut.
1215 * @param parent The group the shortcut belongs to.
1216 * @param info The data structure describing the shortcut.
1217 *
1218 * @return A View inflated from layoutResId.
1219 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001220 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001221 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1222 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 return favorite;
1225 }
1226
1227 /**
1228 * Add an application shortcut to the workspace.
1229 *
1230 * @param data The intent describing the application.
1231 * @param cellInfo The position on screen where to create the shortcut.
1232 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001233 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001234 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001235 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001236
Adam Cohenfbba09b2011-07-18 21:43:05 -07001237 // First we check if we already know the exact location where we want to add this item.
1238 if (cellX >= 0 && cellY >= 0) {
1239 cellXY[0] = cellX;
1240 cellXY[1] = cellY;
1241 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001242 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001243 return;
1244 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001246 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001247
Romain Guy73b979d2009-06-09 12:57:21 -07001248 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001249 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001251 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001252 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001253 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001254 } else {
1255 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 }
1257 }
Romain Guycbb89e42009-06-08 15:52:54 -07001258
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 /**
1260 * Add a shortcut to the workspace.
1261 *
1262 * @param data The intent describing the shortcut.
1263 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001265 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001266 int cellY) {
1267 int[] cellXY = mTmpAddItemCellCoordinates;
1268 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001269 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001270
Michael Jurkad3ef3062010-11-23 16:23:58 -08001271 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001272
Adam Cohen558baaf2011-08-15 15:22:57 -07001273 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001274 if (info == null) {
1275 return;
1276 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001277 final View view = createShortcut(info);
1278
Adam Cohenfbba09b2011-07-18 21:43:05 -07001279 // First we check if we already know the exact location where we want to add this item.
1280 if (cellX >= 0 && cellY >= 0) {
1281 cellXY[0] = cellX;
1282 cellXY[1] = cellY;
1283 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001284
1285 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001286 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001287 true, null,null)) {
1288 return;
1289 }
1290 DragObject dragObject = new DragObject();
1291 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001292 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1293 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001294 return;
1295 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001296 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001297 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001298 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001299 foundCellSpan = (result != null);
1300 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001301 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001302 }
1303
1304 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001305 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001306 return;
1307 }
1308
Adam Cohendcd297f2013-06-18 13:13:40 -07001309 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310
1311 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001312 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001313 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 }
1315 }
1316
Adam Cohen2f093b62012-04-30 18:59:53 -07001317 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1318 int minHeight) {
1319 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001320 // We want to account for the extra amount of padding that we are adding to the widget
1321 // to ensure that it gets the full amount of space that it has requested
1322 int requiredWidth = minWidth + padding.left + padding.right;
1323 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001324 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001325 }
1326
Adam Cohen2f093b62012-04-30 18:59:53 -07001327 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1328 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001329 }
1330
Adam Cohen2f093b62012-04-30 18:59:53 -07001331 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1332 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001333 }
1334
Adam Cohen2f093b62012-04-30 18:59:53 -07001335 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1336 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1340 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001341 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001342 }
1343
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001345 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001347 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001348 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001350 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001351 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1352 if (appWidgetInfo == null) {
1353 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1354 }
Romain Guycbb89e42009-06-08 15:52:54 -07001355
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001356 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001357 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001358
Adam Cohen2f093b62012-04-30 18:59:53 -07001359 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1360 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001361
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001363 // We have saved the position to which the widget was dragged-- this really only matters
1364 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001365 int[] cellXY = mTmpAddItemCellCoordinates;
1366 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001367 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001368 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001369 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1370 cellXY[0] = mPendingAddInfo.cellX;
1371 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001372 spanXY[0] = mPendingAddInfo.spanX;
1373 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001374 foundCellSpan = true;
1375 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001376 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001378 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1379 spanXY[1], cellXY, finalSpan);
1380 spanXY[0] = finalSpan[0];
1381 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001382 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001383 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001384 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001385 }
1386
Michael Jurka0280c3b2010-09-17 15:00:07 -07001387 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001388 if (appWidgetId != -1) {
1389 // Deleting an app widget ID is a void call but writes to disk before returning
1390 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001391 new Thread("deleteAppWidgetId") {
1392 public void run() {
1393 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1394 }
1395 }.start();
1396 }
Winson Chung93eef082012-03-23 15:59:27 -07001397 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001398 return;
1399 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001401 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001402 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1403 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001404 launcherInfo.spanX = spanXY[0];
1405 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001406 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1407 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001408
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001410 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001411
1412 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001413 if (hostView == null) {
1414 // Perform actual inflation because we're live
1415 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1416 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1417 } else {
1418 // The AppWidgetHostView has already been inflated and instantiated
1419 launcherInfo.hostView = hostView;
1420 }
Romain Guycbb89e42009-06-08 15:52:54 -07001421
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001423 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001424 launcherInfo.notifyWidgetSizeChanged(this);
1425
Adam Cohendcd297f2013-06-18 13:13:40 -07001426 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001427 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001428
1429 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001431 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 }
Romain Guycbb89e42009-06-08 15:52:54 -07001433
Adam Cohended9f8d2010-11-03 13:25:16 -07001434 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1435 @Override
1436 public void onReceive(Context context, Intent intent) {
1437 final String action = intent.getAction();
1438 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1439 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001440 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001441 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001442
Winson Chungc100e8e2011-08-09 16:02:43 -07001443 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001444 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001445 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001446 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001447 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001448 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1449 mUserPresent = true;
1450 updateRunning();
1451 }
1452 }
1453 };
1454
1455 @Override
1456 public void onAttachedToWindow() {
1457 super.onAttachedToWindow();
1458
1459 // Listen for broadcasts related to user-presence
1460 final IntentFilter filter = new IntentFilter();
1461 filter.addAction(Intent.ACTION_SCREEN_OFF);
1462 filter.addAction(Intent.ACTION_USER_PRESENT);
1463 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001464 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001465 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001466 mVisible = true;
1467 }
1468
1469 @Override
1470 public void onDetachedFromWindow() {
1471 super.onDetachedFromWindow();
1472 mVisible = false;
1473
Adam Cohend113e0c2010-11-11 10:48:05 -08001474 if (mAttached) {
1475 unregisterReceiver(mReceiver);
1476 mAttached = false;
1477 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001478 updateRunning();
1479 }
1480
1481 public void onWindowVisibilityChanged(int visibility) {
1482 mVisible = visibility == View.VISIBLE;
1483 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001484 // The following code used to be in onResume, but it turns out onResume is called when
1485 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1486 // is a more appropriate event to handle
1487 if (mVisible) {
1488 mAppsCustomizeTabHost.onWindowVisible();
1489 if (!mWorkspaceLoading) {
1490 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001491 // We want to let Launcher draw itself at least once before we force it to build
1492 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001493 // apps is nice and speedy.
1494 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001495 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001496 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001497 if (mStarted) return;
1498 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001499 // We delay the layer building a bit in order to give
1500 // other message processing a time to run. In particular
1501 // this avoids a delay in hiding the IME if it was
1502 // currently shown, because doing that may involve
1503 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001504 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001505 final ViewTreeObserver.OnDrawListener listener = this;
1506 mWorkspace.post(new Runnable() {
1507 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001508 if (mWorkspace != null &&
1509 mWorkspace.getViewTreeObserver() != null) {
1510 mWorkspace.getViewTreeObserver().
1511 removeOnDrawListener(listener);
1512 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001513 }
1514 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001515 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001516 }
1517 });
1518 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001519 // When Launcher comes back to foreground, a different Activity might be responsible for
1520 // the app market intent, so refresh the icon
1521 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001522 clearTypedText();
1523 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001524 }
1525
1526 private void sendAdvanceMessage(long delay) {
1527 mHandler.removeMessages(ADVANCE_MSG);
1528 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1529 mHandler.sendMessageDelayed(msg, delay);
1530 mAutoAdvanceSentTime = System.currentTimeMillis();
1531 }
1532
1533 private void updateRunning() {
1534 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1535 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1536 mAutoAdvanceRunning = autoAdvanceRunning;
1537 if (autoAdvanceRunning) {
1538 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1539 sendAdvanceMessage(delay);
1540 } else {
1541 if (!mWidgetsToAdvance.isEmpty()) {
1542 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1543 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1544 }
1545 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001546 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001547 }
1548 }
1549 }
1550
1551 private final Handler mHandler = new Handler() {
1552 @Override
1553 public void handleMessage(Message msg) {
1554 if (msg.what == ADVANCE_MSG) {
1555 int i = 0;
1556 for (View key: mWidgetsToAdvance.keySet()) {
1557 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1558 final int delay = mAdvanceStagger * i;
1559 if (v instanceof Advanceable) {
1560 postDelayed(new Runnable() {
1561 public void run() {
1562 ((Advanceable) v).advance();
1563 }
1564 }, delay);
1565 }
1566 i++;
1567 }
1568 sendAdvanceMessage(mAdvanceInterval);
1569 }
1570 }
1571 };
1572
1573 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001574 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001575 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1576 if (v instanceof Advanceable) {
1577 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001578 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001579 updateRunning();
1580 }
1581 }
1582
1583 void removeWidgetToAutoAdvance(View hostView) {
1584 if (mWidgetsToAdvance.containsKey(hostView)) {
1585 mWidgetsToAdvance.remove(hostView);
1586 updateRunning();
1587 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001588 }
1589
Joe Onorato9c1289c2009-08-17 11:03:03 -04001590 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001591 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001592 launcherInfo.hostView = null;
1593 }
1594
Winson Chung93eef082012-03-23 15:59:27 -07001595 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1596 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1597 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001598 }
1599
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001600 public LauncherAppWidgetHost getAppWidgetHost() {
1601 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 }
Romain Guycbb89e42009-06-08 15:52:54 -07001603
Winson Chunga9abd0e2010-10-27 17:18:37 -07001604 public LauncherModel getModel() {
1605 return mModel;
1606 }
1607
Bjorn Bringertc459e522013-06-07 19:36:01 +01001608 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001609 getWindow().closeAllPanels();
1610
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001611 // Whatever we were doing is hereby canceled.
1612 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001613 }
1614
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 @Override
1616 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001617 long startTime = 0;
1618 if (DEBUG_RESUME_TIME) {
1619 startTime = System.currentTimeMillis();
1620 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001621 super.onNewIntent(intent);
1622
1623 // Close the menu
1624 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001625 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001626 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001627
Jamie Genniscb222e82012-10-23 15:44:26 -07001628 final boolean alreadyOnHome =
1629 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001630 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001631
Jamie Genniscb222e82012-10-23 15:44:26 -07001632 Runnable processIntent = new Runnable() {
1633 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001634 if (mWorkspace == null) {
1635 // Can be cases where mWorkspace is null, this prevents a NPE
1636 return;
1637 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001638 Folder openFolder = mWorkspace.getOpenFolder();
1639 // In all these cases, only animate if we're already on home
1640 mWorkspace.exitWidgetResizeMode();
1641 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1642 openFolder == null) {
1643 mWorkspace.moveToDefaultScreen(true);
1644 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001645
Jamie Genniscb222e82012-10-23 15:44:26 -07001646 closeFolder();
1647 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001648
Jamie Genniscb222e82012-10-23 15:44:26 -07001649 // If we are already on home, then just animate back to the workspace,
1650 // otherwise, just wait until onResume to set the state back to Workspace
1651 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001652 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001653 } else {
1654 mOnResumeState = State.WORKSPACE;
1655 }
1656
1657 final View v = getWindow().peekDecorView();
1658 if (v != null && v.getWindowToken() != null) {
1659 InputMethodManager imm = (InputMethodManager)getSystemService(
1660 INPUT_METHOD_SERVICE);
1661 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1662 }
1663
Winson Chung7819a562013-09-19 15:55:45 -07001664 // Reset the apps customize page
1665 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001666 mAppsCustomizeTabHost.reset();
1667 }
1668 }
1669 };
1670
1671 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1672 // Delay processing of the intent to allow the status bar animation to finish
1673 // first in order to avoid janky animations.
1674 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001675 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001676 // Process the intent immediately.
1677 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001678 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001679
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001680 }
Michael Jurka447bf842013-05-15 14:52:15 +02001681 if (DEBUG_RESUME_TIME) {
1682 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1683 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 }
1685
Adam Cohen040a5d22013-09-16 17:09:33 -07001686 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1687 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001688 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001689 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001690 }
1691 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001692 protected void showWorkspaceAndExitOverviewMode() {
1693 showWorkspaceAndExitOverviewMode(true);
1694 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001695
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001697 public void onRestoreInstanceState(Bundle state) {
1698 super.onRestoreInstanceState(state);
1699 for (int page: mSynchronouslyBoundPages) {
1700 mWorkspace.restoreInstanceStateForChild(page);
1701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 }
1703
1704 @Override
1705 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001706 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001707 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708
Michael Jurka883f55b2010-10-21 15:47:14 -07001709 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001710 // We close any open folder since it will not be re-opened, and we need to make sure
1711 // this state is reflected.
1712 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713
Adam Cohendcd297f2013-06-18 13:13:40 -07001714 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001715 mWaitingForResult) {
1716 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001717 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001718 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1719 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001720 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1721 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1722 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001723 }
1724
1725 if (mFolderInfo != null && mWaitingForResult) {
1726 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1727 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1728 }
Michael Jurka946ad472010-07-09 18:05:18 -07001729
Winson Chung785d2eb2011-04-14 16:08:02 -07001730 // Save the current AppsCustomize tab
1731 if (mAppsCustomizeTabHost != null) {
1732 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1733 if (currentTabTag != null) {
1734 outState.putString("apps_customize_currentTab", currentTabTag);
1735 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001736 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1737 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739 }
1740
1741 @Override
1742 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001744
Winson Chunge7a03942011-08-05 15:05:12 -07001745 // Remove all pending runnables
1746 mHandler.removeMessages(ADVANCE_MSG);
1747 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001748 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001749
Winson Chungcd2b0142011-06-08 16:02:26 -07001750 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001751 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001752 mModel.stopLoader();
1753 app.setLauncher(null);
1754
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001755 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001756 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001758 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001760 mAppWidgetHost = null;
1761
1762 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001763
1764 TextKeyListener.getInstance().release();
1765
Winson Chung81b52252012-08-27 15:34:29 -07001766 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1767 // to prevent leaking Launcher activities on orientation change.
1768 if (mModel != null) {
1769 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1770 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001771
1772 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001773 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001774
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001775 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001776 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1777 mWorkspace.removeAllViews();
1778 mWorkspace = null;
1779 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001780
Michael Jurka2ecf9952012-06-18 12:52:28 -07001781 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 }
1783
Adam Cohena9cf38f2011-05-02 15:36:58 -07001784 public DragController getDragController() {
1785 return mDragController;
1786 }
1787
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 @Override
1789 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001790 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 super.startActivityForResult(intent, requestCode);
1792 }
1793
Winson Chung70d72102011-08-12 11:24:35 -07001794 /**
1795 * Indicates that we want global search for this activity by setting the globalSearch
1796 * argument for {@link #startSearch} to true.
1797 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001799 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001801
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001802 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001803
Karl Rosaen138a0412009-04-23 19:00:21 -07001804 if (initialQuery == null) {
1805 // Use any text typed in the launcher as the initial query
1806 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001807 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 if (appSearchData == null) {
1809 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001810 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 }
Winson Chungadf0c182012-08-23 14:59:07 -07001812 Rect sourceBounds = new Rect();
1813 if (mSearchDropTargetBar != null) {
1814 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1815 }
Romain Guycbb89e42009-06-08 15:52:54 -07001816
Bjorn Bringertc459e522013-06-07 19:36:01 +01001817 startSearch(initialQuery, selectInitialQuery,
1818 appSearchData, sourceBounds);
1819 }
1820
1821 public void startSearch(String initialQuery,
1822 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001823 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001824 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001825 }
1826
1827 /**
1828 * Starts the global search activity. This code is a copied from SearchManager
1829 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001830 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001831 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001832 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001833 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1834 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1835 if (globalSearchActivity == null) {
1836 Log.w(TAG, "No global search activity found.");
1837 return;
1838 }
1839 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1840 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1841 intent.setComponent(globalSearchActivity);
1842 // Make sure that we have a Bundle to put source in
1843 if (appSearchData == null) {
1844 appSearchData = new Bundle();
1845 } else {
1846 appSearchData = new Bundle(appSearchData);
1847 }
1848 // Set source to package name of app that starts global search, if not set already.
1849 if (!appSearchData.containsKey("source")) {
1850 appSearchData.putString("source", getPackageName());
1851 }
1852 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1853 if (!TextUtils.isEmpty(initialQuery)) {
1854 intent.putExtra(SearchManager.QUERY, initialQuery);
1855 }
1856 if (selectInitialQuery) {
1857 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1858 }
1859 intent.setSourceBounds(sourceBounds);
1860 try {
1861 startActivity(intent);
1862 } catch (ActivityNotFoundException ex) {
1863 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1864 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 }
1866
Winson Chung70d72102011-08-12 11:24:35 -07001867 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001868 public boolean onPrepareOptionsMenu(Menu menu) {
1869 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001870 if (!mWorkspace.isInOverviewMode()) {
1871 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001872 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001873 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001874 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001876 @Override
1877 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001878 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001879 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001880 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001881 }
1882
Joe Onorato9c1289c2009-08-17 11:03:03 -04001883 public boolean isWorkspaceLocked() {
1884 return mWorkspaceLoading || mWaitingForResult;
1885 }
1886
Michael Jurka0280c3b2010-09-17 15:00:07 -07001887 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001888 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001889 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001890 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1891 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001892 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001893 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001894 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001895
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001896 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1897 AppWidgetProviderInfo appWidgetInfo) {
1898 if (appWidgetInfo.configure != null) {
1899 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001900
Bjorn Bringert7984c942009-12-09 15:38:25 +00001901 // Launch over to configure widget, if needed
1902 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001903 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001904 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001905 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001907 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001908 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001909 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001910 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001911 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001912 }
1913 }
Romain Guycbb89e42009-06-08 15:52:54 -07001914
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001915 protected void moveToCustomContentScreen(boolean animate) {
1916 mWorkspace.moveToCustomContentScreen(animate);
1917 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001918 /**
1919 * Process a shortcut drop.
1920 *
1921 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001922 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001923 * @param cell The cell it should be added to, optional
1924 * @param position The location on the screen where it was dropped, optional
1925 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001926 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001927 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001928 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001929 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001930 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001931 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001932
1933 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001934 mPendingAddInfo.cellX = cell[0];
1935 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001936 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001937
1938 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1939 createShortcutIntent.setComponent(componentName);
1940 processShortcut(createShortcutIntent);
1941 }
1942
Adam Cohenfbba09b2011-07-18 21:43:05 -07001943 /**
1944 * Process a widget drop.
1945 *
1946 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001947 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001948 * @param cell The cell it should be added to, optional
1949 * @param position The location on the screen where it was dropped, optional
1950 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001952 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001953 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001954 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001957 mPendingAddInfo.minSpanX = info.minSpanX;
1958 mPendingAddInfo.minSpanY = info.minSpanY;
1959
Adam Cohenfbba09b2011-07-18 21:43:05 -07001960 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001961 mPendingAddInfo.cellX = cell[0];
1962 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001963 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001964 if (span != null) {
1965 mPendingAddInfo.spanX = span[0];
1966 mPendingAddInfo.spanY = span[1];
1967 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001968
Adam Cohened66b2b2012-01-23 17:28:51 -08001969 AppWidgetHostView hostView = info.boundWidget;
1970 int appWidgetId;
1971 if (hostView != null) {
1972 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001973 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001974 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001975 // In this case, we either need to start an activity to get permission to bind
1976 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001977 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001978 Bundle options = info.bindOptions;
1979
1980 boolean success = false;
1981 if (options != null) {
1982 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1983 info.componentName, options);
1984 } else {
1985 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1986 info.componentName);
1987 }
1988 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001989 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001990 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001991 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001992 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1993 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1994 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001995 // TODO: we need to make sure that this accounts for the options bundle.
1996 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001997 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1998 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001999 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002000 }
2001
Joe Onoratodeb98af2010-02-19 14:59:39 -08002002 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002003 // Handle case where user selected "Applications"
2004 String applicationName = getResources().getString(R.string.group_applications);
2005 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002006
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002007 if (applicationName != null && applicationName.equals(shortcutName)) {
2008 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2009 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002010
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002011 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2012 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002013 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002014 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002015 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002016 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002017 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 }
2019
Winson Chung24ab2f12010-09-16 14:10:47 -07002020 void processWallpaper(Intent intent) {
2021 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2022 }
2023
Adam Cohendcd297f2013-06-18 13:13:40 -07002024 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002025 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002026 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 folderInfo.title = getText(R.string.folder_name);
2028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002030 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002031 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002032 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033
2034 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002035 FolderIcon newFolder =
2036 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002037 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002038 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002039 // Force measure the new folder icon
2040 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2041 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002042 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 }
Romain Guycbb89e42009-06-08 15:52:54 -07002044
Joe Onorato9c1289c2009-08-17 11:03:03 -04002045 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002046 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002047 }
2048
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002049 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002050 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002052 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002053 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 }
2055
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002056 protected ComponentName getWallpaperPickerComponent() {
2057 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2058 }
2059
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002060 /**
2061 * Registers various content observers. The current implementation registers
2062 * only a favorites observer to keep track of the favorites applications.
2063 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002064 private void registerContentObservers() {
2065 ContentResolver resolver = getContentResolver();
2066 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2067 true, mWidgetObserver);
2068 }
2069
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 @Override
2071 public boolean dispatchKeyEvent(KeyEvent event) {
2072 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2073 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002075 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002076 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002077 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002078 dumpState();
2079 return true;
2080 }
2081 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002082 }
2083 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2084 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002085 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002086 return true;
2087 }
2088 }
2089
2090 return super.dispatchKeyEvent(event);
2091 }
2092
Joe Onorato88ec0992009-11-19 13:16:06 -08002093 @Override
2094 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002095 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002096 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002097 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002098 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002099 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002100 Folder openFolder = mWorkspace.getOpenFolder();
2101 if (openFolder.isEditingName()) {
2102 openFolder.dismissEditingName();
2103 } else {
2104 closeFolder();
2105 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002106 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002107 mWorkspace.exitWidgetResizeMode();
2108
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002109 // Back button is a no-op here, but give at least some feedback for the button press
2110 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002111 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002112 }
2113
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002114 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002115 * Re-listen when widgets are reset.
2116 */
2117 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002118 if (mAppWidgetHost != null) {
2119 mAppWidgetHost.startListening();
2120 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002121 }
2122
2123 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 * Launches the intent referred by the clicked shortcut.
2125 *
2126 * @param v The view representing the clicked shortcut.
2127 */
2128 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002129 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2130 // view has detached (it's possible for this to happen if the view is removed mid touch).
2131 if (v.getWindowToken() == null) {
2132 return;
2133 }
2134
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002135 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002136 return;
2137 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002138
Adam Cohen1697b792013-09-17 19:08:21 -07002139 if (v instanceof Workspace) {
2140 if (mWorkspace.isInOverviewMode()) {
2141 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002142 }
2143 return;
2144 }
2145
2146 if (v instanceof CellLayout) {
2147 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002148 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002149 }
2150 }
2151
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002153 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002154 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002155 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2156 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002157
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002158 // Check for special shortcuts
2159 if (intent.getComponent() != null) {
2160 final String shortcutClass = intent.getComponent().getClassName();
2161
2162 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002163 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002164 return;
2165 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2166 MemoryDumpActivity.startDump(this);
2167 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002168 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2169 toggleShowWeightWatcher();
2170 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002171 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002172 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002173
2174 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002175 int[] pos = new int[2];
2176 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002177 intent.setSourceBounds(new Rect(pos[0], pos[1],
2178 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002179
2180 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002181
Daniel Sandlerff02d492013-08-05 02:12:05 -04002182 mStats.recordLaunch(intent, shortcut);
2183
Michael Jurkaddd62e92011-02-16 17:49:14 -08002184 if (success && v instanceof BubbleTextView) {
2185 mWaitingForResume = (BubbleTextView) v;
2186 mWaitingForResume.setStayPressed(true);
2187 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002189 if (v instanceof FolderIcon) {
2190 FolderIcon fi = (FolderIcon) v;
2191 handleFolderClick(fi);
2192 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002193 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002194 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002195 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002196 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002197 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002198 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002199 }
2200 }
2201
Michael Jurka0e260592010-06-30 17:07:39 -07002202 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002203 return false;
2204 }
2205
Michael Jurkaaf442092010-06-10 17:01:57 -07002206 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002207 * Event handler for the search button
2208 *
2209 * @param v The view that was clicked.
2210 */
2211 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002212 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2213
Amith Yamasania135ba82011-08-09 17:42:01 -07002214 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002215 }
2216
2217 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002218 * Event handler for the voice button
2219 *
2220 * @param v The view that was clicked.
2221 */
2222 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002223 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002224
Bjorn Bringertc459e522013-06-07 19:36:01 +01002225 startVoice();
2226 }
2227
2228 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002229 try {
2230 final SearchManager searchManager =
2231 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2232 ComponentName activityName = searchManager.getGlobalSearchActivity();
2233 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002234 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002235 if (activityName != null) {
2236 intent.setPackage(activityName.getPackageName());
2237 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002238 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002239 } catch (ActivityNotFoundException e) {
2240 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002241 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002242 startActivitySafely(null, intent, "onClickVoiceButton");
2243 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002244 }
2245
2246 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002247 * Event handler for the "grid" button that appears on the home screen, which
2248 * enters all apps mode.
2249 *
2250 * @param v The view that was clicked.
2251 */
2252 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002253 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002254 }
2255
2256 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002257 // Provide the same haptic feedback that the system offers for virtual keys.
2258 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002259 }
2260
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002261 public void onClickAppMarketButton(View v) {
2262 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002263 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002264 } else {
2265 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002266 }
2267 }
2268
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002269 /**
2270 * Called when the user stops interacting with the launcher.
2271 * This implies that the user is now on the homescreen and is not doing housekeeping.
2272 */
2273 protected void onInteractionEnd() {}
2274
2275 /**
2276 * Called when the user starts interacting with the launcher.
2277 * The possible interactions are:
2278 * - open all apps
2279 * - reorder an app shortcut, or a widget
2280 * - open the overview mode.
2281 * This is a good time to stop doing things that only make sense
2282 * when the user is on the homescreen and not doing housekeeping.
2283 */
2284 protected void onInteractionBegin() {}
2285
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002286 void startApplicationDetailsActivity(ComponentName componentName) {
2287 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002288 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2289 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002290 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002291 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002292 }
2293
Michael Jurka1e2f4652013-07-08 18:03:46 -07002294 // returns true if the activity was started
2295 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002296 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002297 // System applications cannot be installed. For now, show a toast explaining that.
2298 // We may give them the option of disabling apps this way.
2299 int messageId = R.string.uninstall_system_app_text;
2300 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002301 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002302 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002303 String packageName = componentName.getPackageName();
2304 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002305 Intent intent = new Intent(
2306 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002307 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2308 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002309 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002310 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002311 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002312 }
2313
Michael Jurka86a720e2012-05-09 11:23:23 -07002314 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002315 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002316
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002318 // Only launch using the new animation if the shortcut has not opted out (this is a
2319 // private contract between launcher and may be ignored in the future).
2320 boolean useLaunchAnimation = (v != null) &&
2321 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2322 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002323 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2324 v.getMeasuredWidth(), v.getMeasuredHeight());
2325
2326 startActivity(intent, opts.toBundle());
2327 } else {
2328 startActivity(intent);
2329 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002330 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002331 } catch (SecurityException e) {
2332 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002333 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002335 "or use the exported attribute for this activity. "
2336 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002337 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002338 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002340
Michael Jurka86a720e2012-05-09 11:23:23 -07002341 boolean startActivitySafely(View v, Intent intent, Object tag) {
2342 boolean success = false;
2343 try {
2344 success = startActivity(v, intent, tag);
2345 } catch (ActivityNotFoundException e) {
2346 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2347 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2348 }
2349 return success;
2350 }
2351
Adam Cohena9cf38f2011-05-02 15:36:58 -07002352 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002353 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002354 Folder openFolder = mWorkspace.getFolderForTag(info);
2355
2356 // If the folder info reports that the associated folder is open, then verify that
2357 // it is actually opened. There have been a few instances where this gets out of sync.
2358 if (info.opened && openFolder == null) {
2359 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002360 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002361 info.opened = false;
2362 }
2363
Adam Cohenfb91f302012-06-11 15:45:18 -07002364 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002365 // Close any open folder
2366 closeFolder();
2367 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002368 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 } else {
2370 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 int folderScreen;
2372 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002373 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 // .. and close it
2375 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002376 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002377 // Close any folder open on the current screen
2378 closeFolder();
2379 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002380 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002381 }
2382 }
2383 }
2384 }
2385
Adam Cohen268c4752012-06-06 17:47:33 -07002386 /**
2387 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2388 * in the DragLayer in the exact absolute location of the original FolderIcon.
2389 */
2390 private void copyFolderIconToImage(FolderIcon fi) {
2391 final int width = fi.getMeasuredWidth();
2392 final int height = fi.getMeasuredHeight();
2393
2394 // Lazy load ImageView, Bitmap and Canvas
2395 if (mFolderIconImageView == null) {
2396 mFolderIconImageView = new ImageView(this);
2397 }
2398 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2399 mFolderIconBitmap.getHeight() != height) {
2400 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2401 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2402 }
2403
2404 DragLayer.LayoutParams lp;
2405 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2406 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2407 } else {
2408 lp = new DragLayer.LayoutParams(width, height);
2409 }
2410
Adam Cohen307fe232012-08-16 17:55:58 -07002411 // The layout from which the folder is being opened may be scaled, adjust the starting
2412 // view size by this scale factor.
2413 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002414 lp.customPosition = true;
2415 lp.x = mRectForFolderAnimation.left;
2416 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002417 lp.width = (int) (scale * width);
2418 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002419
2420 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2421 fi.draw(mFolderIconCanvas);
2422 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002423 if (fi.getFolder() != null) {
2424 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2425 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002426 }
Adam Cohen268c4752012-06-06 17:47:33 -07002427 // Just in case this image view is still in the drag layer from a previous animation,
2428 // we remove it and re-add it.
2429 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2430 mDragLayer.removeView(mFolderIconImageView);
2431 }
2432 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002433 if (fi.getFolder() != null) {
2434 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002435 }
Adam Cohen268c4752012-06-06 17:47:33 -07002436 }
2437
Adam Cohen2801caf2011-05-13 20:57:39 -07002438 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002439 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002440 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2441 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2442 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2443
Adam Cohenc51934b2011-07-26 21:07:43 -07002444 FolderInfo info = (FolderInfo) fi.getTag();
2445 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2446 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002447 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2448 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002449 }
2450
Adam Cohen268c4752012-06-06 17:47:33 -07002451 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2452 copyFolderIconToImage(fi);
2453 fi.setVisibility(View.INVISIBLE);
2454
Michael Jurka2ecf9952012-06-18 12:52:28 -07002455 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002456 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002457 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2458 oa.start();
2459 }
2460
Adam Cohen268c4752012-06-06 17:47:33 -07002461 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002462 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002463 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2464 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2465 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2466
Adam Cohen268c4752012-06-06 17:47:33 -07002467 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002468
Adam Cohen268c4752012-06-06 17:47:33 -07002469 // We remove and re-draw the FolderIcon in-case it has changed
2470 mDragLayer.removeView(mFolderIconImageView);
2471 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002472 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002473 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002474 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002475 oa.addListener(new AnimatorListenerAdapter() {
2476 @Override
2477 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002478 if (cl != null) {
2479 cl.clearFolderLeaveBehind();
2480 // Remove the ImageView copy of the FolderIcon and make the original visible.
2481 mDragLayer.removeView(mFolderIconImageView);
2482 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002483 }
2484 }
2485 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002486 oa.start();
2487 }
2488
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002489 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002490 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002491 * is animated relative to the specified View. If the View is null, no animation
2492 * is played.
2493 *
2494 * @param folderInfo The FolderInfo describing the folder to open.
2495 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002496 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002497 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002498 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002499
Adam Cohena9cf38f2011-05-02 15:36:58 -07002500 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002501
Adam Cohen4554ee12011-08-03 16:13:21 -07002502 // Just verify that the folder hasn't already been added to the DragLayer.
2503 // There was a one-off crash where the folder had a parent already.
2504 if (folder.getParent() == null) {
2505 mDragLayer.addView(folder);
2506 mDragController.addDropTarget((DropTarget) folder);
2507 } else {
2508 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2509 folder.getParent() + ").");
2510 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002511 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002512 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002513
2514 // Notify the accessibility manager that this folder "window" has appeared and occluded
2515 // the workspace items
2516 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2517 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002518 }
2519
2520 public void closeFolder() {
2521 Folder folder = mWorkspace.getOpenFolder();
2522 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002523 if (folder.isEditingName()) {
2524 folder.dismissEditingName();
2525 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002526 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002527
2528 // Dismiss the folder cling
2529 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002530 }
2531 }
2532
2533 void closeFolder(Folder folder) {
2534 folder.getInfo().opened = false;
2535
2536 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2537 if (parent != null) {
2538 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2539 shrinkAndFadeInFolderIcon(fi);
2540 }
2541 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002542
2543 // Notify the accessibility manager that this folder "window" has disappeard and no
2544 // longer occludeds the workspace items
2545 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002546 }
2547
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002548 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002549 if (!isDraggingEnabled()) return false;
2550 if (isWorkspaceLocked()) return false;
2551 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552
Adam Cohen1697b792013-09-17 19:08:21 -07002553 if (v instanceof Workspace) {
2554 if (!mWorkspace.isInOverviewMode()) {
2555 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2556 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2557 mWorkspace.enterOverviewMode();
2558 }
2559 return true;
2560 }
2561
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002562 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002563 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 }
2565
Michael Jurka0280c3b2010-09-17 15:00:07 -07002566 resetAddInfo();
2567 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002568 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002569 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002570 return true;
2571 }
2572
Winson Chung3d503fb2011-07-13 17:25:49 -07002573 // The hotseat touch handling does not go through Workspace, and we always allow long press
2574 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002575 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002576 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2577 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002578 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002579 // User long pressed on empty space
2580 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2581 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2582 // Disabling reordering until we sort out some issues.
2583 if (mWorkspace.isInOverviewMode()) {
2584 mWorkspace.startReordering(v);
2585 } else {
2586 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002587 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002588 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002589 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002590 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002591 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002592 }
2593 }
2594 }
2595 return true;
2596 }
2597
Winson Chung3d503fb2011-07-13 17:25:49 -07002598 boolean isHotseatLayout(View layout) {
2599 return mHotseat != null && layout != null &&
2600 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2601 }
2602 Hotseat getHotseat() {
2603 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002604 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002605 View getOverviewPanel() {
2606 return mOverviewPanel;
2607 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002608 SearchDropTargetBar getSearchBar() {
2609 return mSearchDropTargetBar;
2610 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002611
Winson Chung3d503fb2011-07-13 17:25:49 -07002612 /**
2613 * Returns the CellLayout of the specified container at the specified screen.
2614 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002615 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002616 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2617 if (mHotseat != null) {
2618 return mHotseat.getLayout();
2619 } else {
2620 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002621 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002622 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002623 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002624 }
2625 }
2626
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002627 Workspace getWorkspace() {
2628 return mWorkspace;
2629 }
2630
Daniel Sandler843e8602010-06-07 14:59:01 -04002631 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002632 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002633 }
2634
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002635 /**
2636 * Helper method for the cameraZoomIn/cameraZoomOut animations
2637 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002638 * @param scaleFactor The scale factor used for the zoom
2639 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002640 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002641 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002642 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002644
Craig Mautner360310b2012-10-26 15:13:08 -07002645 private void setWorkspaceBackground(boolean workspace) {
2646 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002647 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002648 }
2649
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002650 void updateWallpaperVisibility(boolean visible) {
2651 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2652 int curflags = getWindow().getAttributes().flags
2653 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2654 if (wpflags != curflags) {
2655 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2656 }
Craig Mautner360310b2012-10-26 15:13:08 -07002657 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002658 }
2659
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002660 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2661 if (v instanceof LauncherTransitionable) {
2662 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2663 }
2664 }
2665
Michael Jurkabed61d22012-02-14 22:51:29 -08002666 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2667 if (v instanceof LauncherTransitionable) {
2668 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2669 }
Winson Chung70442722012-02-10 15:43:22 -08002670
2671 // Update the workspace transition step as well
2672 dispatchOnLauncherTransitionStep(v, 0f);
2673 }
2674
2675 private void dispatchOnLauncherTransitionStep(View v, float t) {
2676 if (v instanceof LauncherTransitionable) {
2677 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2678 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002679 }
2680
2681 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2682 if (v instanceof LauncherTransitionable) {
2683 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2684 }
Winson Chung70442722012-02-10 15:43:22 -08002685
2686 // Update the workspace transition step as well
2687 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002688 }
2689
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002690 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002691 * Things to test when changing the following seven functions.
2692 * - Home from workspace
2693 * - from center screen
2694 * - from other screens
2695 * - Home from all apps
2696 * - from center screen
2697 * - from other screens
2698 * - Back from all apps
2699 * - from center screen
2700 * - from other screens
2701 * - Launch app from workspace and quit
2702 * - with back
2703 * - with home
2704 * - Launch app from all apps and quit
2705 * - with back
2706 * - with home
2707 * - Go to a screen that's not the default, then all
2708 * apps, and launch and app, and go back
2709 * - with back
2710 * -with home
2711 * - On workspace, long press power and go back
2712 * - with back
2713 * - with home
2714 * - On all apps, long press power and go back
2715 * - with back
2716 * - with home
2717 * - On workspace, power off
2718 * - On all apps, power off
2719 * - Launch an app and turn off the screen while in that app
2720 * - Go back with home key
2721 * - Go back with back key TODO: make this not go to workspace
2722 * - From all apps
2723 * - From workspace
2724 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2725 * - From all apps
2726 * - From the center workspace
2727 * - From another workspace
2728 */
2729
2730 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002731 * Zoom the camera out from the workspace to reveal 'toView'.
2732 * Assumes that the view to show is anchored at either the very top or very bottom
2733 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002734 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002735 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002736 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2737 showAppsCustomizeHelper(animated, springLoaded, contentType);
2738 }
2739 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2740 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002741 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002742 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002743 mStateAnimation.cancel();
2744 mStateAnimation = null;
2745 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002746 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002747
Winson Chungf0ea4d32011-06-06 14:27:16 -07002748 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2749 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2750 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002751 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002752 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002753 final int startDelay =
2754 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002755
Michael Jurkab3e22d92011-10-31 15:58:33 -07002756 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002757
Michael Jurkad74c9842011-07-10 12:44:21 -07002758 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002759 Animator workspaceAnim =
2760 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002761 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2762 // Set the content type for the all apps space
2763 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2764 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002765
2766 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002767 toView.setScaleX(scale);
2768 toView.setScaleY(scale);
2769 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2770 scaleAnim.
2771 scaleX(1f).scaleY(1f).
2772 setDuration(duration).
2773 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002774
Winson Chungf0ea4d32011-06-06 14:27:16 -07002775 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002776 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002777 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002778 .ofFloat(toView, "alpha", 0f, 1f)
2779 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002780 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002781 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2782 @Override
2783 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002784 if (animation == null) {
2785 throw new RuntimeException("animation is null");
2786 }
Winson Chung70442722012-02-10 15:43:22 -08002787 float t = (Float) animation.getAnimatedValue();
2788 dispatchOnLauncherTransitionStep(fromView, t);
2789 dispatchOnLauncherTransitionStep(toView, t);
2790 }
2791 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002792
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002793 // toView should appear right at the end of the workspace shrink
2794 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002795 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002796 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002797 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002798
2799 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002800 boolean animationCancelled = false;
2801
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002802 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002803 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002804 // Prepare the position
2805 toView.setTranslationX(0.0f);
2806 toView.setTranslationY(0.0f);
2807 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002808 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002809 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002810 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002811 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002812 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2813 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002814
Winson Chungc7d2b602012-05-16 17:02:20 -07002815 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002816 if (mSearchDropTargetBar != null) {
2817 mSearchDropTargetBar.hideSearchBar(false);
2818 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002819 }
2820
Adam Cohencff6af82011-09-13 14:51:53 -07002821 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002822 public void onAnimationCancel(Animator animation) {
2823 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002824 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002825 });
2826
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002827 if (workspaceAnim != null) {
2828 mStateAnimation.play(workspaceAnim);
2829 }
Michael Jurka1899a362011-11-03 13:50:45 -07002830
2831 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002832
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002833 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2834 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002835
2836 // If any of the objects being animated haven't been measured/laid out
2837 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002838 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002839 (mWorkspace.getMeasuredWidth() == 0) ||
2840 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002841 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002842 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002843
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002844 final AnimatorSet stateAnimation = mStateAnimation;
2845 final Runnable startAnimRunnable = new Runnable() {
2846 public void run() {
2847 // Check that mStateAnimation hasn't changed while
2848 // we waited for a layout/draw pass
2849 if (mStateAnimation != stateAnimation)
2850 return;
2851 setPivotsForZoom(toView, scale);
2852 dispatchOnLauncherTransitionStart(fromView, animated, false);
2853 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002854 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002855 }
2856 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002858 final ViewTreeObserver observer = toView.getViewTreeObserver();
2859 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2860 public void onGlobalLayout() {
2861 startAnimRunnable.run();
2862 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2863 }
2864 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002865 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002866 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002867 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002868 } else {
2869 toView.setTranslationX(0.0f);
2870 toView.setTranslationY(0.0f);
2871 toView.setScaleX(1.0f);
2872 toView.setScaleY(1.0f);
2873 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002874 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002875
Daniel Sandlere4f98912013-06-25 15:13:26 -04002876 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002877 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002878 if (mSearchDropTargetBar != null) {
2879 mSearchDropTargetBar.hideSearchBar(false);
2880 }
Michael Jurkaabded662011-03-04 12:06:57 -08002881 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002882 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002883 dispatchOnLauncherTransitionStart(fromView, animated, false);
2884 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002885 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002886 dispatchOnLauncherTransitionStart(toView, animated, false);
2887 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002888 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002889 }
2890
2891 /**
2892 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002893 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002894 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002895 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002896 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2897 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002898
Michael Jurkab3e22d92011-10-31 15:58:33 -07002899 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002900 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002901 mStateAnimation.cancel();
2902 mStateAnimation = null;
2903 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002904 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002905
Winson Chungf0ea4d32011-06-06 14:27:16 -07002906 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002907 final int fadeOutDuration =
2908 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002909 final float scaleFactor = (float)
2910 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2911 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002912 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002913 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002914 if (toState == State.WORKSPACE) {
2915 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2916 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002917 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002918 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2919 workspaceAnim = mWorkspace.getChangeStateAnimation(
2920 Workspace.State.SPRING_LOADED, animated);
2921 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002922
Michael Jurkab3e22d92011-10-31 15:58:33 -07002923 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002924 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002925 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002926 final LauncherViewPropertyAnimator scaleAnim =
2927 new LauncherViewPropertyAnimator(fromView);
2928 scaleAnim.
2929 scaleX(scaleFactor).scaleY(scaleFactor).
2930 setDuration(duration).
2931 setInterpolator(new Workspace.ZoomInInterpolator());
2932
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002933 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002934 .ofFloat(fromView, "alpha", 1f, 0f)
2935 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002936 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002937 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2938 @Override
2939 public void onAnimationUpdate(ValueAnimator animation) {
2940 float t = 1f - (Float) animation.getAnimatedValue();
2941 dispatchOnLauncherTransitionStep(fromView, t);
2942 dispatchOnLauncherTransitionStep(toView, t);
2943 }
2944 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002945
Michael Jurka2ecf9952012-06-18 12:52:28 -07002946 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002947
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002948 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2949 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002950 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002951
2952 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002953 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002954 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002955 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002956 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2957 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002958 if (onCompleteRunnable != null) {
2959 onCompleteRunnable.run();
2960 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002961 mAppsCustomizeContent.updateCurrentPageScroll();
2962 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002963 }
2964 });
2965
Winson Chungf0ea4d32011-06-06 14:27:16 -07002966 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002967 if (workspaceAnim != null) {
2968 mStateAnimation.play(workspaceAnim);
2969 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002970 dispatchOnLauncherTransitionStart(fromView, animated, true);
2971 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002972 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002973 } else {
2974 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002975 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002976 dispatchOnLauncherTransitionStart(fromView, animated, true);
2977 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002978 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002979 dispatchOnLauncherTransitionStart(toView, animated, true);
2980 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002981 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002982 }
2983
Michael Jurkae326f182011-11-21 14:05:46 -08002984 @Override
2985 public void onTrimMemory(int level) {
2986 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002987 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002988 mAppsCustomizeTabHost.onTrimMemory();
2989 }
2990 }
2991
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002992 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002993 showWorkspace(animated, null);
2994 }
2995
2996 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002997 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07002998 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002999 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003000 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003001
Winson Chungc7d2b602012-05-16 17:02:20 -07003002 // Show the search bar (only animate if we were showing the drop target bar in spring
3003 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003004 if (mSearchDropTargetBar != null) {
3005 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3006 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003007
Michael Jurkab3e22d92011-10-31 15:58:33 -07003008 // Set focus to the AppsCustomize button
3009 if (mAllAppsButton != null) {
3010 mAllAppsButton.requestFocus();
3011 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003012 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003013
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003014 // Change the state *after* we've called all the transition code
3015 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003016
Winson Chung5fb63472011-02-02 17:03:37 -08003017 // Resume the auto-advance of widgets
3018 mUserPresent = true;
3019 updateRunning();
3020
alanv1d4fde62012-10-17 13:15:47 -07003021 // Send an accessibility event to announce the context change
3022 getWindow().getDecorView()
3023 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003024
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003025 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003026 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003027 }
3028
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003029 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003030 }
3031
Winson Chungc58497e2013-09-03 17:48:37 -07003032 void showAllApps(boolean animated,
3033 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003034 if (mState != State.WORKSPACE) return;
3035
Winson Chungc58497e2013-09-03 17:48:37 -07003036 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003037 mAppsCustomizeTabHost.requestFocus();
3038
Michael Jurkab3e22d92011-10-31 15:58:33 -07003039 // Change the state *after* we've called all the transition code
3040 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003041 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003042
3043 // Pause the auto-advance of widgets until we are out of AllApps
3044 mUserPresent = false;
3045 updateRunning();
3046 closeFolder();
3047
3048 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003049 getWindow().getDecorView()
3050 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051 }
3052
Adam Cohen7777d962011-08-18 18:58:38 -07003053 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003054 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003055 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003056 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003057 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003058 }
Adam Cohen7777d962011-08-18 18:58:38 -07003059
Adam Cohened66b2b2012-01-23 17:28:51 -08003060 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3061 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003062 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3063
Winson Chunge7a03942011-08-05 15:05:12 -07003064 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003065 @Override
3066 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003067 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003068 // Before we show workspace, hide all apps again because
3069 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3070 // clean up our state transition functions
3071 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003072 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003073 } else {
3074 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003075 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003076 }
3077 }, (extendedDelay ?
3078 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3079 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3080 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003081
Michael Jurkad3ef3062010-11-23 16:23:58 -08003082 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003083 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003084 final boolean animated = true;
3085 final boolean springLoaded = true;
3086 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003087 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003088 }
3089 // Otherwise, we are not in spring loaded mode, so don't do anything.
3090 }
3091
Michael Jurkab3e22d92011-10-31 15:58:33 -07003092 void lockAllApps() {
3093 // TODO
3094 }
3095
3096 void unlockAllApps() {
3097 // TODO
3098 }
3099
Winson Chungf0ea4d32011-06-06 14:27:16 -07003100 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003101 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003102 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003103 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003104 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003105 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003106 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003107 int duration = 0;
3108 if (mSearchDropTargetBar != null) {
3109 duration = mSearchDropTargetBar.getTransitionInDuration();
3110 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003111 mHotseat.animate().alpha(1f).setDuration(duration);
3112 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003113 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003114 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003115 }
3116 }
3117 }
3118
3119 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003120 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003121 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003122 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003123 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003124 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003125 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003126 int duration = 0;
3127 if (mSearchDropTargetBar != null) {
3128 duration = mSearchDropTargetBar.getTransitionOutDuration();
3129 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003130 mHotseat.animate().alpha(0f).setDuration(duration);
3131 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003132 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003133 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003134 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003135 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003136 }
3137
Patrick Dubroy5f445422011-02-18 14:35:21 -08003138 /**
3139 * Add an item from all apps or customize onto the given workspace screen.
3140 * If layout is null, add to the current screen.
3141 */
3142 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003143 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003144 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003145 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003146 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003147
Winson Chungdff8ebb2011-09-08 17:25:31 -07003148 /** Maps the current orientation to an index for referencing orientation correct global icons */
3149 private int getCurrentOrientationIndexForGlobalIcons() {
3150 // default - 0, landscape - 1
3151 switch (getResources().getConfiguration().orientation) {
3152 case Configuration.ORIENTATION_LANDSCAPE:
3153 return 1;
3154 default:
3155 return 0;
3156 }
3157 }
3158
Michael Jurkaae65ee32012-04-30 11:45:54 -07003159 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003160 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003161 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003162 // Look for the toolbar icon specified in the activity meta-data
3163 Bundle metaData = packageManager.getActivityInfo(
3164 activityName, PackageManager.GET_META_DATA).metaData;
3165 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003166 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003167 if (iconResId != 0) {
3168 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003169 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003170 }
3171 }
3172 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003173 // This can happen if the activity defines an invalid drawable
3174 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3175 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003176 } catch (Resources.NotFoundException nfe) {
3177 // This can happen if the activity defines an invalid drawable
3178 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3179 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003180 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003181 return null;
3182 }
3183
3184 // if successful in getting icon, return it; otherwise, set button to use default drawable
3185 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003186 int buttonId, ComponentName activityName, int fallbackDrawableId,
3187 String toolbarResourceName) {
3188 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003189 Resources r = getResources();
3190 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3191 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003192
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003193 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003194 // If we were unable to find the icon via the meta-data, use a generic one
3195 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003196 toolbarIcon = r.getDrawable(fallbackDrawableId);
3197 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003198 if (button != null) {
3199 button.setCompoundDrawables(toolbarIcon, null, null, null);
3200 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003201 return null;
3202 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003203 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003204 if (button != null) {
3205 button.setCompoundDrawables(toolbarIcon, null, null, null);
3206 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003207 return toolbarIcon.getConstantState();
3208 }
3209 }
3210
3211 // if successful in getting icon, return it; otherwise, set button to use default drawable
3212 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003213 int buttonId, ComponentName activityName, int fallbackDrawableId,
3214 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003215 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003216 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003217
Michael Jurka19e0fc52011-07-22 18:00:21 -07003218 if (button != null) {
3219 // If we were unable to find the icon via the meta-data, use a
3220 // generic one
3221 if (toolbarIcon == null) {
3222 button.setImageResource(fallbackDrawableId);
3223 } else {
3224 button.setImageDrawable(toolbarIcon);
3225 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003226 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003227
3228 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3229
Michael Jurka0423dcf2010-10-05 14:56:18 -07003230 }
3231
Winson Chung1b884092012-06-08 17:13:02 -07003232 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003233 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003234 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003235 }
3236
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003237 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003238 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003239 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003240 }
3241
Winson Chungbb185bd2011-11-21 12:31:42 -08003242 private void invalidatePressedFocusedStates(View container, View button) {
3243 if (container instanceof HolographicLinearLayout) {
3244 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3245 layout.invalidatePressedFocusedStates();
3246 } else if (button instanceof HolographicImageView) {
3247 HolographicImageView view = (HolographicImageView) button;
3248 view.invalidatePressedFocusedStates();
3249 }
3250 }
3251
Cristina Stancu476493b2013-08-07 17:20:14 +01003252 public View getQsbBar() {
3253 if (mQsbBar == null) {
3254 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3255 }
3256 return mQsbBar;
3257 }
3258
3259 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003260 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003261 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003262 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003263 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003264
Winson Chung1cad91e2011-05-25 17:41:01 -07003265 final SearchManager searchManager =
3266 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3267 ComponentName activityName = searchManager.getGlobalSearchActivity();
3268 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003269 int coi = getCurrentOrientationIndexForGlobalIcons();
3270 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003271 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3272 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3273 if (sGlobalSearchIcon[coi] == null) {
3274 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3275 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3276 TOOLBAR_ICON_METADATA_NAME);
3277 }
3278
Winson Chungc51db6a2011-10-05 11:44:49 -07003279 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3280 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003281 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003282 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003283 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003284 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003285 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3286 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003287 if (searchButton != null) searchButton.setVisibility(View.GONE);
3288 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003289 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003290 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003291 }
3292 }
3293
Cristina Stancu476493b2013-08-07 17:20:14 +01003294 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003295 final View searchButtonContainer = findViewById(R.id.search_button_container);
3296 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003297 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003298 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003299 }
3300
Cristina Stancu476493b2013-08-07 17:20:14 +01003301 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003302 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003303 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003304
Winson Chungc51db6a2011-10-05 11:44:49 -07003305 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003306 final SearchManager searchManager =
3307 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3308 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3309
3310 ComponentName activityName = null;
3311 if (globalSearchActivity != null) {
3312 // Check if the global search activity handles voice search
3313 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3314 intent.setPackage(globalSearchActivity.getPackageName());
3315 activityName = intent.resolveActivity(getPackageManager());
3316 }
3317
3318 if (activityName == null) {
3319 // Fallback: check if an activity other than the global search activity
3320 // resolves this
3321 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3322 activityName = intent.resolveActivity(getPackageManager());
3323 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003324 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003325 int coi = getCurrentOrientationIndexForGlobalIcons();
3326 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003327 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3328 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3329 if (sVoiceSearchIcon[coi] == null) {
3330 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3331 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3332 TOOLBAR_ICON_METADATA_NAME);
3333 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003335 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003336 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003337 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003338 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003339 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003340 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003341 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003342 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003343 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003344 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003345 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003346
Cristina Stancu476493b2013-08-07 17:20:14 +01003347 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003348 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3349 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003350 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003351 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003352 }
3353
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003354 public void setVoiceButtonProxyVisible(boolean visible) {
3355 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3356 if (voiceButtonProxy != null) {
3357 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3358 }
3359 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003360 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003361 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003362 */
3363 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003364 final View marketButton = findViewById(R.id.market_button);
3365 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3366 // Find the app market activity by resolving an intent.
3367 // (If multiple app markets are installed, it will return the ResolverActivity.)
3368 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003369 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003370 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003371 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003372 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003373 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3374 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003375 marketButton.setVisibility(View.VISIBLE);
3376 } else {
3377 // We should hide and disable the view so that we don't try and restore the visibility
3378 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3379 marketButton.setVisibility(View.GONE);
3380 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003381 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003382 }
3383
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003384 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003385 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3386 Resources r = getResources();
3387 Drawable marketIconDrawable = d.newDrawable(r);
3388 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3389 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3390 marketIconDrawable.setBounds(0, 0, w, h);
3391
3392 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003393 }
3394
Michael Jurkad7c28052012-04-27 15:43:36 -07003395 @Override
3396 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003397 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003398 final List<CharSequence> text = event.getText();
3399 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003400 // Populate event with a fake title based on the current state.
3401 if (mState == State.APPS_CUSTOMIZE) {
3402 text.add(getString(R.string.all_apps_button_label));
3403 } else {
3404 text.add(getString(R.string.all_apps_home_button_label));
3405 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003406 return result;
3407 }
3408
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003409 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003410 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003411 */
3412 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3413 @Override
3414 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003415 closeSystemDialogs();
3416 }
3417 }
3418
3419 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003420 * Receives notifications whenever the appwidgets are reset.
3421 */
3422 private class AppWidgetResetObserver extends ContentObserver {
3423 public AppWidgetResetObserver() {
3424 super(new Handler());
3425 }
3426
3427 @Override
3428 public void onChange(boolean selfChange) {
3429 onAppWidgetReset();
3430 }
3431 }
3432
3433 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003434 * If the activity is currently paused, signal that we need to run the passed Runnable
3435 * in onResume.
3436 *
3437 * This needs to be called from incoming places where resources might have been loaded
3438 * while we are paused. That is becaues the Configuration might be wrong
3439 * when we're not running, and if it comes back to what it was when we
3440 * were paused, we are not restarted.
3441 *
3442 * Implementation of the method from LauncherModel.Callbacks.
3443 *
3444 * @return true if we are currently paused. The caller might be able to
3445 * skip some work in that case since we will come back again.
3446 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003447 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003448 if (mPaused) {
3449 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003450 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003451 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003452 }
3453 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003454 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003455 return true;
3456 } else {
3457 return false;
3458 }
3459 }
3460
Michael Jurkac402cd92013-05-20 15:49:32 +02003461 private boolean waitUntilResume(Runnable run) {
3462 return waitUntilResume(run, false);
3463 }
3464
Michael Jurka1e2f4652013-07-08 18:03:46 -07003465 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003466 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003467 }
3468
Michael Jurka7607c2f2013-04-03 14:33:19 -07003469 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003470 * If the activity is currently paused, signal that we need to re-run the loader
3471 * in onResume.
3472 *
3473 * This needs to be called from incoming places where resources might have been loaded
3474 * while we are paused. That is becaues the Configuration might be wrong
3475 * when we're not running, and if it comes back to what it was when we
3476 * were paused, we are not restarted.
3477 *
3478 * Implementation of the method from LauncherModel.Callbacks.
3479 *
3480 * @return true if we are currently paused. The caller might be able to
3481 * skip some work in that case since we will come back again.
3482 */
3483 public boolean setLoadOnResume() {
3484 if (mPaused) {
3485 Log.i(TAG, "setLoadOnResume");
3486 mOnResumeNeedsLoad = true;
3487 return true;
3488 } else {
3489 return false;
3490 }
3491 }
3492
3493 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003494 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003495 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003496 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003497 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003498 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003499 } else {
3500 return SCREEN_COUNT / 2;
3501 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003502 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003503
Joe Onorato9c1289c2009-08-17 11:03:03 -04003504 /**
3505 * Refreshes the shortcuts shown on the workspace.
3506 *
3507 * Implementation of the method from LauncherModel.Callbacks.
3508 */
3509 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003510 // If we're starting binding all over again, clear any bind calls we'd postponed in
3511 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3512 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003513 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003514
Winson Chungd64d1762013-08-20 14:37:16 -07003515 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003516 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003517 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003518
Michael Jurka05bf6442011-11-30 20:28:53 -08003519 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003520 if (mHotseat != null) {
3521 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003522 }
3523 }
3524
Adam Cohendcd297f2013-06-18 13:13:40 -07003525 @Override
3526 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003527 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003528
Adam Cohen5084cba2013-09-03 12:01:16 -07003529 // If there are no screens, we need to have an empty screen
3530 if (orderedScreenIds.size() == 0) {
3531 mWorkspace.addExtraEmptyScreen();
3532 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003533
3534 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003535 // setCurrentPage() so ensure that all pages are added before calling this).
3536 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003537 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3538 mWorkspace.createCustomContentPage();
3539 }
Winson Chung64359a52013-07-08 17:17:08 -07003540 }
3541
3542 @Override
3543 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003544 int count = orderedScreenIds.size();
3545 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003546 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003547 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003548 }
3549
Adam Cohen39a06042013-07-19 14:30:12 -07003550 private boolean shouldShowWeightWatcher() {
3551 String spKey = LauncherAppState.getSharedPreferencesKey();
3552 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003553 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003554
3555 return show;
3556 }
3557
Adam Cohen4caf2982013-08-20 18:54:31 -07003558 private boolean emailSent() {
3559 String spKey = LauncherAppState.getSharedPreferencesKey();
3560 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3561 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3562 return show;
3563 }
3564
3565 private void setEmailSent(boolean sent) {
3566 String spKey = LauncherAppState.getSharedPreferencesKey();
3567 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3568
3569 SharedPreferences.Editor editor = sp.edit();
3570 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3571 editor.commit();
3572 }
3573
Adam Cohen39a06042013-07-19 14:30:12 -07003574 private void toggleShowWeightWatcher() {
3575 String spKey = LauncherAppState.getSharedPreferencesKey();
3576 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3577 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3578
3579 show = !show;
3580
3581 SharedPreferences.Editor editor = sp.edit();
3582 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3583 editor.commit();
3584
3585 if (mWeightWatcher != null) {
3586 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3587 }
3588 }
3589
Winson Chungd64d1762013-08-20 14:37:16 -07003590 public void bindAppsAdded(final ArrayList<Long> newScreens,
3591 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003592 final ArrayList<ItemInfo> addAnimated,
3593 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003594 Runnable r = new Runnable() {
3595 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003596 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003597 }
3598 };
3599 if (waitUntilResume(r)) {
3600 return;
3601 }
3602
Winson Chungd64d1762013-08-20 14:37:16 -07003603 // Add the new screens
3604 bindAddScreens(newScreens);
3605
3606 // We add the items without animation on non-visible pages, and with
3607 // animations on the new page (which we will try and snap to).
3608 if (!addNotAnimated.isEmpty()) {
3609 bindItems(addNotAnimated, 0,
3610 addNotAnimated.size(), false);
3611 }
3612 if (!addAnimated.isEmpty()) {
3613 bindItems(addAnimated, 0,
3614 addAnimated.size(), true);
3615 }
Winson Chungc58497e2013-09-03 17:48:37 -07003616
3617 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3618 addedApps != null && mAppsCustomizeContent != null) {
3619 mAppsCustomizeContent.addApps(addedApps);
3620 }
Winson Chungd64d1762013-08-20 14:37:16 -07003621 }
3622
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003623 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003624 * Bind the items start-end from the list.
3625 *
3626 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003627 */
Winson Chung64359a52013-07-08 17:17:08 -07003628 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3629 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003630 Runnable r = new Runnable() {
3631 public void run() {
3632 bindItems(shortcuts, start, end, forceAnimateIcons);
3633 }
3634 };
3635 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003636 return;
3637 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003638
Winson Chungf0c6ae02012-03-21 16:10:31 -07003639 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003640 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3641 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003642 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003643 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003644 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003645 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003646 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003647
3648 // Short circuit if we are loading dock items for a configuration which has no dock
3649 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3650 mHotseat == null) {
3651 continue;
3652 }
3653
Joe Onorato9c1289c2009-08-17 11:03:03 -04003654 switch (item.itemType) {
3655 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3656 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003657 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003658 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003659
Winson Chung64359a52013-07-08 17:17:08 -07003660 /*
3661 * TODO: FIX collision case
3662 */
Winson Chungce376632013-07-11 16:12:41 -07003663 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3664 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3665 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3666 throw new RuntimeException("OCCUPIED");
3667 }
Winson Chung64359a52013-07-08 17:17:08 -07003668 }
3669
Adam Cohendcd297f2013-06-18 13:13:40 -07003670 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3671 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003672 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003673 // Animate all the applications up now
3674 shortcut.setAlpha(0f);
3675 shortcut.setScaleX(0f);
3676 shortcut.setScaleY(0f);
3677 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003678 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003679 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003680 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003681 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003682 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003683 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003684 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003685 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3686 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003687 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003688 default:
3689 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003690 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003691 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003692
Winson Chung997a9232013-07-24 15:33:46 -07003693 if (animateIcons) {
3694 // Animate to the correct page
3695 if (newShortcutsScreenId > -1) {
3696 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3697 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3698 if (newShortcutsScreenId != currentScreenId) {
3699 mWorkspace.snapToPage(newScreenIndex);
3700 }
3701 }
3702
Winson Chung64359a52013-07-08 17:17:08 -07003703 // We post the animation slightly delayed to prevent slowdowns when we are loading
3704 // right after we return to launcher.
3705 mWorkspace.postDelayed(new Runnable() {
3706 public void run() {
3707 anim.playTogether(bounceAnims);
3708 anim.start();
3709 }
3710 }, NEW_APPS_ANIMATION_DELAY);
3711 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003712 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003713 }
3714
Joe Onorato9c1289c2009-08-17 11:03:03 -04003715 /**
3716 * Implementation of the method from LauncherModel.Callbacks.
3717 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003718 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003719 Runnable r = new Runnable() {
3720 public void run() {
3721 bindFolders(folders);
3722 }
3723 };
3724 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003725 return;
3726 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003727 sFolders.clear();
3728 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003729 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003730
3731 /**
3732 * Add the views for a widget to the workspace.
3733 *
3734 * Implementation of the method from LauncherModel.Callbacks.
3735 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003736 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003737 Runnable r = new Runnable() {
3738 public void run() {
3739 bindAppWidget(item);
3740 }
3741 };
3742 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003743 return;
3744 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003745
Daniel Sandler843e8602010-06-07 14:59:01 -04003746 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3747 if (DEBUG_WIDGETS) {
3748 Log.d(TAG, "bindAppWidget: " + item);
3749 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003750 final Workspace workspace = mWorkspace;
3751
3752 final int appWidgetId = item.appWidgetId;
3753 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003754 if (DEBUG_WIDGETS) {
3755 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3756 }
3757
Joe Onorato9c1289c2009-08-17 11:03:03 -04003758 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3759
Joe Onorato9c1289c2009-08-17 11:03:03 -04003760 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003761 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003762
Adam Cohendcd297f2013-06-18 13:13:40 -07003763 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003764 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003765 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3766
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767 workspace.requestLayout();
3768
Daniel Sandler843e8602010-06-07 14:59:01 -04003769 if (DEBUG_WIDGETS) {
3770 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3771 + (SystemClock.uptimeMillis()-start) + "ms");
3772 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003773 }
3774
Adam Cohen1462de32012-07-24 22:34:36 -07003775 public void onPageBoundSynchronously(int page) {
3776 mSynchronouslyBoundPages.add(page);
3777 }
3778
Joe Onorato9c1289c2009-08-17 11:03:03 -04003779 /**
3780 * Callback saying that there aren't any more items to bind.
3781 *
3782 * Implementation of the method from LauncherModel.Callbacks.
3783 */
Adam Cohene25af792013-06-06 23:08:25 -07003784 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003785 Runnable r = new Runnable() {
3786 public void run() {
3787 finishBindingItems(upgradePath);
3788 }
3789 };
3790 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003791 return;
3792 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003793 if (mSavedState != null) {
3794 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003795 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 mSavedState = null;
3798 }
3799
Adam Cohen1462de32012-07-24 22:34:36 -07003800 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003801
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003802 // If we received the result of any pending adds while the loader was running (e.g. the
3803 // widget configuration forced an orientation change), process them now.
3804 for (int i = 0; i < sPendingAddList.size(); i++) {
3805 completeAdd(sPendingAddList.get(i));
3806 }
3807 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003808
Winson Chungc51db6a2011-10-05 11:44:49 -07003809 // Update the market app icon as necessary (the other icons will be managed in response to
3810 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003811 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003812
Winson Chungf0c6ae02012-03-21 16:10:31 -07003813 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003814 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003815 mWorkspace.getUniqueComponents(true, null);
3816 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003817 }
Adam Cohen99894d92013-06-14 11:22:59 -07003818
Adam Cohen66a01fd2013-06-11 12:48:00 -07003819 mWorkspace.post(new Runnable() {
3820 @Override
3821 public void run() {
3822 onFinishBindingItems();
3823 }
3824 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003825 }
3826
Winson Chunga0b7e862013-09-05 16:03:15 -07003827 public boolean isAllAppsButtonRank(int rank) {
3828 if (mHotseat != null) {
3829 return mHotseat.isAllAppsButtonRank(rank);
3830 }
3831 return false;
3832 }
3833
Winson Chunga2413752012-04-03 14:22:34 -07003834 private boolean canRunNewAppsAnimation() {
3835 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3836 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3837 }
3838
Winson Chungc9168342013-06-26 14:54:55 -07003839 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3840 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3841 PropertyValuesHolder.ofFloat("alpha", 1f),
3842 PropertyValuesHolder.ofFloat("scaleX", 1f),
3843 PropertyValuesHolder.ofFloat("scaleY", 1f));
3844 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3845 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3846 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3847 return bounceAnim;
3848 }
3849
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003850 @Override
3851 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003852 boolean searchVisible = updateGlobalSearchIcon();
3853 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003854 if (mSearchDropTargetBar != null) {
3855 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3856 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003857 }
3858
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003859 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003860 * Add the icons for all apps.
3861 *
3862 * Implementation of the method from LauncherModel.Callbacks.
3863 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003864 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003865 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3866 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3867 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3868 getHotseat().addAllAppsFolder(mIconCache, apps,
3869 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3870 }
3871 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003872 }
Winson Chungc58497e2013-09-03 17:48:37 -07003873 } else {
3874 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3875 mAppsCustomizeContent != null) {
3876 mAppsCustomizeContent.setApps(apps);
3877 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003878 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003879 }
3880
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003881 @Override
3882 public boolean shouldShowApp(ResolveInfo app) {
3883 return true;
3884 }
3885
Joe Onorato9c1289c2009-08-17 11:03:03 -04003886 /**
3887 * A package was updated.
3888 *
3889 * Implementation of the method from LauncherModel.Callbacks.
3890 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003891 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003892 Runnable r = new Runnable() {
3893 public void run() {
3894 bindAppsUpdated(apps);
3895 }
3896 };
3897 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003898 return;
3899 }
3900
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003901 if (mWorkspace != null) {
3902 mWorkspace.updateShortcuts(apps);
3903 }
Winson Chungc58497e2013-09-03 17:48:37 -07003904
3905 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3906 mAppsCustomizeContent != null) {
3907 mAppsCustomizeContent.updateApps(apps);
3908 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003909 }
3910
3911 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003912 * A package was uninstalled. We take both the super set of packageNames
3913 * in addition to specific applications to remove, the reason being that
3914 * this can be called when a package is updated as well. In that scenario,
3915 * we only remove specific components from the workspace, where as
3916 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917 *
3918 * Implementation of the method from LauncherModel.Callbacks.
3919 */
Winson Chung83892cc2013-05-01 16:53:33 -07003920 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003921 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003922 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003923 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003924 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003925 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003926 }
Winson Chungd64d1762013-08-20 14:37:16 -07003927 };
3928 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003929 return;
3930 }
3931
Winson Chung64359a52013-07-08 17:17:08 -07003932 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003933 mWorkspace.removeItemsByPackageName(packageNames);
3934 } else {
3935 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003936 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003937
Winson Chunga1820962011-10-03 16:31:06 -07003938 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003939 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003940
3941 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3942 mAppsCustomizeContent != null) {
3943 mAppsCustomizeContent.removeApps(appInfos);
3944 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003945 }
Joe Onoratobe386092009-11-17 17:32:16 -08003946
3947 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003948 * A number of packages were updated.
3949 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003950 private ArrayList<Object> mWidgetsAndShortcuts;
3951 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003952 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003953 bindPackagesUpdated(mWidgetsAndShortcuts);
3954 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003955 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003956 };
3957
3958 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3959 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3960 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003961 return;
3962 }
3963
Winson Chung64359a52013-07-08 17:17:08 -07003964 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003965 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3966 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003967 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003968 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003969 }
3970
Winson Chung400438b2011-01-16 17:53:48 -08003971 private int mapConfigurationOriActivityInfoOri(int configOri) {
3972 final Display d = getWindowManager().getDefaultDisplay();
3973 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3974 switch (d.getRotation()) {
3975 case Surface.ROTATION_0:
3976 case Surface.ROTATION_180:
3977 // We are currently in the same basic orientation as the natural orientation
3978 naturalOri = configOri;
3979 break;
3980 case Surface.ROTATION_90:
3981 case Surface.ROTATION_270:
3982 // We are currently in the other basic orientation to the natural orientation
3983 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3984 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3985 break;
3986 }
3987
3988 int[] oriMap = {
3989 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3990 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3991 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3992 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3993 };
3994 // Since the map starts at portrait, we need to offset if this device's natural orientation
3995 // is landscape.
3996 int indexOffset = 0;
3997 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3998 indexOffset = 1;
3999 }
4000 return oriMap[(d.getRotation() + indexOffset) % 4];
4001 }
Adam Cohen446e9402011-09-15 18:21:21 -07004002
Winson Chung4b919f82012-05-01 10:44:08 -07004003 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004004 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004005 getResources().getBoolean(R.bool.allow_rotation);
4006 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004007 }
Winson Chung4b919f82012-05-01 10:44:08 -07004008 public void lockScreenOrientation() {
4009 if (isRotationEnabled()) {
4010 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4011 .getConfiguration().orientation));
4012 }
4013 }
4014 public void unlockScreenOrientation(boolean immediate) {
4015 if (isRotationEnabled()) {
4016 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004017 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004018 } else {
4019 mHandler.postDelayed(new Runnable() {
4020 public void run() {
4021 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4022 }
4023 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004024 }
Winson Chung4b919f82012-05-01 10:44:08 -07004025 }
Winson Chung400438b2011-01-16 17:53:48 -08004026 }
4027
Winson Chung82f55532011-08-09 14:14:23 -07004028 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004029 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004030 if (DISABLE_CLINGS) {
4031 return false;
4032 }
4033
Brett Chabot2a9e2282011-08-23 15:03:13 -07004034 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004035 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004036
Michael Jurkae233a8b2013-03-19 13:49:20 +01004037 // Restricted secondary users (child mode) will potentially have very few apps
4038 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004039// boolean supportsLimitedUsers =
4040// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4041// Account[] accounts = AccountManager.get(this).getAccounts();
4042// if (supportsLimitedUsers && accounts.length == 0) {
4043// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4044// Bundle restrictions = um.getUserRestrictions();
4045// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4046// return false;
4047// }
4048// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004049 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004050 }
Michael Jurka22143132012-10-04 17:42:38 +02004051
Winson Chungaf40f202013-09-18 18:26:31 -07004052 private Cling initCling(int clingId, int[] positionData, boolean animate,
4053 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004054 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004055 if (cling != null) {
4056 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004057 cling.show(animate, SHOW_CLING_DURATION);
4058
4059 if (dimNavBarVisibilty) {
4060 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4061 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004062 }
4063 }
4064 return cling;
4065 }
Michael Jurka22143132012-10-04 17:42:38 +02004066
Winson Chungaf40f202013-09-18 18:26:31 -07004067 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4068 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004069 // To catch cases where siblings of top-level views are made invisible, just check whether
4070 // the cling is directly set to GONE before dismissing it.
4071 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004072 final Runnable cleanUpClingCb = new Runnable() {
4073 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004074 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004075 /*
Winson Chung46353de2012-02-16 14:05:10 -08004076 // We should update the shared preferences on a background thread
4077 new Thread("dismissClingThread") {
4078 public void run() {
4079 SharedPreferences.Editor editor = mSharedPrefs.edit();
4080 editor.putBoolean(flag, true);
4081 editor.commit();
4082 }
4083 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004084 */
4085 if (postAnimationCb != null) {
4086 postAnimationCb.run();
4087 }
4088 }
4089 };
4090 if (duration <= 0) {
4091 cleanUpClingCb.run();
4092 } else {
4093 cling.hide(duration, cleanUpClingCb);
4094 }
Michael Jurka22143132012-10-04 17:42:38 +02004095 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004096
4097 if (restoreNavBarVisibilty) {
4098 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4099 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4100 }
Winson Chung82f55532011-08-09 14:14:23 -07004101 }
4102 }
Michael Jurka22143132012-10-04 17:42:38 +02004103
Winson Chung9d9d74f2011-09-19 11:49:12 -07004104 private void removeCling(int id) {
4105 final View cling = findViewById(id);
4106 if (cling != null) {
4107 final ViewGroup parent = (ViewGroup) cling.getParent();
4108 parent.post(new Runnable() {
4109 @Override
4110 public void run() {
4111 parent.removeView(cling);
4112 }
4113 });
Michael Jurka22143132012-10-04 17:42:38 +02004114 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004115 }
4116 }
Michael Jurka974c3862012-05-22 22:00:31 -07004117
4118 private boolean skipCustomClingIfNoAccounts() {
4119 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4120 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4121 if (customCling) {
4122 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004123 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004124 Account[] accounts = am.getAccountsByType("com.google");
4125 return accounts.length == 0;
4126 }
4127 return false;
4128 }
4129
Winson Chungaf40f202013-09-18 18:26:31 -07004130 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004131 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004132 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004133 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004134 // If we're not using the default workspace layout, replace workspace cling
4135 // with a custom workspace cling (usually specified in an overlay)
4136 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004137 if (!DISABLE_CUSTOM_CLINGS) {
4138 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4139 getResources().getBoolean(R.bool.config_useCustomClings)) {
4140 // Use a custom cling
4141 View cling = findViewById(R.id.workspace_cling);
4142 ViewGroup clingParent = (ViewGroup) cling.getParent();
4143 int clingIndex = clingParent.indexOfChild(cling);
4144 clingParent.removeViewAt(clingIndex);
4145 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4146 clingParent.addView(customCling, clingIndex);
4147 customCling.setId(R.id.workspace_cling);
4148 }
4149 }
4150 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4151 if (cling != null) {
4152 String sbHintStr = getFirstRunClingSearchBarHint();
4153 String ccHintStr = getFirstRunCustomContentHint();
4154 if (!sbHintStr.isEmpty()) {
4155 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4156 sbHint.setText(sbHintStr);
4157 sbHint.setVisibility(View.VISIBLE);
4158 }
4159 if (!ccHintStr.isEmpty()) {
4160 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4161 ccHint.setText(ccHintStr);
4162 ccHint.setVisibility(View.VISIBLE);
4163 }
Michael Jurka45355c42012-10-08 13:21:35 +02004164 }
Winson Chungaf40f202013-09-18 18:26:31 -07004165 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004166 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004167 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004168 }
4169 }
Winson Chungaf40f202013-09-18 18:26:31 -07004170
Winson Chunge6eabff2013-09-24 11:01:23 -07004171 protected String getFirstRunClingSearchBarHint() {
4172 return "";
4173 }
4174 protected String getFirstRunCustomContentHint() {
4175 return "";
4176 }
4177
Winson Chungaf40f202013-09-18 18:26:31 -07004178 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004179 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004180 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004181 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4182 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004183 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004184 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004185 }
4186 }
4187 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004188 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004189 if (isClingsEnabled() &&
4190 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004191 Cling cling = initCling(R.id.folder_cling, null, true, true);
4192 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004193 } else {
4194 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004195 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004196 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004197 }
Michael Jurka104c4562013-07-08 18:03:46 -07004198 protected SharedPreferences getSharedPrefs() {
4199 return mSharedPrefs;
4200 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004201 public boolean isFolderClingVisible() {
4202 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004203 if (cling != null) {
4204 return cling.getVisibility() == View.VISIBLE;
4205 }
4206 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004207 }
Winson Chungaf40f202013-09-18 18:26:31 -07004208 public void dismissFirstRunCling(View v) {
4209 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4210 Runnable cb = new Runnable() {
4211 public void run() {
4212 // Show the workspace cling next
4213 showFirstRunWorkspaceCling();
4214 }
4215 };
4216 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4217 DISMISS_CLING_DURATION, false);
4218 }
Winson Chung82f55532011-08-09 14:14:23 -07004219 public void dismissWorkspaceCling(View v) {
4220 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004221 Runnable cb = null;
4222 if (v == null) {
4223 cb = new Runnable() {
4224 public void run() {
4225 mWorkspace.enterOverviewMode();
4226 }
4227 };
4228 }
4229 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4230 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004231 }
4232 public void dismissFolderCling(View v) {
4233 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004234 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4235 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004236 }
4237
Winson Chung80baf5a2010-08-09 16:03:15 -07004238 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004239 * Prints out out state for debugging.
4240 */
4241 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004242 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004243 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004244 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4245 Log.d(TAG, "mRestoring=" + mRestoring);
4246 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4247 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004248 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004249 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004250
Winson Chung785d2eb2011-04-14 16:08:02 -07004251 if (mAppsCustomizeContent != null) {
4252 mAppsCustomizeContent.dumpState();
4253 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004254 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004255 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004256
4257 @Override
4258 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4259 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004260 synchronized (sDumpLogs) {
4261 writer.println(" ");
4262 writer.println("Debug logs: ");
4263 for (int i = 0; i < sDumpLogs.size(); i++) {
4264 writer.println(" " + sDumpLogs.get(i));
4265 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004266 }
4267 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004268
4269 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004270 if (DEBUG_DUMP_LOG) {
4271 synchronized (sDumpLogs) {
4272 Log.d(TAG, "");
4273 Log.d(TAG, "*********************");
4274 Log.d(TAG, "Launcher debug logs: ");
4275 for (int i = 0; i < sDumpLogs.size(); i++) {
4276 Log.d(TAG, " " + sDumpLogs.get(i));
4277 }
4278 Log.d(TAG, "*********************");
4279 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004280 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004281 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004282 }
4283
4284 public static void addDumpLog(String tag, String log, boolean debugLog) {
4285 if (debugLog) {
4286 Log.d(tag, log);
4287 }
Winson Chungede41292013-09-19 16:27:36 -07004288 if (DEBUG_DUMP_LOG) {
4289 sDateStamp.setTime(System.currentTimeMillis());
4290 synchronized (sDumpLogs) {
4291 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004292 }
Winson Chungede41292013-09-19 16:27:36 -07004293 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004294 }
4295
Winson Chungede41292013-09-19 16:27:36 -07004296 public void dumpLogsToLocalData() {
4297 if (DEBUG_DUMP_LOG) {
4298 new Thread("DumpLogsToLocalData") {
4299 @Override
4300 public void run() {
4301 boolean success = false;
4302 sDateStamp.setTime(sRunStart);
4303 String FILENAME = sDateStamp.getMonth() + "-"
4304 + sDateStamp.getDay() + "_"
4305 + sDateStamp.getHours() + "-"
4306 + sDateStamp.getMinutes() + "_"
4307 + sDateStamp.getSeconds() + ".txt";
4308
4309 FileOutputStream fos = null;
4310 File outFile = null;
4311 try {
4312 outFile = new File(getFilesDir(), FILENAME);
4313 outFile.createNewFile();
4314 fos = new FileOutputStream(outFile);
4315 } catch (Exception e) {
4316 e.printStackTrace();
4317 }
4318 if (fos != null) {
4319 PrintWriter writer = new PrintWriter(fos);
4320
4321 writer.println(" ");
4322 writer.println("Debug logs: ");
4323 synchronized (sDumpLogs) {
4324 for (int i = 0; i < sDumpLogs.size(); i++) {
4325 writer.println(" " + sDumpLogs.get(i));
4326 }
4327 }
4328 writer.close();
4329 }
4330 try {
4331 if (fos != null) {
4332 fos.close();
4333 success = true;
4334 }
4335 } catch (IOException e) {
4336 e.printStackTrace();
4337 }
4338 }
4339 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004340 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004341 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004342}
Michael Jurka2763be32011-02-24 11:19:57 -08004343
Michael Jurkaabded662011-03-04 12:06:57 -08004344interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004345 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004346 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004347 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004348 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004349 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004350}