blob: 269f53baaa0910cfe56f1d392af9e364bc10aaca [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;
Mathew Inwood72fbec12013-11-19 15:45:07 +000048import 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;
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -070090import android.view.accessibility.AccessibilityManager;
Adam Cohencff6af82011-09-13 14:51:53 -070091import android.view.animation.AccelerateDecelerateInterpolator;
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 Cohenc0dcf592011-06-01 15:30:43 -0700106import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700108import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700109import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700112import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700115import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000116import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118/**
119 * Default launcher application.
120 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100121public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700122 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700123 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800124 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700125 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126
Daniel Sandlerf061f822013-06-27 13:59:36 -0400127 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400128 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700129 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400130 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700131 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Michael Jurka8b805b12012-04-18 14:23:14 -0700140 private static final int REQUEST_BIND_APPWIDGET = 11;
141
Mathew Inwood876a8462013-06-14 14:12:41 +0100142 /**
143 * IntentStarter uses request codes starting with this. This must be greater than all activity
144 * request codes used internally.
145 */
146 protected static final int REQUEST_LAST = 100;
147
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
149
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800150 static final int SCREEN_COUNT = 5;
151 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
Romain Guy98d01652009-06-30 16:21:04 -0700153 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800154 // To turn on these properties, type
155 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
156 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
157 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158
Winson Chung2672ff92012-05-04 16:22:30 -0700159 // The Intent extra that defines whether to ignore the launch animation
160 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400161 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: int
164 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700165 // Type: int
166 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700168 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
169 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
171 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700172 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: boolean
176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
177 // Type: long
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700179 // Type: int
180 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
183 // Type: parcelable
184 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000185 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000187 // Type: int[]
188 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189
Adam Cohenb54a5982014-01-08 15:21:04 -0800190
191 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
192
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100193 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700194 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100195 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700196 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100197 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700198
Adam Cohen39a06042013-07-19 14:30:12 -0700199 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700200 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700201
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700202 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700203 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700204 private State mState = State.WORKSPACE;
205 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700206
Joe Onorato9c1289c2009-08-17 11:03:03 -0400207 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700208 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
209 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Winson Chungaf40f202013-09-18 18:26:31 -0700210 private static final int SHOW_CLING_DURATION = 250;
211 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800214 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000216 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
217 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
218
Winson Chunga2413752012-04-03 14:22:34 -0700219 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700220 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
221 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700222 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700223
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800224 private final BroadcastReceiver mCloseSystemDialogsReceiver
225 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800226 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
227
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 private LayoutInflater mInflater;
229
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700231 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800232 private DragLayer mDragLayer;
233 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700234 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700235
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700236 private AppWidgetManager mAppWidgetManager;
237 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700238
Michael Jurkac9d95c52011-08-29 14:03:34 -0700239 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700240 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800241 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700242
Michael Jurka0280c3b2010-09-17 15:00:07 -0700243 private int[] mTmpAddItemCellCoordinates = new int[2];
244
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 private FolderInfo mFolderInfo;
246
Winson Chung3d503fb2011-07-13 17:25:49 -0700247 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700248 private View mOverviewPanel;
249
Michael Jurka838a4ca2011-02-07 13:33:06 -0800250 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700251
Winson Chungc51db6a2011-10-05 11:44:49 -0700252 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700253 private AppsCustomizeTabHost mAppsCustomizeTabHost;
254 private AppsCustomizePagedView mAppsCustomizeContent;
255 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100256 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700259 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
260 // scroll issues (because the workspace may not have been measured yet) and extra work.
261 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
262 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
264 private SpannableStringBuilder mDefaultKeySsb = null;
265
Joe Onorato9c1289c2009-08-17 11:03:03 -0400266 private boolean mWorkspaceLoading = true;
267
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800268 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private boolean mRestoring;
270 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700271 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272
Michael Jurka1e2f4652013-07-08 18:03:46 -0700273 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700274 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
275
Winson Chung4a2afa32012-07-19 14:53:05 -0700276 // Keep track of whether the user has left launcher
277 private static boolean sPausedFromUserAction = false;
278
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279 private Bundle mSavedInstanceState;
280
Joe Onorato9c1289c2009-08-17 11:03:03 -0400281 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800282 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800283 private boolean mUserPresent = true;
284 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700285 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800286 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700287 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700288 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700290 private static LocaleConfiguration sLocaleConfiguration = null;
291
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700292 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700293
Adam Cohen61f560d2013-09-30 15:58:20 -0700294 private View.OnTouchListener mHapticFeedbackTouchListener;
295
Adam Cohended9f8d2010-11-03 13:25:16 -0700296 // Related to the auto-advancing of widgets
297 private final int ADVANCE_MSG = 1;
298 private final int mAdvanceInterval = 20000;
299 private final int mAdvanceStagger = 250;
300 private long mAutoAdvanceSentTime;
301 private long mAutoAdvanceTimeLeft = -1;
302 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
303 new HashMap<View, AppWidgetProviderInfo>();
304
Winson Chung400438b2011-01-16 17:53:48 -0800305 // Determines how long to wait after a rotation before restoring the screen orientation to
306 // match the sensor state.
307 private final int mRestoreScreenOrientationDelay = 500;
308
Michael Jurka4ef207b2010-11-29 17:05:45 -0800309 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700310 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
311 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
312 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800313
Winson Chungd64a6662013-09-30 11:06:59 -0700314 private Intent mAppMarketIntent = null;
315 private static final boolean DISABLE_MARKET_BUTTON = true;
316
Craig Mautner360310b2012-10-26 15:13:08 -0700317 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700318
Adam Cohen1462de32012-07-24 22:34:36 -0700319 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700320 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700321
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700322 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700323 static Date sDateStamp = new Date();
324 static DateFormat sDateFormat =
325 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
326 static long sRunStart = System.currentTimeMillis();
327 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700328
Winson Chung46353de2012-02-16 14:05:10 -0800329 // We only want to get the SharedPreferences once since it does an FS stat each time we get
330 // it from the context.
331 private SharedPreferences mSharedPrefs;
332
Adam Cohene25af792013-06-06 23:08:25 -0700333 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
334
Winson Chungf0c6ae02012-03-21 16:10:31 -0700335 // Holds the page that we need to animate to, and the icon views that we need to animate up
336 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700337 private ImageView mFolderIconImageView;
338 private Bitmap mFolderIconBitmap;
339 private Canvas mFolderIconCanvas;
340 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700341
Michael Jurkaddd62e92011-02-16 17:49:14 -0800342 private BubbleTextView mWaitingForResume;
343
Michael Jurka22143132012-10-04 17:42:38 +0200344 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
345 = new HideFromAccessibilityHelper();
346
Michael Jurkac1f5d262011-09-30 19:32:27 -0700347 private Runnable mBuildLayersRunnable = new Runnable() {
348 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700349 if (mWorkspace != null) {
350 mWorkspace.buildPageHardwareLayers();
351 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700352 }
353 };
354
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800355 private static ArrayList<PendingAddArguments> sPendingAddList
356 = new ArrayList<PendingAddArguments>();
357
Michael Jurka7267fa52013-09-26 15:29:57 -0700358 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800359
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800360 private static class PendingAddArguments {
361 int requestCode;
362 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700363 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700364 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 int cellX;
366 int cellY;
367 }
368
Daniel Sandlerff02d492013-08-05 02:12:05 -0400369 private Stats mStats;
370
Michael Jurka0a457bf2012-11-19 14:05:05 -0800371 private static boolean isPropertyEnabled(String propertyName) {
372 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700373 }
374
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 @Override
376 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700377 if (DEBUG_STRICT_MODE) {
378 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
379 .detectDiskReads()
380 .detectDiskWrites()
381 .detectNetwork() // or .detectAll() for all detectable problems
382 .penaltyLog()
383 .build());
384 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
385 .detectLeakedSqlLiteObjects()
386 .detectLeakedClosableObjects()
387 .penaltyLog()
388 .penaltyDeath()
389 .build());
390 }
391
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400393
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400394 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400395 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700396
397 // Determine the dynamic grid properties
398 Point smallestSize = new Point();
399 Point largestSize = new Point();
400 Point realSize = new Point();
401 Display display = getWindowManager().getDefaultDisplay();
402 display.getCurrentSizeRange(smallestSize, largestSize);
403 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700404 DisplayMetrics dm = new DisplayMetrics();
405 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700406
Winson Chung5f8afe62013-08-12 16:19:28 -0700407 // Lazy-initialize the dynamic grid
408 DeviceProfile grid = app.initDynamicGrid(this,
409 Math.min(smallestSize.x, smallestSize.y),
410 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700411 realSize.x, realSize.y,
412 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700413
414 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400415 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700416 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800417 mModel = app.setLauncher(this);
418 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700419 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400420 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700422
Daniel Sandlerff02d492013-08-05 02:12:05 -0400423 mStats = new Stats(this);
424
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700425 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700426
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700427 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
428 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700430 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
431 // this also ensures that any synchronous binding below doesn't re-trigger another
432 // LauncherModel load.
433 mPaused = false;
434
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200436 android.os.Debug.startMethodTracing(
437 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438 }
439
Adam Cohen53805212013-10-01 10:39:23 -0700440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700443
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100445 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800447 registerContentObservers();
448
Joe Onorato7c312c12009-08-13 21:36:53 -0700449 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700450
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 mSavedState = savedInstanceState;
452 restoreState(mSavedState);
453
454 if (PROFILE_STARTUP) {
455 android.os.Debug.stopMethodTracing();
456 }
457
458 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700459 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700460 // If the user leaves launcher, then we should just load items asynchronously when
461 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500462 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 } else {
464 // We only load the page synchronously if the user rotates (or triggers a
465 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800466 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700467 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800468 }
469
470 // For handling default keys
471 mDefaultKeySsb = new SpannableStringBuilder();
472 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800473
474 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
475 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800476
Adam Cohenf9426d52012-06-04 17:26:21 -0700477 updateGlobalIcons();
478
479 // On large interfaces, we want the screen to auto-rotate based on the current orientation
480 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700481
Adam Cohenb54a5982014-01-08 15:21:04 -0800482 showFirstRunActivity();
Winson Chungaf40f202013-09-18 18:26:31 -0700483 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700484 }
485
Winson Chung4a2afa32012-07-19 14:53:05 -0700486 protected void onUserLeaveHint() {
487 super.onUserLeaveHint();
488 sPausedFromUserAction = true;
489 }
490
Winson Chung98ca0f72013-07-29 12:58:51 -0700491 /** To be overriden by subclasses to hint to Launcher that we have custom content */
492 protected boolean hasCustomContentToLeft() {
493 return false;
494 }
495
Dave Hawkeya8881582013-09-17 15:55:33 -0600496 /**
497 * To be overridden by subclasses to create the custom content and call
498 * {@link #addToCustomContentPage}. This will only be invoked if
499 * {@link #hasCustomContentToLeft()} is {@code true}.
500 */
501 protected void addCustomContentToLeft() {
502 }
503
504 /**
Adam Cohenb54a5982014-01-08 15:21:04 -0800505 * To be overridden by subclasses to indicate that there is an activity to launch
506 * before showing the standard launcher experience.
507 */
508 protected boolean hasFirstRunActivity() {
509 return false;
510 }
511
512 /**
513 * To be overridden by subclasses to launch any first run activity
514 */
515 protected Intent getFirstRunActivity() {
516 return null;
517 }
518
519 /**
Dave Hawkeya8881582013-09-17 15:55:33 -0600520 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
521 * ensure the custom content page is added or removed if necessary.
522 */
523 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600524 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600525 // Not bound yet, wait for bindScreens to be called.
526 return;
527 }
528
529 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
530 // Create the custom content page and call the subclass to populate it.
531 mWorkspace.createCustomContentPage();
532 addCustomContentToLeft();
533 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
534 mWorkspace.removeCustomContentPage();
535 }
536 }
537
Adam Cohenf9426d52012-06-04 17:26:21 -0700538 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700539 boolean searchVisible = false;
540 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800541 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700542 int coi = getCurrentOrientationIndexForGlobalIcons();
543 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
544 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700545 if (!DISABLE_MARKET_BUTTON) {
546 updateAppMarketIcon();
547 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700548 searchVisible = updateGlobalSearchIcon();
549 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700550 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700551 if (sGlobalSearchIcon[coi] != null) {
552 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700553 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700554 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700555 if (sVoiceSearchIcon[coi] != null) {
556 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700557 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700558 }
Winson Chungd64a6662013-09-30 11:06:59 -0700559 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700560 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800561 }
Winson Chungadf0c182012-08-23 14:59:07 -0700562 if (mSearchDropTargetBar != null) {
563 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
564 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800565 }
Romain Guycbb89e42009-06-08 15:52:54 -0700566
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700568 if (sLocaleConfiguration == null) {
569 new AsyncTask<Void, Void, LocaleConfiguration>() {
570 @Override
571 protected LocaleConfiguration doInBackground(Void... unused) {
572 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
573 readConfiguration(Launcher.this, localeConfiguration);
574 return localeConfiguration;
575 }
576
577 @Override
578 protected void onPostExecute(LocaleConfiguration result) {
579 sLocaleConfiguration = result;
580 checkForLocaleChange(); // recursive, but now with a locale configuration
581 }
582 }.execute();
583 return;
584 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700585
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 final Configuration configuration = getResources().getConfiguration();
587
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 final String locale = configuration.locale.toString();
590
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700591 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 final int mcc = configuration.mcc;
593
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700594 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800595 final int mnc = configuration.mnc;
596
Romain Guy84f296c2009-11-04 15:00:44 -0800597 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598
Romain Guy84f296c2009-11-04 15:00:44 -0800599 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700600 sLocaleConfiguration.locale = locale;
601 sLocaleConfiguration.mcc = mcc;
602 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700603
Joe Onorato0589f0f2010-02-08 13:44:00 -0800604 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700605
606 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100607 new AsyncTask<Void, Void, Void>() {
608 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700609 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100610 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700611 }
Michael Jurka43467462013-11-14 12:03:58 +0100612 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700613 }
614 }
615
616 private static class LocaleConfiguration {
617 public String locale;
618 public int mcc = -1;
619 public int mnc = -1;
620 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700621
Romain Guy98d01652009-06-30 16:21:04 -0700622 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
623 DataInputStream in = null;
624 try {
625 in = new DataInputStream(context.openFileInput(PREFERENCES));
626 configuration.locale = in.readUTF();
627 configuration.mcc = in.readInt();
628 configuration.mnc = in.readInt();
629 } catch (FileNotFoundException e) {
630 // Ignore
631 } catch (IOException e) {
632 // Ignore
633 } finally {
634 if (in != null) {
635 try {
636 in.close();
637 } catch (IOException e) {
638 // Ignore
639 }
640 }
641 }
642 }
643
644 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
645 DataOutputStream out = null;
646 try {
647 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
648 out.writeUTF(configuration.locale);
649 out.writeInt(configuration.mcc);
650 out.writeInt(configuration.mnc);
651 out.flush();
652 } catch (FileNotFoundException e) {
653 // Ignore
654 } catch (IOException e) {
655 //noinspection ResultOfMethodCallIgnored
656 context.getFileStreamPath(PREFERENCES).delete();
657 } finally {
658 if (out != null) {
659 try {
660 out.close();
661 } catch (IOException e) {
662 // Ignore
663 }
664 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 }
666 }
667
Anton Hanssona2f665f2013-09-26 12:18:32 +0100668 public Stats getStats() {
669 return mStats;
670 }
671
Bjorn Bringertc459e522013-06-07 19:36:01 +0100672 public LayoutInflater getInflater() {
673 return mInflater;
674 }
675
Adam Cohen716b51e2011-06-30 12:09:54 -0700676 public DragLayer getDragLayer() {
677 return mDragLayer;
678 }
679
Winson Chung36a62fe2012-05-06 18:04:42 -0700680 boolean isDraggingEnabled() {
681 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
682 // that is subsequently removed from the workspace in startBinding().
683 return !mModel.isLoadingWorkspace();
684 }
685
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800686 static int getScreen() {
687 synchronized (sLock) {
688 return sScreen;
689 }
690 }
691
692 static void setScreen(int screen) {
693 synchronized (sLock) {
694 sScreen = screen;
695 }
696 }
697
Winson Chung557d6ed2011-07-08 15:34:52 -0700698 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000699 * Copied from View -- the View version of the method isn't called
700 * anywhere else in our process and only exists for API level 17+,
701 * so it's ok to keep our own version with no API requirement.
702 */
703 public static int generateViewId() {
704 for (;;) {
705 final int result = sNextGeneratedId.get();
706 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
707 int newValue = result + 1;
708 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
709 if (sNextGeneratedId.compareAndSet(result, newValue)) {
710 return result;
711 }
712 }
713 }
714
715 public int getViewIdForItem(ItemInfo info) {
716 // This cast is safe given the > 2B range for int.
717 int itemId = (int) info.id;
718 if (mItemIdToViewId.containsKey(itemId)) {
719 return mItemIdToViewId.get(itemId);
720 }
721 int viewId = generateViewId();
722 mItemIdToViewId.put(itemId, viewId);
723 return viewId;
724 }
725
726 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700727 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
728 * a configuration step, this allows the proper animations to run after other transitions.
729 */
730 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700731 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800732 switch (args.requestCode) {
733 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700734 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700735 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800736 break;
737 case REQUEST_PICK_SHORTCUT:
738 processShortcut(args.intent);
739 break;
740 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700741 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700742 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700743 result = true;
744 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 case REQUEST_CREATE_APPWIDGET:
746 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700747 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700748 result = true;
749 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 }
Michael Jurka27614d22012-04-02 06:40:22 -0700751 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
752 // if you turned the screen off and then back while in All Apps, Launcher would not
753 // return to the workspace. Clearing mAddInfo.container here fixes this issue
754 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700755 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800756 }
757
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700759 protected void onActivityResult(
760 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700761 // Reset the startActivity waiting flag
762 mWaitingForResult = false;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800763 int pendingAddWidgetId = mPendingAddWidgetId;
764 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700765
Adam Cohenad4e15c2013-10-17 16:21:35 -0700766 Runnable exitSpringLoaded = new Runnable() {
767 @Override
768 public void run() {
769 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
770 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
771 }
772 };
773
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700775 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700776 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
777 if (resultCode == RESULT_CANCELED) {
778 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700779 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
780 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
783 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700784 }
785 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200786 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
787 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
788 mWorkspace.exitOverviewMode(false);
789 }
790 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700791 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200792
Adam Cohened66b2b2012-01-23 17:28:51 -0800793 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
794 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700795
Adam Cohened66b2b2012-01-23 17:28:51 -0800796 // We have special handling for widgets
797 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800798 final int appWidgetId;
799 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
800 : -1;
801 if (widgetId < 0) {
802 appWidgetId = pendingAddWidgetId;
803 } else {
804 appWidgetId = widgetId;
805 }
806
Adam Cohenad4e15c2013-10-17 16:21:35 -0700807 final int result;
808 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800809 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700810 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
811 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 result = RESULT_CANCELED;
813 completeTwoStageWidgetDrop(result, appWidgetId);
814 onComplete = new Runnable() {
815 @Override
816 public void run() {
817 exitSpringLoadedDragModeDelayed(false, 0, null);
818 }
819 };
Winson Chung5aaab772012-04-27 15:24:02 -0700820 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700821 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700822 final CellLayout dropLayout =
823 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
824 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700825 onComplete = new Runnable() {
826 @Override
827 public void run() {
828 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700829 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700830 }
831 };
Winson Chung5aaab772012-04-27 15:24:02 -0700832 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700833 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
834 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800835 return;
836 }
837
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838 // The pattern used here is that a user PICKs a specific application,
839 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700840
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
842 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700843 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800844 final PendingAddArguments args = new PendingAddArguments();
845 args.requestCode = requestCode;
846 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700847 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700848 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700849 args.cellX = mPendingAddInfo.cellX;
850 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800851 if (isWorkspaceLocked()) {
852 sPendingAddList.add(args);
853 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700854 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700856 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
857 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700858 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700859 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
860 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800862 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800863 }
864
865 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700866 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700867 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800868 Runnable onCompleteRunnable = null;
869 int animationType = 0;
870
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700871 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 if (resultCode == RESULT_OK) {
873 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
874 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700875 mPendingAddWidgetInfo);
876 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800877 onCompleteRunnable = new Runnable() {
878 @Override
879 public void run() {
880 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700881 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700882 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
883 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 }
885 };
886 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800887 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800888 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800889 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700890 if (mDragLayer.getAnimatedView() != null) {
891 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
892 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
893 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700894 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700895 // The animated view may be null in the case of a rotation during widget configuration
896 onCompleteRunnable.run();
897 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 }
899
900 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700901 protected void onStop() {
902 super.onStop();
903 FirstFrameAnimatorHelper.setIsVisible(false);
904 }
905
906 @Override
907 protected void onStart() {
908 super.onStart();
909 FirstFrameAnimatorHelper.setIsVisible(true);
910 }
911
912 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800913 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200914 long startTime = 0;
915 if (DEBUG_RESUME_TIME) {
916 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400917 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200918 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800919 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700920
Winson Chung4a2afa32012-07-19 14:53:05 -0700921 // Restore the previous launcher state
922 if (mOnResumeState == State.WORKSPACE) {
923 showWorkspace(false);
924 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800925 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700926 }
927 mOnResumeState = State.NONE;
928
Craig Mautner360310b2012-10-26 15:13:08 -0700929 // Background was set to gradient in onPause(), restore to black if in all apps.
930 setWorkspaceBackground(mState == State.WORKSPACE);
931
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800932 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700933 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700934 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400935 mWorkspaceLoading = true;
Derek Prothro7aff3992013-12-10 14:00:37 -0500936 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400937 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700938 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700940 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200941 // We might have postponed some bind calls until onResume (see waitUntilResume) --
942 // execute them here
943 long startTimeCallbacks = 0;
944 if (DEBUG_RESUME_TIME) {
945 startTimeCallbacks = System.currentTimeMillis();
946 }
947
948 if (mAppsCustomizeContent != null) {
949 mAppsCustomizeContent.setBulkBind(true);
950 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700951 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
952 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200953 }
954 if (mAppsCustomizeContent != null) {
955 mAppsCustomizeContent.setBulkBind(false);
956 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700957 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200958 if (DEBUG_RESUME_TIME) {
959 Log.d(TAG, "Time spent processing callbacks in onResume: " +
960 (System.currentTimeMillis() - startTimeCallbacks));
961 }
Michael Jurka447bf842013-05-15 14:52:15 +0200962 }
Michael Jurka54554252013-08-01 12:52:23 +0200963 if (mOnResumeCallbacks.size() > 0) {
964 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
965 mOnResumeCallbacks.get(i).run();
966 }
967 mOnResumeCallbacks.clear();
968 }
Winson Chunge4e50662012-01-23 14:45:13 -0800969
970 // Reset the pressed state of icons that were locked in the press state while activities
971 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800972 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800973 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800974 mWaitingForResume.setStayPressed(false);
975 }
Winson Chunge4e50662012-01-23 14:45:13 -0800976 if (mAppsCustomizeContent != null) {
977 // Resets the previous all apps icon press state
978 mAppsCustomizeContent.resetDrawableState();
979 }
Winson Chung82963d52013-10-09 11:20:57 -0700980
Adam Cohen06dff352012-06-01 17:17:08 -0700981 // It is possible that widgets can receive updates while launcher is not in the foreground.
982 // Consequently, the widgets will be inflated in the orientation of the foreground activity
983 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
984 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700985 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700986
Winson Chung780fe592013-09-26 14:48:44 -0700987 // Process any items that were added while Launcher was away.
988 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
989
Winson Chung5841efa2013-09-30 18:06:44 -0700990 // Update the voice search button proxy
991 updateVoiceButtonProxyVisible(false);
992
Adam Cohenf9426d52012-06-04 17:26:21 -0700993 // Again, as with the above scenario, it's possible that one or more of the global icons
994 // were updated in the wrong orientation.
995 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200996 if (DEBUG_RESUME_TIME) {
997 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
998 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700999
1000 if (mWorkspace.getCustomContentCallbacks() != null) {
1001 // If we are resuming and the custom content is the current page, we call onShow().
1002 // It is also poassible that onShow will instead be called slightly after first layout
1003 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1004 if (mWorkspace.isOnOrMovingToCustomContent()) {
1005 mWorkspace.getCustomContentCallbacks().onShow();
1006 }
1007 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001008 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001009 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001010 }
1011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001013 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001014 // Ensure that items added to Launcher are queued until Launcher returns
1015 InstallShortcutReceiver.enableInstallQueue();
1016
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001017 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001018 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001019 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001020 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001021
1022 // We call onHide() aggressively. The custom content callbacks should be able to
1023 // debounce excess onHide calls.
1024 if (mWorkspace.getCustomContentCallbacks() != null) {
1025 mWorkspace.getCustomContentCallbacks().onHide();
1026 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001027 }
Romain Guycbb89e42009-06-08 15:52:54 -07001028
Adam Cohen66a01fd2013-06-11 12:48:00 -07001029 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -07001030 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -06001031 addCustomContentToLeft();
1032 }
Adam Cohen66a01fd2013-06-11 12:48:00 -07001033 }
1034
Adam Cohenbffe7452013-07-22 18:21:45 -07001035 QSBScroller mQsbScroller = new QSBScroller() {
1036 int scrollY = 0;
1037
1038 @Override
1039 public void setScrollY(int scroll) {
1040 scrollY = scroll;
1041
1042 if (mWorkspace.isOnOrMovingToCustomContent()) {
1043 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001044 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001045 }
1046 }
1047 };
1048
1049 public void resetQSBScroll() {
1050 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001051 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001052 }
1053
1054 public interface CustomContentCallbacks {
1055 // Custom content is completely shown
1056 public void onShow();
1057
1058 // Custom content is completely hidden
1059 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001060
1061 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1062 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001063 }
1064
Adam Cohen30bacb22013-08-29 14:25:25 -07001065 protected void startSettings() {
1066 }
1067
Adam Cohenbffe7452013-07-22 18:21:45 -07001068 public interface QSBScroller {
1069 public void setScrollY(int scrollY);
1070 }
1071
Winson Chung98ca0f72013-07-29 12:58:51 -07001072 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001073 CustomContentCallbacks callbacks, String description) {
1074 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001075 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001076 }
1077
Adam Cohenedb40762013-07-18 16:45:45 -07001078 // The custom content needs to offset its content to account for the QSB
1079 public int getTopOffsetForCustomContent() {
1080 return mWorkspace.getPaddingTop();
1081 }
1082
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001083 @Override
1084 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001085 // Flag the loader to stop early before switching
1086 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001087 if (mAppsCustomizeContent != null) {
1088 mAppsCustomizeContent.surrender();
1089 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001090 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001091 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001092
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001093 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001094 @Override
1095 public void onWindowFocusChanged(boolean hasFocus) {
1096 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001097 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001098 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001099
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 private boolean acceptFilter() {
1101 final InputMethodManager inputManager = (InputMethodManager)
1102 getSystemService(Context.INPUT_METHOD_SERVICE);
1103 return !inputManager.isFullscreenMode();
1104 }
1105
1106 @Override
1107 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001108 final int uniChar = event.getUnicodeChar();
1109 final boolean handled = super.onKeyDown(keyCode, event);
1110 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1111 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1113 keyCode, event);
1114 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001115 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001116 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001117 // showSearchDialog()
1118 // If there are multiple keystrokes before the search dialog takes focus,
1119 // onSearchRequested() will be called for every keystroke,
1120 // but it is idempotent, so it's fine.
1121 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 }
1123 }
1124
Joe Onorato8a9625e2010-01-28 15:55:35 -08001125 // Eat the long press event so the keyboard doesn't come up.
1126 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1127 return true;
1128 }
1129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 return handled;
1131 }
1132
Karl Rosaen138a0412009-04-23 19:00:21 -07001133 private String getTypedText() {
1134 return mDefaultKeySsb.toString();
1135 }
1136
1137 private void clearTypedText() {
1138 mDefaultKeySsb.clear();
1139 mDefaultKeySsb.clearSpans();
1140 Selection.setSelection(mDefaultKeySsb, 0);
1141 }
1142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001144 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1145 * State
1146 */
1147 private static State intToState(int stateOrdinal) {
1148 State state = State.WORKSPACE;
1149 final State[] stateValues = State.values();
1150 for (int i = 0; i < stateValues.length; i++) {
1151 if (stateValues[i].ordinal() == stateOrdinal) {
1152 state = stateValues[i];
1153 break;
1154 }
1155 }
1156 return state;
1157 }
1158
1159 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001160 * Restores the previous state, if it exists.
1161 *
1162 * @param savedState The previous state.
1163 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001164 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 private void restoreState(Bundle savedState) {
1166 if (savedState == null) {
1167 return;
1168 }
1169
Michael Jurka883f55b2010-10-21 15:47:14 -07001170 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001171 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001172 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001173 }
1174
Adam Cohen21cd0022013-10-09 18:57:02 -07001175 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1176 PagedView.INVALID_RESTORE_PAGE);
1177 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001178 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001179 }
1180
Winson Chung3d503fb2011-07-13 17:25:49 -07001181 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001182 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001183
Winson Chung3d503fb2011-07-13 17:25:49 -07001184 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1185 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001186 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001187 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1188 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001189 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1190 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1191 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001192 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001193 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 mRestoring = true;
1195 }
1196
1197 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1198 if (renameFolder) {
1199 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001200 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 mRestoring = true;
1202 }
Winson Chunga12a2502010-12-20 14:41:35 -08001203
Winson Chung785d2eb2011-04-14 16:08:02 -07001204 // Restore the AppsCustomize tab
1205 if (mAppsCustomizeTabHost != null) {
1206 String curTab = savedState.getString("apps_customize_currentTab");
1207 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001208 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001209 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001210 mAppsCustomizeContent.loadAssociatedPages(
1211 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001212 }
1213
Winson Chung5afbf7b2011-07-25 11:53:08 -07001214 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1215 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001216 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001217 mItemIdToViewId = (HashMap<Integer, Integer>)
1218 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 }
1220
1221 /**
1222 * Finds all the views we need and configure them properly.
1223 */
1224 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001225 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001226
Craig Mautner360310b2012-10-26 15:13:08 -07001227 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001228 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1229 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001230
John Spurlock77e1f472013-09-11 10:09:51 -04001231 mLauncherView.setSystemUiVisibility(
1232 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001233 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
Winson Chung4c98d922011-05-31 16:50:48 -07001235 // Setup the drag layer
1236 mDragLayer.setup(this, dragController);
1237
Winson Chung3d503fb2011-07-13 17:25:49 -07001238 // Setup the hotseat
1239 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1240 if (mHotseat != null) {
1241 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001242 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001243 }
1244
Adam Cohenf358a4b2013-07-23 16:47:31 -07001245 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001246 View widgetButton = findViewById(R.id.widget_button);
1247 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001248 @Override
1249 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001250 if (!mWorkspace.isSwitchingState()) {
1251 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
1252 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001253 }
1254 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001255 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1256
1257 View wallpaperButton = findViewById(R.id.wallpaper_button);
1258 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001259 @Override
1260 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001261 if (!mWorkspace.isSwitchingState()) {
1262 startWallpaper();
1263 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001264 }
1265 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001266 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1267
1268 View settingsButton = findViewById(R.id.settings_button);
1269 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001270 @Override
1271 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001272 if (!mWorkspace.isSwitchingState()) {
1273 startSettings();
1274 }
Adam Cohen30bacb22013-08-29 14:25:25 -07001275 }
1276 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001277 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001278 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001279
Winson Chung4c98d922011-05-31 16:50:48 -07001280 // Setup the workspace
1281 mWorkspace.setHapticFeedbackEnabled(false);
1282 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001283 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001284 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001285
Winson Chungf0ea4d32011-06-06 14:27:16 -07001286 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001287 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001288
Winson Chungf0ea4d32011-06-06 14:27:16 -07001289 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001290 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001291 mAppsCustomizeContent = (AppsCustomizePagedView)
1292 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1293 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001294
Winson Chung3d503fb2011-07-13 17:25:49 -07001295 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001296 dragController.setDragScoller(mWorkspace);
1297 dragController.setScrollView(mDragLayer);
1298 dragController.setMoveTarget(mWorkspace);
1299 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001300 if (mSearchDropTargetBar != null) {
1301 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001302 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001303
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001304 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001305 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001306 mWeightWatcher = new WeightWatcher(this);
1307 mWeightWatcher.setAlpha(0.5f);
1308 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001309 new FrameLayout.LayoutParams(
1310 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001311 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001312 Gravity.BOTTOM)
1313 );
Adam Cohen39a06042013-07-19 14:30:12 -07001314
1315 boolean show = shouldShowWeightWatcher();
1316 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 }
1319
1320 /**
1321 * Creates a view representing a shortcut.
1322 *
1323 * @param info The data structure describing the shortcut.
1324 *
1325 * @return A View inflated from R.layout.application.
1326 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001327 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001329 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330 }
1331
1332 /**
1333 * Creates a view representing a shortcut inflated from the specified resource.
1334 *
1335 * @param layoutResId The id of the XML layout used to create the shortcut.
1336 * @param parent The group the shortcut belongs to.
1337 * @param info The data structure describing the shortcut.
1338 *
1339 * @return A View inflated from layoutResId.
1340 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001341 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001342 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1343 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 return favorite;
1346 }
1347
1348 /**
1349 * Add an application shortcut to the workspace.
1350 *
1351 * @param data The intent describing the application.
1352 * @param cellInfo The position on screen where to create the shortcut.
1353 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001354 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001355 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001356 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001357
Adam Cohenfbba09b2011-07-18 21:43:05 -07001358 // First we check if we already know the exact location where we want to add this item.
1359 if (cellX >= 0 && cellY >= 0) {
1360 cellXY[0] = cellX;
1361 cellXY[1] = cellY;
1362 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001363 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001364 return;
1365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001367 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001368
Romain Guy73b979d2009-06-09 12:57:21 -07001369 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001370 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001372 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001373 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001374 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001375 } else {
1376 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001377 }
1378 }
Romain Guycbb89e42009-06-08 15:52:54 -07001379
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 /**
1381 * Add a shortcut to the workspace.
1382 *
1383 * @param data The intent describing the shortcut.
1384 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001386 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001387 int cellY) {
1388 int[] cellXY = mTmpAddItemCellCoordinates;
1389 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001390 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001391
Michael Jurkad3ef3062010-11-23 16:23:58 -08001392 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001393
Adam Cohen558baaf2011-08-15 15:22:57 -07001394 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001395 if (info == null) {
1396 return;
1397 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001398 final View view = createShortcut(info);
1399
Adam Cohenfbba09b2011-07-18 21:43:05 -07001400 // First we check if we already know the exact location where we want to add this item.
1401 if (cellX >= 0 && cellY >= 0) {
1402 cellXY[0] = cellX;
1403 cellXY[1] = cellY;
1404 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001405
1406 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001407 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001408 true, null,null)) {
1409 return;
1410 }
1411 DragObject dragObject = new DragObject();
1412 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001413 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1414 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001415 return;
1416 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001417 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001418 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001419 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001420 foundCellSpan = (result != null);
1421 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001422 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001423 }
1424
1425 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001426 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001427 return;
1428 }
1429
Adam Cohendcd297f2013-06-18 13:13:40 -07001430 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431
1432 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001433 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001434 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 }
1436 }
1437
Adam Cohen2f093b62012-04-30 18:59:53 -07001438 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1439 int minHeight) {
1440 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001441 // We want to account for the extra amount of padding that we are adding to the widget
1442 // to ensure that it gets the full amount of space that it has requested
1443 int requiredWidth = minWidth + padding.left + padding.right;
1444 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001445 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001446 }
1447
Adam Cohen2f093b62012-04-30 18:59:53 -07001448 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1449 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001450 }
1451
Adam Cohen2f093b62012-04-30 18:59:53 -07001452 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1453 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001454 }
1455
Adam Cohen2f093b62012-04-30 18:59:53 -07001456 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1457 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001458 }
1459
Adam Cohen2f093b62012-04-30 18:59:53 -07001460 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1461 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001462 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001463 }
1464
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001465 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001466 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001468 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001469 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001471 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001472 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1473 if (appWidgetInfo == null) {
1474 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1475 }
Romain Guycbb89e42009-06-08 15:52:54 -07001476
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001477 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001478 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001479
Adam Cohen2f093b62012-04-30 18:59:53 -07001480 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1481 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001482
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001484 // We have saved the position to which the widget was dragged-- this really only matters
1485 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001486 int[] cellXY = mTmpAddItemCellCoordinates;
1487 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001488 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001489 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001490 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1491 cellXY[0] = mPendingAddInfo.cellX;
1492 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001493 spanXY[0] = mPendingAddInfo.spanX;
1494 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001495 foundCellSpan = true;
1496 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001497 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001498 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001499 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1500 spanXY[1], cellXY, finalSpan);
1501 spanXY[0] = finalSpan[0];
1502 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001503 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001504 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001505 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001506 }
1507
Michael Jurka0280c3b2010-09-17 15:00:07 -07001508 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001509 if (appWidgetId != -1) {
1510 // Deleting an app widget ID is a void call but writes to disk before returning
1511 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001512 new AsyncTask<Void, Void, Void>() {
1513 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001514 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001515 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001516 }
Michael Jurka43467462013-11-14 12:03:58 +01001517 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001518 }
Winson Chung93eef082012-03-23 15:59:27 -07001519 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001520 return;
1521 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001523 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001524 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1525 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001526 launcherInfo.spanX = spanXY[0];
1527 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001528 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1529 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001530
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001531 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001532 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001533
1534 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001535 if (hostView == null) {
1536 // Perform actual inflation because we're live
1537 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1538 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1539 } else {
1540 // The AppWidgetHostView has already been inflated and instantiated
1541 launcherInfo.hostView = hostView;
1542 }
Romain Guycbb89e42009-06-08 15:52:54 -07001543
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001545 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001546 launcherInfo.notifyWidgetSizeChanged(this);
1547
Adam Cohendcd297f2013-06-18 13:13:40 -07001548 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001549 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001550
1551 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001553 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 }
Romain Guycbb89e42009-06-08 15:52:54 -07001555
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1557 @Override
1558 public void onReceive(Context context, Intent intent) {
1559 final String action = intent.getAction();
1560 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1561 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001562 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001563 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001564
Winson Chungc100e8e2011-08-09 16:02:43 -07001565 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001566 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001567 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001568 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001569 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001570 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1571 mUserPresent = true;
1572 updateRunning();
1573 }
1574 }
1575 };
1576
1577 @Override
1578 public void onAttachedToWindow() {
1579 super.onAttachedToWindow();
1580
1581 // Listen for broadcasts related to user-presence
1582 final IntentFilter filter = new IntentFilter();
1583 filter.addAction(Intent.ACTION_SCREEN_OFF);
1584 filter.addAction(Intent.ACTION_USER_PRESENT);
1585 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001586 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001587 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001588 mVisible = true;
1589 }
1590
1591 @Override
1592 public void onDetachedFromWindow() {
1593 super.onDetachedFromWindow();
1594 mVisible = false;
1595
Adam Cohend113e0c2010-11-11 10:48:05 -08001596 if (mAttached) {
1597 unregisterReceiver(mReceiver);
1598 mAttached = false;
1599 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 updateRunning();
1601 }
1602
1603 public void onWindowVisibilityChanged(int visibility) {
1604 mVisible = visibility == View.VISIBLE;
1605 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001606 // The following code used to be in onResume, but it turns out onResume is called when
1607 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1608 // is a more appropriate event to handle
1609 if (mVisible) {
1610 mAppsCustomizeTabHost.onWindowVisible();
1611 if (!mWorkspaceLoading) {
1612 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001613 // We want to let Launcher draw itself at least once before we force it to build
1614 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001615 // apps is nice and speedy.
1616 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001617 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001618 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001619 if (mStarted) return;
1620 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001621 // We delay the layer building a bit in order to give
1622 // other message processing a time to run. In particular
1623 // this avoids a delay in hiding the IME if it was
1624 // currently shown, because doing that may involve
1625 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001626 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001627 final ViewTreeObserver.OnDrawListener listener = this;
1628 mWorkspace.post(new Runnable() {
1629 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001630 if (mWorkspace != null &&
1631 mWorkspace.getViewTreeObserver() != null) {
1632 mWorkspace.getViewTreeObserver().
1633 removeOnDrawListener(listener);
1634 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001635 }
1636 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001637 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001638 }
1639 });
1640 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001641 // When Launcher comes back to foreground, a different Activity might be responsible for
1642 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001643 if (!DISABLE_MARKET_BUTTON) {
1644 updateAppMarketIcon();
1645 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001646 clearTypedText();
1647 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 }
1649
1650 private void sendAdvanceMessage(long delay) {
1651 mHandler.removeMessages(ADVANCE_MSG);
1652 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1653 mHandler.sendMessageDelayed(msg, delay);
1654 mAutoAdvanceSentTime = System.currentTimeMillis();
1655 }
1656
1657 private void updateRunning() {
1658 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1659 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1660 mAutoAdvanceRunning = autoAdvanceRunning;
1661 if (autoAdvanceRunning) {
1662 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1663 sendAdvanceMessage(delay);
1664 } else {
1665 if (!mWidgetsToAdvance.isEmpty()) {
1666 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1667 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1668 }
1669 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001670 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001671 }
1672 }
1673 }
1674
1675 private final Handler mHandler = new Handler() {
1676 @Override
1677 public void handleMessage(Message msg) {
1678 if (msg.what == ADVANCE_MSG) {
1679 int i = 0;
1680 for (View key: mWidgetsToAdvance.keySet()) {
1681 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1682 final int delay = mAdvanceStagger * i;
1683 if (v instanceof Advanceable) {
1684 postDelayed(new Runnable() {
1685 public void run() {
1686 ((Advanceable) v).advance();
1687 }
1688 }, delay);
1689 }
1690 i++;
1691 }
1692 sendAdvanceMessage(mAdvanceInterval);
1693 }
1694 }
1695 };
1696
1697 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001698 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001699 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1700 if (v instanceof Advanceable) {
1701 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001702 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001703 updateRunning();
1704 }
1705 }
1706
1707 void removeWidgetToAutoAdvance(View hostView) {
1708 if (mWidgetsToAdvance.containsKey(hostView)) {
1709 mWidgetsToAdvance.remove(hostView);
1710 updateRunning();
1711 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001712 }
1713
Joe Onorato9c1289c2009-08-17 11:03:03 -04001714 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001715 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001716 launcherInfo.hostView = null;
1717 }
1718
Winson Chung93eef082012-03-23 15:59:27 -07001719 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1720 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1721 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001722 }
1723
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001724 public LauncherAppWidgetHost getAppWidgetHost() {
1725 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 }
Romain Guycbb89e42009-06-08 15:52:54 -07001727
Winson Chunga9abd0e2010-10-27 17:18:37 -07001728 public LauncherModel getModel() {
1729 return mModel;
1730 }
1731
Bjorn Bringertc459e522013-06-07 19:36:01 +01001732 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001733 getWindow().closeAllPanels();
1734
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001735 // Whatever we were doing is hereby canceled.
1736 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001737 }
1738
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739 @Override
1740 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001741 long startTime = 0;
1742 if (DEBUG_RESUME_TIME) {
1743 startTime = System.currentTimeMillis();
1744 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001745 super.onNewIntent(intent);
1746
1747 // Close the menu
1748 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001749 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001750 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001751
Adam Cohened307df2013-10-02 09:37:31 -07001752 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1753 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1754 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001755
Adam Cohen6fecd412013-10-02 17:41:50 -07001756 if (mWorkspace == null) {
1757 // Can be cases where mWorkspace is null, this prevents a NPE
1758 return;
1759 }
1760 Folder openFolder = mWorkspace.getOpenFolder();
1761 // In all these cases, only animate if we're already on home
1762 mWorkspace.exitWidgetResizeMode();
1763 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001764 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001765 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001766 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001767
Adam Cohen6fecd412013-10-02 17:41:50 -07001768 closeFolder();
1769 exitSpringLoadedDragMode();
1770
1771 // If we are already on home, then just animate back to the workspace,
1772 // otherwise, just wait until onResume to set the state back to Workspace
1773 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001774 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001775 } else {
1776 mOnResumeState = State.WORKSPACE;
1777 }
1778
1779 final View v = getWindow().peekDecorView();
1780 if (v != null && v.getWindowToken() != null) {
1781 InputMethodManager imm = (InputMethodManager)getSystemService(
1782 INPUT_METHOD_SERVICE);
1783 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1784 }
1785
1786 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001787 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001788 mAppsCustomizeTabHost.reset();
1789 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001790
1791 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 }
Adam Cohened307df2013-10-02 09:37:31 -07001793
Michael Jurka447bf842013-05-15 14:52:15 +02001794 if (DEBUG_RESUME_TIME) {
1795 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1796 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 }
1798
Adam Coppa120b8e2013-11-12 16:26:04 +00001799 /**
1800 * Override point for subclasses to prevent movement to the default screen when the home
1801 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1802 */
1803 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1804 return true;
1805 }
1806
1807 /**
1808 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1809 */
1810 protected void onHomeIntent() {
1811 // Do nothing
1812 }
1813
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001815 public void onRestoreInstanceState(Bundle state) {
1816 super.onRestoreInstanceState(state);
1817 for (int page: mSynchronouslyBoundPages) {
1818 mWorkspace.restoreInstanceStateForChild(page);
1819 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
1821
1822 @Override
1823 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001824 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001825 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1826 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001827 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001828 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829
Michael Jurka883f55b2010-10-21 15:47:14 -07001830 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001831 // We close any open folder since it will not be re-opened, and we need to make sure
1832 // this state is reflected.
1833 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834
Adam Cohendcd297f2013-06-18 13:13:40 -07001835 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001836 mWaitingForResult) {
1837 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001838 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001839 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1840 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001841 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1842 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1843 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001844 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
1846
1847 if (mFolderInfo != null && mWaitingForResult) {
1848 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1849 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1850 }
Michael Jurka946ad472010-07-09 18:05:18 -07001851
Winson Chung785d2eb2011-04-14 16:08:02 -07001852 // Save the current AppsCustomize tab
1853 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001854 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1855 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001856 if (currentTabTag != null) {
1857 outState.putString("apps_customize_currentTab", currentTabTag);
1858 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001859 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1860 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001861 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001862 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001863 }
1864
1865 @Override
1866 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001867 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001868
Winson Chunge7a03942011-08-05 15:05:12 -07001869 // Remove all pending runnables
1870 mHandler.removeMessages(ADVANCE_MSG);
1871 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001872 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001873
Winson Chungcd2b0142011-06-08 16:02:26 -07001874 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001875 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001876 mModel.stopLoader();
1877 app.setLauncher(null);
1878
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001880 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001882 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001884 mAppWidgetHost = null;
1885
1886 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887
1888 TextKeyListener.getInstance().release();
1889
Winson Chung81b52252012-08-27 15:34:29 -07001890 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1891 // to prevent leaking Launcher activities on orientation change.
1892 if (mModel != null) {
1893 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1894 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001895
1896 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001897 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001898
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001899 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001900 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001901 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001902 mWorkspace = null;
1903 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001904
Michael Jurka2ecf9952012-06-18 12:52:28 -07001905 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 }
1907
Adam Cohena9cf38f2011-05-02 15:36:58 -07001908 public DragController getDragController() {
1909 return mDragController;
1910 }
1911
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001912 @Override
1913 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001914 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 super.startActivityForResult(intent, requestCode);
1916 }
1917
Winson Chung70d72102011-08-12 11:24:35 -07001918 /**
1919 * Indicates that we want global search for this activity by setting the globalSearch
1920 * argument for {@link #startSearch} to true.
1921 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001923 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001925
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001926 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001927
Karl Rosaen138a0412009-04-23 19:00:21 -07001928 if (initialQuery == null) {
1929 // Use any text typed in the launcher as the initial query
1930 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001931 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 if (appSearchData == null) {
1933 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001934 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 }
Winson Chungadf0c182012-08-23 14:59:07 -07001936 Rect sourceBounds = new Rect();
1937 if (mSearchDropTargetBar != null) {
1938 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1939 }
Romain Guycbb89e42009-06-08 15:52:54 -07001940
Bjorn Bringertc459e522013-06-07 19:36:01 +01001941 startSearch(initialQuery, selectInitialQuery,
1942 appSearchData, sourceBounds);
1943 }
1944
1945 public void startSearch(String initialQuery,
1946 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001947 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001948 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001949 }
1950
1951 /**
1952 * Starts the global search activity. This code is a copied from SearchManager
1953 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001954 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001955 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001956 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001957 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1958 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1959 if (globalSearchActivity == null) {
1960 Log.w(TAG, "No global search activity found.");
1961 return;
1962 }
1963 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1964 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1965 intent.setComponent(globalSearchActivity);
1966 // Make sure that we have a Bundle to put source in
1967 if (appSearchData == null) {
1968 appSearchData = new Bundle();
1969 } else {
1970 appSearchData = new Bundle(appSearchData);
1971 }
1972 // Set source to package name of app that starts global search, if not set already.
1973 if (!appSearchData.containsKey("source")) {
1974 appSearchData.putString("source", getPackageName());
1975 }
1976 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1977 if (!TextUtils.isEmpty(initialQuery)) {
1978 intent.putExtra(SearchManager.QUERY, initialQuery);
1979 }
1980 if (selectInitialQuery) {
1981 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1982 }
1983 intent.setSourceBounds(sourceBounds);
1984 try {
1985 startActivity(intent);
1986 } catch (ActivityNotFoundException ex) {
1987 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1988 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 }
1990
Winson Chung70d72102011-08-12 11:24:35 -07001991 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001992 public boolean onPrepareOptionsMenu(Menu menu) {
1993 super.onPrepareOptionsMenu(menu);
Dan Sandler14c6a3f2014-01-07 14:12:27 -05001994 showOverviewMode(true);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001995 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001996 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001998 @Override
1999 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002000 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002001 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002002 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002003 }
2004
Joe Onorato9c1289c2009-08-17 11:03:03 -04002005 public boolean isWorkspaceLocked() {
2006 return mWorkspaceLoading || mWaitingForResult;
2007 }
2008
Michael Jurka0280c3b2010-09-17 15:00:07 -07002009 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002010 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002011 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002012 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2013 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002014 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002015 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002016 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002017
Adam Cohenad4e15c2013-10-17 16:21:35 -07002018 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2019 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2020 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2021 }
2022
2023 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2024 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2025 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002026 if (appWidgetInfo.configure != null) {
2027 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002028 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002029
Bjorn Bringert7984c942009-12-09 15:38:25 +00002030 // Launch over to configure widget, if needed
2031 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002032 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002033 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002034 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002035 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002036 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002037 Runnable onComplete = new Runnable() {
2038 @Override
2039 public void run() {
2040 // Exit spring loaded mode if necessary after adding the widget
2041 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2042 null);
2043 }
2044 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002045 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002046 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002047 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 }
2049 }
Romain Guycbb89e42009-06-08 15:52:54 -07002050
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002051 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002052 // Close any folders that may be open.
2053 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002054 mWorkspace.moveToCustomContentScreen(animate);
2055 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002056 /**
2057 * Process a shortcut drop.
2058 *
2059 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002060 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002061 * @param cell The cell it should be added to, optional
2062 * @param position The location on the screen where it was dropped, optional
2063 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002064 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002065 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002066 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002067 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002068 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002069 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002070
2071 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002072 mPendingAddInfo.cellX = cell[0];
2073 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002074 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002075
2076 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2077 createShortcutIntent.setComponent(componentName);
2078 processShortcut(createShortcutIntent);
2079 }
2080
Adam Cohenfbba09b2011-07-18 21:43:05 -07002081 /**
2082 * Process a widget drop.
2083 *
2084 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002085 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002086 * @param cell The cell it should be added to, optional
2087 * @param position The location on the screen where it was dropped, optional
2088 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002089 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002090 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002091 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002092 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002093 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002094 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002095 mPendingAddInfo.minSpanX = info.minSpanX;
2096 mPendingAddInfo.minSpanY = info.minSpanY;
2097
Adam Cohenfbba09b2011-07-18 21:43:05 -07002098 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002099 mPendingAddInfo.cellX = cell[0];
2100 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002101 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002102 if (span != null) {
2103 mPendingAddInfo.spanX = span[0];
2104 mPendingAddInfo.spanY = span[1];
2105 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002106
Adam Cohened66b2b2012-01-23 17:28:51 -08002107 AppWidgetHostView hostView = info.boundWidget;
2108 int appWidgetId;
2109 if (hostView != null) {
2110 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002111 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002112 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002113 // In this case, we either need to start an activity to get permission to bind
2114 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002115 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002116 Bundle options = info.bindOptions;
2117
2118 boolean success = false;
2119 if (options != null) {
2120 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2121 info.componentName, options);
2122 } else {
2123 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2124 info.componentName);
2125 }
2126 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002127 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002128 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002129 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002130 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2131 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2132 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002133 // TODO: we need to make sure that this accounts for the options bundle.
2134 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002135 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2136 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002137 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002138 }
2139
Joe Onoratodeb98af2010-02-19 14:59:39 -08002140 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002141 // Handle case where user selected "Applications"
2142 String applicationName = getResources().getString(R.string.group_applications);
2143 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002144
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002145 if (applicationName != null && applicationName.equals(shortcutName)) {
2146 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2147 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002148
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002149 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2150 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002151 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002152 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002153 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002154 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002155 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 }
2157
Winson Chung24ab2f12010-09-16 14:10:47 -07002158 void processWallpaper(Intent intent) {
2159 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2160 }
2161
Adam Cohendcd297f2013-06-18 13:13:40 -07002162 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002163 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002164 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165 folderInfo.title = getText(R.string.folder_name);
2166
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002167 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002168 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002169 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002170 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171
2172 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002173 FolderIcon newFolder =
2174 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002175 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002176 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002177 // Force measure the new folder icon
2178 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2179 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002180 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 }
Romain Guycbb89e42009-06-08 15:52:54 -07002182
Joe Onorato9c1289c2009-08-17 11:03:03 -04002183 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002184 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002185 }
2186
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002187 protected void startWallpaper() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002189 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002190 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 }
2192
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002193 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002194 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002195 }
2196
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002197 /**
2198 * Registers various content observers. The current implementation registers
2199 * only a favorites observer to keep track of the favorites applications.
2200 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002201 private void registerContentObservers() {
2202 ContentResolver resolver = getContentResolver();
2203 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2204 true, mWidgetObserver);
2205 }
2206
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002207 @Override
2208 public boolean dispatchKeyEvent(KeyEvent event) {
2209 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2210 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002211 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002212 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002213 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002214 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002215 dumpState();
2216 return true;
2217 }
2218 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002219 }
2220 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2221 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002222 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002223 return true;
2224 }
2225 }
2226
2227 return super.dispatchKeyEvent(event);
2228 }
2229
Joe Onorato88ec0992009-11-19 13:16:06 -08002230 @Override
2231 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002232 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002233 if (mAppsCustomizeContent.getContentType() ==
2234 AppsCustomizePagedView.ContentType.Applications) {
2235 showWorkspace(true);
2236 } else {
2237 showOverviewMode(true);
2238 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002239 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002240 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002241 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002242 Folder openFolder = mWorkspace.getOpenFolder();
2243 if (openFolder.isEditingName()) {
2244 openFolder.dismissEditingName();
2245 } else {
2246 closeFolder();
2247 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002248 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002249 mWorkspace.exitWidgetResizeMode();
2250
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002251 // Back button is a no-op here, but give at least some feedback for the button press
2252 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002253 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002254 }
2255
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002256 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002257 * Re-listen when widgets are reset.
2258 */
2259 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002260 if (mAppWidgetHost != null) {
2261 mAppWidgetHost.startListening();
2262 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002263 }
2264
2265 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002266 * Launches the intent referred by the clicked shortcut.
2267 *
2268 * @param v The view representing the clicked shortcut.
2269 */
2270 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002271 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2272 // view has detached (it's possible for this to happen if the view is removed mid touch).
2273 if (v.getWindowToken() == null) {
2274 return;
2275 }
2276
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002277 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002278 return;
2279 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002280
Adam Cohen1697b792013-09-17 19:08:21 -07002281 if (v instanceof Workspace) {
2282 if (mWorkspace.isInOverviewMode()) {
2283 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002284 }
2285 return;
2286 }
2287
2288 if (v instanceof CellLayout) {
2289 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002290 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002291 }
2292 }
2293
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002294 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002295 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002296 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002297 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2298 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002299
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002300 // Check for special shortcuts
2301 if (intent.getComponent() != null) {
2302 final String shortcutClass = intent.getComponent().getClassName();
2303
2304 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chung82963d52013-10-09 11:20:57 -07002305 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002306 return;
2307 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2308 MemoryDumpActivity.startDump(this);
2309 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002310 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2311 toggleShowWeightWatcher();
2312 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002313 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002314 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002315
2316 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002317 int[] pos = new int[2];
2318 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002319 intent.setSourceBounds(new Rect(pos[0], pos[1],
2320 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002321
2322 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002323
Daniel Sandlerff02d492013-08-05 02:12:05 -04002324 mStats.recordLaunch(intent, shortcut);
2325
Michael Jurkaddd62e92011-02-16 17:49:14 -08002326 if (success && v instanceof BubbleTextView) {
2327 mWaitingForResume = (BubbleTextView) v;
2328 mWaitingForResume.setStayPressed(true);
2329 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002330 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002331 if (v instanceof FolderIcon) {
2332 FolderIcon fi = (FolderIcon) v;
2333 handleFolderClick(fi);
2334 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002335 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002336 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002337 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002338 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002339 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002340 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341 }
2342 }
2343
Michael Jurka0e260592010-06-30 17:07:39 -07002344 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002345 return false;
2346 }
2347
Michael Jurkaaf442092010-06-10 17:01:57 -07002348 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002349 * Event handler for the search button
2350 *
2351 * @param v The view that was clicked.
2352 */
2353 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002354 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2355
Amith Yamasania135ba82011-08-09 17:42:01 -07002356 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002357 }
2358
2359 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002360 * Event handler for the voice button
2361 *
2362 * @param v The view that was clicked.
2363 */
2364 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002365 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002366
Bjorn Bringertc459e522013-06-07 19:36:01 +01002367 startVoice();
2368 }
2369
2370 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002371 try {
2372 final SearchManager searchManager =
2373 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2374 ComponentName activityName = searchManager.getGlobalSearchActivity();
2375 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002376 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002377 if (activityName != null) {
2378 intent.setPackage(activityName.getPackageName());
2379 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002380 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002381 } catch (ActivityNotFoundException e) {
2382 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002383 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002384 startActivitySafely(null, intent, "onClickVoiceButton");
2385 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002386 }
2387
2388 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002389 * Event handler for the "grid" button that appears on the home screen, which
2390 * enters all apps mode.
2391 *
2392 * @param v The view that was clicked.
2393 */
2394 public void onClickAllAppsButton(View v) {
Winson Chunge7e97e62013-12-02 17:02:50 -08002395 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
Michael Jurka5130e402011-10-13 04:55:35 -07002396 }
2397
2398 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002399 // Provide the same haptic feedback that the system offers for virtual keys.
2400 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002401 }
2402
Adam Cohen61f560d2013-09-30 15:58:20 -07002403 public void performHapticFeedbackOnTouchDown(View v) {
2404 // Provide the same haptic feedback that the system offers for virtual keys.
2405 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2406 }
2407
2408 public View.OnTouchListener getHapticFeedbackTouchListener() {
2409 if (mHapticFeedbackTouchListener == null) {
2410 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2411 @Override
2412 public boolean onTouch(View v, MotionEvent event) {
2413 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2414 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2415 }
2416 return false;
2417 }
2418 };
2419 }
2420 return mHapticFeedbackTouchListener;
2421 }
2422
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002423 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002424 if (!DISABLE_MARKET_BUTTON) {
2425 if (mAppMarketIntent != null) {
2426 startActivitySafely(v, mAppMarketIntent, "app market");
2427 } else {
2428 Log.e(TAG, "Invalid app market intent.");
2429 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002430 }
2431 }
2432
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002433 /**
2434 * Called when the user stops interacting with the launcher.
2435 * This implies that the user is now on the homescreen and is not doing housekeeping.
2436 */
2437 protected void onInteractionEnd() {}
2438
2439 /**
2440 * Called when the user starts interacting with the launcher.
2441 * The possible interactions are:
2442 * - open all apps
2443 * - reorder an app shortcut, or a widget
2444 * - open the overview mode.
2445 * This is a good time to stop doing things that only make sense
2446 * when the user is on the homescreen and not doing housekeeping.
2447 */
2448 protected void onInteractionBegin() {}
2449
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002450 void startApplicationDetailsActivity(ComponentName componentName) {
2451 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002452 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2453 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002454 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002455 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002456 }
2457
Michael Jurka1e2f4652013-07-08 18:03:46 -07002458 // returns true if the activity was started
2459 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002460 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002461 // System applications cannot be installed. For now, show a toast explaining that.
2462 // We may give them the option of disabling apps this way.
2463 int messageId = R.string.uninstall_system_app_text;
2464 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002465 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002466 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002467 String packageName = componentName.getPackageName();
2468 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002469 Intent intent = new Intent(
2470 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002471 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2472 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002473 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002474 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002475 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002476 }
2477
Michael Jurka86a720e2012-05-09 11:23:23 -07002478 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002479 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002480
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002481 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002482 // Only launch using the new animation if the shortcut has not opted out (this is a
2483 // private contract between launcher and may be ignored in the future).
2484 boolean useLaunchAnimation = (v != null) &&
2485 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2486 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002487 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2488 v.getMeasuredWidth(), v.getMeasuredHeight());
2489
2490 startActivity(intent, opts.toBundle());
2491 } else {
2492 startActivity(intent);
2493 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002494 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002495 } catch (SecurityException e) {
2496 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002497 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002498 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002499 "or use the exported attribute for this activity. "
2500 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002501 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002502 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002503 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002504
Michael Jurka86a720e2012-05-09 11:23:23 -07002505 boolean startActivitySafely(View v, Intent intent, Object tag) {
2506 boolean success = false;
2507 try {
2508 success = startActivity(v, intent, tag);
2509 } catch (ActivityNotFoundException e) {
2510 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2511 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2512 }
2513 return success;
2514 }
2515
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002517 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002518 Folder openFolder = mWorkspace.getFolderForTag(info);
2519
2520 // If the folder info reports that the associated folder is open, then verify that
2521 // it is actually opened. There have been a few instances where this gets out of sync.
2522 if (info.opened && openFolder == null) {
2523 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002524 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002525 info.opened = false;
2526 }
2527
Adam Cohenfb91f302012-06-11 15:45:18 -07002528 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002529 // Close any open folder
2530 closeFolder();
2531 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002532 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002533 } else {
2534 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002535 int folderScreen;
2536 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002537 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002538 // .. and close it
2539 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002540 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002541 // Close any folder open on the current screen
2542 closeFolder();
2543 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002544 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002545 }
2546 }
2547 }
2548 }
2549
Adam Cohen268c4752012-06-06 17:47:33 -07002550 /**
2551 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2552 * in the DragLayer in the exact absolute location of the original FolderIcon.
2553 */
2554 private void copyFolderIconToImage(FolderIcon fi) {
2555 final int width = fi.getMeasuredWidth();
2556 final int height = fi.getMeasuredHeight();
2557
2558 // Lazy load ImageView, Bitmap and Canvas
2559 if (mFolderIconImageView == null) {
2560 mFolderIconImageView = new ImageView(this);
2561 }
2562 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2563 mFolderIconBitmap.getHeight() != height) {
2564 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2565 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2566 }
2567
2568 DragLayer.LayoutParams lp;
2569 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2570 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2571 } else {
2572 lp = new DragLayer.LayoutParams(width, height);
2573 }
2574
Adam Cohen307fe232012-08-16 17:55:58 -07002575 // The layout from which the folder is being opened may be scaled, adjust the starting
2576 // view size by this scale factor.
2577 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002578 lp.customPosition = true;
2579 lp.x = mRectForFolderAnimation.left;
2580 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002581 lp.width = (int) (scale * width);
2582 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002583
2584 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2585 fi.draw(mFolderIconCanvas);
2586 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002587 if (fi.getFolder() != null) {
2588 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2589 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002590 }
Adam Cohen268c4752012-06-06 17:47:33 -07002591 // Just in case this image view is still in the drag layer from a previous animation,
2592 // we remove it and re-add it.
2593 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2594 mDragLayer.removeView(mFolderIconImageView);
2595 }
2596 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002597 if (fi.getFolder() != null) {
2598 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002599 }
Adam Cohen268c4752012-06-06 17:47:33 -07002600 }
2601
Adam Cohen2801caf2011-05-13 20:57:39 -07002602 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002603 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002604 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2605 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2606 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2607
Adam Cohenc51934b2011-07-26 21:07:43 -07002608 FolderInfo info = (FolderInfo) fi.getTag();
2609 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2610 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002611 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2612 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002613 }
2614
Adam Cohen268c4752012-06-06 17:47:33 -07002615 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2616 copyFolderIconToImage(fi);
2617 fi.setVisibility(View.INVISIBLE);
2618
Michael Jurka2ecf9952012-06-18 12:52:28 -07002619 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002620 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002621 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2622 oa.start();
2623 }
2624
Adam Cohen268c4752012-06-06 17:47:33 -07002625 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002626 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002627 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2628 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2629 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2630
Adam Cohen268c4752012-06-06 17:47:33 -07002631 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002632
Adam Cohen268c4752012-06-06 17:47:33 -07002633 // We remove and re-draw the FolderIcon in-case it has changed
2634 mDragLayer.removeView(mFolderIconImageView);
2635 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002636 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002637 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002638 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002639 oa.addListener(new AnimatorListenerAdapter() {
2640 @Override
2641 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002642 if (cl != null) {
2643 cl.clearFolderLeaveBehind();
2644 // Remove the ImageView copy of the FolderIcon and make the original visible.
2645 mDragLayer.removeView(mFolderIconImageView);
2646 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002647 }
2648 }
2649 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002650 oa.start();
2651 }
2652
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002653 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002654 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002655 * is animated relative to the specified View. If the View is null, no animation
2656 * is played.
2657 *
2658 * @param folderInfo The FolderInfo describing the folder to open.
2659 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002660 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002661 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002662 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002663
Adam Cohena9cf38f2011-05-02 15:36:58 -07002664 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002665
Adam Cohen4554ee12011-08-03 16:13:21 -07002666 // Just verify that the folder hasn't already been added to the DragLayer.
2667 // There was a one-off crash where the folder had a parent already.
2668 if (folder.getParent() == null) {
2669 mDragLayer.addView(folder);
2670 mDragController.addDropTarget((DropTarget) folder);
2671 } else {
2672 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2673 folder.getParent() + ").");
2674 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002675 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002676 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002677
2678 // Notify the accessibility manager that this folder "window" has appeared and occluded
2679 // the workspace items
2680 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2681 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002682 }
2683
2684 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002685 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002686 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002687 if (folder.isEditingName()) {
2688 folder.dismissEditingName();
2689 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002690 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002691
2692 // Dismiss the folder cling
2693 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002694 }
2695 }
2696
2697 void closeFolder(Folder folder) {
2698 folder.getInfo().opened = false;
2699
2700 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2701 if (parent != null) {
2702 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2703 shrinkAndFadeInFolderIcon(fi);
2704 }
2705 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002706
2707 // Notify the accessibility manager that this folder "window" has disappeard and no
2708 // longer occludeds the workspace items
2709 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002710 }
2711
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002712 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002713 if (!isDraggingEnabled()) return false;
2714 if (isWorkspaceLocked()) return false;
2715 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002716
Adam Cohen1697b792013-09-17 19:08:21 -07002717 if (v instanceof Workspace) {
2718 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002719 if (mWorkspace.enterOverviewMode()) {
2720 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2721 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2722 return true;
2723 } else {
2724 return false;
2725 }
Adam Cohen1697b792013-09-17 19:08:21 -07002726 }
Adam Cohen1697b792013-09-17 19:08:21 -07002727 }
2728
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002729 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002730 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002731 }
2732
Michael Jurka0280c3b2010-09-17 15:00:07 -07002733 resetAddInfo();
2734 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002735 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002736 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002737 return true;
2738 }
2739
Winson Chung3d503fb2011-07-13 17:25:49 -07002740 // The hotseat touch handling does not go through Workspace, and we always allow long press
2741 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002742 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002743 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2744 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002745 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002746 // User long pressed on empty space
2747 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2748 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2749 // Disabling reordering until we sort out some issues.
2750 if (mWorkspace.isInOverviewMode()) {
2751 mWorkspace.startReordering(v);
2752 } else {
2753 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002754 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002755 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002756 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002757 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002758 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002759 }
2760 }
2761 }
2762 return true;
2763 }
2764
Winson Chung3d503fb2011-07-13 17:25:49 -07002765 boolean isHotseatLayout(View layout) {
2766 return mHotseat != null && layout != null &&
2767 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2768 }
2769 Hotseat getHotseat() {
2770 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002771 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002772 View getOverviewPanel() {
2773 return mOverviewPanel;
2774 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002775 SearchDropTargetBar getSearchBar() {
2776 return mSearchDropTargetBar;
2777 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002778
Winson Chung3d503fb2011-07-13 17:25:49 -07002779 /**
2780 * Returns the CellLayout of the specified container at the specified screen.
2781 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002782 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002783 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2784 if (mHotseat != null) {
2785 return mHotseat.getLayout();
2786 } else {
2787 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002788 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002789 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002790 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002791 }
2792 }
2793
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002794 Workspace getWorkspace() {
2795 return mWorkspace;
2796 }
2797
Daniel Sandler843e8602010-06-07 14:59:01 -04002798 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002799 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002800 }
2801
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002802 /**
2803 * Helper method for the cameraZoomIn/cameraZoomOut animations
2804 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002805 * @param scaleFactor The scale factor used for the zoom
2806 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002807 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002808 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002809 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002810 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002811
Craig Mautner360310b2012-10-26 15:13:08 -07002812 private void setWorkspaceBackground(boolean workspace) {
2813 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002814 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002815 }
2816
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002817 void updateWallpaperVisibility(boolean visible) {
2818 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2819 int curflags = getWindow().getAttributes().flags
2820 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2821 if (wpflags != curflags) {
2822 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2823 }
Craig Mautner360310b2012-10-26 15:13:08 -07002824 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002825 }
2826
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002827 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2828 if (v instanceof LauncherTransitionable) {
2829 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2830 }
2831 }
2832
Michael Jurkabed61d22012-02-14 22:51:29 -08002833 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2834 if (v instanceof LauncherTransitionable) {
2835 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2836 }
Winson Chung70442722012-02-10 15:43:22 -08002837
2838 // Update the workspace transition step as well
2839 dispatchOnLauncherTransitionStep(v, 0f);
2840 }
2841
2842 private void dispatchOnLauncherTransitionStep(View v, float t) {
2843 if (v instanceof LauncherTransitionable) {
2844 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2845 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002846 }
2847
2848 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2849 if (v instanceof LauncherTransitionable) {
2850 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2851 }
Winson Chung70442722012-02-10 15:43:22 -08002852
2853 // Update the workspace transition step as well
2854 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002855 }
2856
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002857 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002858 * Things to test when changing the following seven functions.
2859 * - Home from workspace
2860 * - from center screen
2861 * - from other screens
2862 * - Home from all apps
2863 * - from center screen
2864 * - from other screens
2865 * - Back from all apps
2866 * - from center screen
2867 * - from other screens
2868 * - Launch app from workspace and quit
2869 * - with back
2870 * - with home
2871 * - Launch app from all apps and quit
2872 * - with back
2873 * - with home
2874 * - Go to a screen that's not the default, then all
2875 * apps, and launch and app, and go back
2876 * - with back
2877 * -with home
2878 * - On workspace, long press power and go back
2879 * - with back
2880 * - with home
2881 * - On all apps, long press power and go back
2882 * - with back
2883 * - with home
2884 * - On workspace, power off
2885 * - On all apps, power off
2886 * - Launch an app and turn off the screen while in that app
2887 * - Go back with home key
2888 * - Go back with back key TODO: make this not go to workspace
2889 * - From all apps
2890 * - From workspace
2891 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2892 * - From all apps
2893 * - From the center workspace
2894 * - From another workspace
2895 */
2896
2897 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002898 * Zoom the camera out from the workspace to reveal 'toView'.
2899 * Assumes that the view to show is anchored at either the very top or very bottom
2900 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002901 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002902 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002903 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2904 showAppsCustomizeHelper(animated, springLoaded, contentType);
2905 }
2906 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2907 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002908 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002909 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002910 mStateAnimation.cancel();
2911 mStateAnimation = null;
2912 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002913 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002914
Winson Chungf0ea4d32011-06-06 14:27:16 -07002915 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2916 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2917 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002918 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002919 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002920 final int startDelay =
2921 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002922
Michael Jurkab3e22d92011-10-31 15:58:33 -07002923 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002924
Michael Jurkad74c9842011-07-10 12:44:21 -07002925 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002926 Animator workspaceAnim =
2927 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08002928 if (!AppsCustomizePagedView.DISABLE_ALL_APPS
2929 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
2930 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07002931 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2932 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002933
2934 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002935 toView.setScaleX(scale);
2936 toView.setScaleY(scale);
2937 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2938 scaleAnim.
2939 scaleX(1f).scaleY(1f).
2940 setDuration(duration).
2941 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002942
Winson Chungf0ea4d32011-06-06 14:27:16 -07002943 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002944 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002945 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002946 .ofFloat(toView, "alpha", 0f, 1f)
2947 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002948 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002949 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2950 @Override
2951 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002952 if (animation == null) {
2953 throw new RuntimeException("animation is null");
2954 }
Winson Chung70442722012-02-10 15:43:22 -08002955 float t = (Float) animation.getAnimatedValue();
2956 dispatchOnLauncherTransitionStep(fromView, t);
2957 dispatchOnLauncherTransitionStep(toView, t);
2958 }
2959 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002960
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002961 // toView should appear right at the end of the workspace shrink
2962 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002963 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002964 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002965 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002966
2967 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002968 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002969 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002970 // Prepare the position
2971 toView.setTranslationX(0.0f);
2972 toView.setTranslationY(0.0f);
2973 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002974 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002975 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002976 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002977 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002978 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2979 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002980
Winson Chungc7d2b602012-05-16 17:02:20 -07002981 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002982 if (mSearchDropTargetBar != null) {
2983 mSearchDropTargetBar.hideSearchBar(false);
2984 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002985 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002986 });
2987
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002988 if (workspaceAnim != null) {
2989 mStateAnimation.play(workspaceAnim);
2990 }
Michael Jurka1899a362011-11-03 13:50:45 -07002991
2992 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002993
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002994 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2995 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002996
2997 // If any of the objects being animated haven't been measured/laid out
2998 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002999 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003000 (mWorkspace.getMeasuredWidth() == 0) ||
3001 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003002 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003003 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003004
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003005 final AnimatorSet stateAnimation = mStateAnimation;
3006 final Runnable startAnimRunnable = new Runnable() {
3007 public void run() {
3008 // Check that mStateAnimation hasn't changed while
3009 // we waited for a layout/draw pass
3010 if (mStateAnimation != stateAnimation)
3011 return;
3012 setPivotsForZoom(toView, scale);
3013 dispatchOnLauncherTransitionStart(fromView, animated, false);
3014 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003015 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003016 }
3017 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003018 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003019 final ViewTreeObserver observer = toView.getViewTreeObserver();
3020 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3021 public void onGlobalLayout() {
3022 startAnimRunnable.run();
3023 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3024 }
3025 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003026 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003027 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003028 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003029 } else {
3030 toView.setTranslationX(0.0f);
3031 toView.setTranslationY(0.0f);
3032 toView.setScaleX(1.0f);
3033 toView.setScaleY(1.0f);
3034 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003035 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003036
Daniel Sandlere4f98912013-06-25 15:13:26 -04003037 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003038 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003039 if (mSearchDropTargetBar != null) {
3040 mSearchDropTargetBar.hideSearchBar(false);
3041 }
Michael Jurkaabded662011-03-04 12:06:57 -08003042 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003043 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003044 dispatchOnLauncherTransitionStart(fromView, animated, false);
3045 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003046 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003047 dispatchOnLauncherTransitionStart(toView, animated, false);
3048 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003049 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003050 }
3051
3052 /**
3053 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003054 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003055 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003056 */
Adam Cohened307df2013-10-02 09:37:31 -07003057 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003058 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003059
Michael Jurkab3e22d92011-10-31 15:58:33 -07003060 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003061 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003062 mStateAnimation.cancel();
3063 mStateAnimation = null;
3064 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003065 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003066
Winson Chungf0ea4d32011-06-06 14:27:16 -07003067 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003068 final int fadeOutDuration =
3069 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003070 final float scaleFactor = (float)
3071 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3072 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003073 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003074 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003075 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003076 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3077 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003078 toState, animated, stagger, -1);
3079 } else if (toState == Workspace.State.SPRING_LOADED ||
3080 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003081 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003082 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003083 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003084
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003086 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003087 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003088 final LauncherViewPropertyAnimator scaleAnim =
3089 new LauncherViewPropertyAnimator(fromView);
3090 scaleAnim.
3091 scaleX(scaleFactor).scaleY(scaleFactor).
3092 setDuration(duration).
3093 setInterpolator(new Workspace.ZoomInInterpolator());
3094
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003095 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003096 .ofFloat(fromView, "alpha", 1f, 0f)
3097 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003098 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003099 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3100 @Override
3101 public void onAnimationUpdate(ValueAnimator animation) {
3102 float t = 1f - (Float) animation.getAnimatedValue();
3103 dispatchOnLauncherTransitionStep(fromView, t);
3104 dispatchOnLauncherTransitionStep(toView, t);
3105 }
3106 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003107
Michael Jurka2ecf9952012-06-18 12:52:28 -07003108 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003109
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003110 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3111 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003112 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003113
3114 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003115 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003116 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003117 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003118 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3119 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003120 if (onCompleteRunnable != null) {
3121 onCompleteRunnable.run();
3122 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003123 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003124 }
3125 });
3126
Winson Chungf0ea4d32011-06-06 14:27:16 -07003127 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003128 if (workspaceAnim != null) {
3129 mStateAnimation.play(workspaceAnim);
3130 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003131 dispatchOnLauncherTransitionStart(fromView, animated, true);
3132 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003133 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003134 } else {
3135 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003136 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003137 dispatchOnLauncherTransitionStart(fromView, animated, true);
3138 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003139 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003140 dispatchOnLauncherTransitionStart(toView, animated, true);
3141 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003142 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003143 }
3144
Michael Jurkae326f182011-11-21 14:05:46 -08003145 @Override
3146 public void onTrimMemory(int level) {
3147 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003148 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003149 mAppsCustomizeTabHost.onTrimMemory();
3150 }
3151 }
3152
Adam Cohened307df2013-10-02 09:37:31 -07003153 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003154 showWorkspace(animated, null);
3155 }
3156
Adam Cohened307df2013-10-02 09:37:31 -07003157 protected void showWorkspace() {
3158 showWorkspace(true);
3159 }
3160
Adam Cohened66b2b2012-01-23 17:28:51 -08003161 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003162 if (mWorkspace.isInOverviewMode()) {
3163 mWorkspace.exitOverviewMode(animated);
3164 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003165 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003166 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003167 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003168 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003169
Winson Chungc7d2b602012-05-16 17:02:20 -07003170 // Show the search bar (only animate if we were showing the drop target bar in spring
3171 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003172 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003173 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003174 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003175
Michael Jurkab3e22d92011-10-31 15:58:33 -07003176 // Set focus to the AppsCustomize button
3177 if (mAllAppsButton != null) {
3178 mAllAppsButton.requestFocus();
3179 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003180 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003181
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003182 // Change the state *after* we've called all the transition code
3183 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003184
Winson Chung5fb63472011-02-02 17:03:37 -08003185 // Resume the auto-advance of widgets
3186 mUserPresent = true;
3187 updateRunning();
3188
alanv1d4fde62012-10-17 13:15:47 -07003189 // Send an accessibility event to announce the context change
3190 getWindow().getDecorView()
3191 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003192
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003193 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003194 }
3195
Adam Cohened307df2013-10-02 09:37:31 -07003196 void showOverviewMode(boolean animated) {
3197 mWorkspace.setVisibility(View.VISIBLE);
3198 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3199 mState = State.WORKSPACE;
3200 onWorkspaceShown(animated);
3201 }
3202
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003203 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003204 }
3205
Winson Chung82963d52013-10-09 11:20:57 -07003206 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3207 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003208 if (mState != State.WORKSPACE) return;
3209
Winson Chung82963d52013-10-09 11:20:57 -07003210 if (resetPageToZero) {
3211 mAppsCustomizeTabHost.reset();
3212 }
Winson Chungc58497e2013-09-03 17:48:37 -07003213 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003214 mAppsCustomizeTabHost.requestFocus();
3215
Michael Jurkab3e22d92011-10-31 15:58:33 -07003216 // Change the state *after* we've called all the transition code
3217 mState = State.APPS_CUSTOMIZE;
3218
3219 // Pause the auto-advance of widgets until we are out of AllApps
3220 mUserPresent = false;
3221 updateRunning();
3222 closeFolder();
3223
3224 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003225 getWindow().getDecorView()
3226 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003227 }
3228
Adam Cohen7777d962011-08-18 18:58:38 -07003229 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003230 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003231 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003232 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003233 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003234 }
Adam Cohen7777d962011-08-18 18:58:38 -07003235
Adam Cohenad4e15c2013-10-17 16:21:35 -07003236 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003237 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003238 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3239
Winson Chunge7a03942011-08-05 15:05:12 -07003240 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003241 @Override
3242 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003243 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003244 // Before we show workspace, hide all apps again because
3245 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3246 // clean up our state transition functions
3247 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003248 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003249 } else {
3250 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003251 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003252 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003253 }, delay);
3254
Winson Chung557d6ed2011-07-08 15:34:52 -07003255 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003256
Michael Jurkad3ef3062010-11-23 16:23:58 -08003257 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003258 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003259 final boolean animated = true;
3260 final boolean springLoaded = true;
3261 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003262 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003263 }
3264 // Otherwise, we are not in spring loaded mode, so don't do anything.
3265 }
3266
Michael Jurkab3e22d92011-10-31 15:58:33 -07003267 void lockAllApps() {
3268 // TODO
3269 }
3270
3271 void unlockAllApps() {
3272 // TODO
3273 }
3274
Winson Chungf0ea4d32011-06-06 14:27:16 -07003275 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003276 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003277 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003278 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003279 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003280 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003281 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003282 int duration = 0;
3283 if (mSearchDropTargetBar != null) {
3284 duration = mSearchDropTargetBar.getTransitionInDuration();
3285 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003286 mHotseat.animate().alpha(1f).setDuration(duration);
3287 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003288 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003289 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003290 }
3291 }
3292 }
3293
3294 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003295 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003296 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003297 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003298 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003299 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003300 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003301 int duration = 0;
3302 if (mSearchDropTargetBar != null) {
3303 duration = mSearchDropTargetBar.getTransitionOutDuration();
3304 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003305 mHotseat.animate().alpha(0f).setDuration(duration);
3306 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003307 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003308 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003309 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003310 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003311 }
3312
Patrick Dubroy5f445422011-02-18 14:35:21 -08003313 /**
3314 * Add an item from all apps or customize onto the given workspace screen.
3315 * If layout is null, add to the current screen.
3316 */
3317 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003318 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003319 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003320 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003321 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003322
Winson Chungdff8ebb2011-09-08 17:25:31 -07003323 /** Maps the current orientation to an index for referencing orientation correct global icons */
3324 private int getCurrentOrientationIndexForGlobalIcons() {
3325 // default - 0, landscape - 1
3326 switch (getResources().getConfiguration().orientation) {
3327 case Configuration.ORIENTATION_LANDSCAPE:
3328 return 1;
3329 default:
3330 return 0;
3331 }
3332 }
3333
Michael Jurkaae65ee32012-04-30 11:45:54 -07003334 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003335 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003336 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003337 // Look for the toolbar icon specified in the activity meta-data
3338 Bundle metaData = packageManager.getActivityInfo(
3339 activityName, PackageManager.GET_META_DATA).metaData;
3340 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003341 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003342 if (iconResId != 0) {
3343 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003344 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003345 }
3346 }
3347 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003348 // This can happen if the activity defines an invalid drawable
3349 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3350 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003351 } catch (Resources.NotFoundException nfe) {
3352 // This can happen if the activity defines an invalid drawable
3353 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3354 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003355 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003356 return null;
3357 }
3358
3359 // if successful in getting icon, return it; otherwise, set button to use default drawable
3360 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003361 int buttonId, ComponentName activityName, int fallbackDrawableId,
3362 String toolbarResourceName) {
3363 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003364 Resources r = getResources();
3365 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3366 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003367
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003368 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003369 // If we were unable to find the icon via the meta-data, use a generic one
3370 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003371 toolbarIcon = r.getDrawable(fallbackDrawableId);
3372 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003373 if (button != null) {
3374 button.setCompoundDrawables(toolbarIcon, null, null, null);
3375 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003376 return null;
3377 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003378 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003379 if (button != null) {
3380 button.setCompoundDrawables(toolbarIcon, null, null, null);
3381 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003382 return toolbarIcon.getConstantState();
3383 }
3384 }
3385
3386 // if successful in getting icon, return it; otherwise, set button to use default drawable
3387 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003388 int buttonId, ComponentName activityName, int fallbackDrawableId,
3389 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003390 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003391 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003392
Michael Jurka19e0fc52011-07-22 18:00:21 -07003393 if (button != null) {
3394 // If we were unable to find the icon via the meta-data, use a
3395 // generic one
3396 if (toolbarIcon == null) {
3397 button.setImageResource(fallbackDrawableId);
3398 } else {
3399 button.setImageDrawable(toolbarIcon);
3400 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003401 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003402
3403 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3404
Michael Jurka0423dcf2010-10-05 14:56:18 -07003405 }
3406
Winson Chung1b884092012-06-08 17:13:02 -07003407 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003408 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003409 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003410 }
3411
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003412 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003413 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003414 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003415 }
3416
Winson Chungbb185bd2011-11-21 12:31:42 -08003417 private void invalidatePressedFocusedStates(View container, View button) {
3418 if (container instanceof HolographicLinearLayout) {
3419 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3420 layout.invalidatePressedFocusedStates();
3421 } else if (button instanceof HolographicImageView) {
3422 HolographicImageView view = (HolographicImageView) button;
3423 view.invalidatePressedFocusedStates();
3424 }
3425 }
3426
Cristina Stancu476493b2013-08-07 17:20:14 +01003427 public View getQsbBar() {
3428 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003429 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3430 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003431 }
3432 return mQsbBar;
3433 }
3434
3435 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003436 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003437 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003438 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003439 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003440
Winson Chung1cad91e2011-05-25 17:41:01 -07003441 final SearchManager searchManager =
3442 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3443 ComponentName activityName = searchManager.getGlobalSearchActivity();
3444 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003445 int coi = getCurrentOrientationIndexForGlobalIcons();
3446 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003447 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3448 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3449 if (sGlobalSearchIcon[coi] == null) {
3450 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3451 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3452 TOOLBAR_ICON_METADATA_NAME);
3453 }
3454
Winson Chungc51db6a2011-10-05 11:44:49 -07003455 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3456 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003457 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003458 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003459 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003460 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003461 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3462 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003463 if (searchButton != null) searchButton.setVisibility(View.GONE);
3464 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003465 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003466 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003467 }
3468 }
3469
Cristina Stancu476493b2013-08-07 17:20:14 +01003470 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003471 final View searchButtonContainer = findViewById(R.id.search_button_container);
3472 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003473 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003474 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003475 }
3476
Cristina Stancu476493b2013-08-07 17:20:14 +01003477 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003478 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003479 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003480
Winson Chungc51db6a2011-10-05 11:44:49 -07003481 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003482 final SearchManager searchManager =
3483 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3484 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3485
3486 ComponentName activityName = null;
3487 if (globalSearchActivity != null) {
3488 // Check if the global search activity handles voice search
3489 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3490 intent.setPackage(globalSearchActivity.getPackageName());
3491 activityName = intent.resolveActivity(getPackageManager());
3492 }
3493
3494 if (activityName == null) {
3495 // Fallback: check if an activity other than the global search activity
3496 // resolves this
3497 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3498 activityName = intent.resolveActivity(getPackageManager());
3499 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003500 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003501 int coi = getCurrentOrientationIndexForGlobalIcons();
3502 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003503 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3504 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3505 if (sVoiceSearchIcon[coi] == null) {
3506 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3507 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3508 TOOLBAR_ICON_METADATA_NAME);
3509 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003510 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003511 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003512 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003513 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003514 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003515 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003516 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003517 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003518 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003519 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003520 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003521 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003522
Cristina Stancu476493b2013-08-07 17:20:14 +01003523 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003524 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3525 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003526 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003527 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003528 }
3529
Winson Chung5841efa2013-09-30 18:06:44 -07003530 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003531 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3532 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003533 boolean visible = !forceDisableVoiceButtonProxy &&
3534 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003535 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003536 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003537 }
3538 }
Winson Chung5841efa2013-09-30 18:06:44 -07003539
3540 /**
3541 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3542 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3543 */
3544 public void disableVoiceButtonProxy(boolean disabled) {
3545 updateVoiceButtonProxyVisible(disabled);
3546 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003547 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003548 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003549 */
3550 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003551 if (!DISABLE_MARKET_BUTTON) {
3552 final View marketButton = findViewById(R.id.market_button);
3553 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3554 // Find the app market activity by resolving an intent.
3555 // (If multiple app markets are installed, it will return the ResolverActivity.)
3556 ComponentName activityName = intent.resolveActivity(getPackageManager());
3557 if (activityName != null) {
3558 int coi = getCurrentOrientationIndexForGlobalIcons();
3559 mAppMarketIntent = intent;
3560 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3561 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3562 TOOLBAR_ICON_METADATA_NAME);
3563 marketButton.setVisibility(View.VISIBLE);
3564 } else {
3565 // We should hide and disable the view so that we don't try and restore the visibility
3566 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3567 marketButton.setVisibility(View.GONE);
3568 marketButton.setEnabled(false);
3569 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003570 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003571 }
3572
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003573 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003574 if (!DISABLE_MARKET_BUTTON) {
3575 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3576 Resources r = getResources();
3577 Drawable marketIconDrawable = d.newDrawable(r);
3578 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3579 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3580 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003581
Winson Chungd64a6662013-09-30 11:06:59 -07003582 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3583 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003584 }
3585
Michael Jurkad7c28052012-04-27 15:43:36 -07003586 @Override
3587 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003588 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003589 final List<CharSequence> text = event.getText();
3590 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003591 // Populate event with a fake title based on the current state.
3592 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003593 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003594 } else {
3595 text.add(getString(R.string.all_apps_home_button_label));
3596 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003597 return result;
3598 }
3599
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003600 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003601 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003602 */
3603 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3604 @Override
3605 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003606 closeSystemDialogs();
3607 }
3608 }
3609
3610 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003611 * Receives notifications whenever the appwidgets are reset.
3612 */
3613 private class AppWidgetResetObserver extends ContentObserver {
3614 public AppWidgetResetObserver() {
3615 super(new Handler());
3616 }
3617
3618 @Override
3619 public void onChange(boolean selfChange) {
3620 onAppWidgetReset();
3621 }
3622 }
3623
3624 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003625 * If the activity is currently paused, signal that we need to run the passed Runnable
3626 * in onResume.
3627 *
3628 * This needs to be called from incoming places where resources might have been loaded
3629 * while we are paused. That is becaues the Configuration might be wrong
3630 * when we're not running, and if it comes back to what it was when we
3631 * were paused, we are not restarted.
3632 *
3633 * Implementation of the method from LauncherModel.Callbacks.
3634 *
3635 * @return true if we are currently paused. The caller might be able to
3636 * skip some work in that case since we will come back again.
3637 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003638 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003639 if (mPaused) {
3640 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003641 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003642 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003643 }
3644 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003645 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003646 return true;
3647 } else {
3648 return false;
3649 }
3650 }
3651
Michael Jurkac402cd92013-05-20 15:49:32 +02003652 private boolean waitUntilResume(Runnable run) {
3653 return waitUntilResume(run, false);
3654 }
3655
Michael Jurka1e2f4652013-07-08 18:03:46 -07003656 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003657 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003658 }
3659
Michael Jurka7607c2f2013-04-03 14:33:19 -07003660 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003661 * If the activity is currently paused, signal that we need to re-run the loader
3662 * in onResume.
3663 *
3664 * This needs to be called from incoming places where resources might have been loaded
3665 * while we are paused. That is becaues the Configuration might be wrong
3666 * when we're not running, and if it comes back to what it was when we
3667 * were paused, we are not restarted.
3668 *
3669 * Implementation of the method from LauncherModel.Callbacks.
3670 *
3671 * @return true if we are currently paused. The caller might be able to
3672 * skip some work in that case since we will come back again.
3673 */
3674 public boolean setLoadOnResume() {
3675 if (mPaused) {
3676 Log.i(TAG, "setLoadOnResume");
3677 mOnResumeNeedsLoad = true;
3678 return true;
3679 } else {
3680 return false;
3681 }
3682 }
3683
3684 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003685 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003686 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003687 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003688 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003689 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003690 } else {
3691 return SCREEN_COUNT / 2;
3692 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003693 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003694
Joe Onorato9c1289c2009-08-17 11:03:03 -04003695 /**
3696 * Refreshes the shortcuts shown on the workspace.
3697 *
3698 * Implementation of the method from LauncherModel.Callbacks.
3699 */
3700 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003701 // If we're starting binding all over again, clear any bind calls we'd postponed in
3702 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3703 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003704 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003705
Winson Chungd64d1762013-08-20 14:37:16 -07003706 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003707 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003708 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003709
Michael Jurka05bf644e2011-11-30 20:28:53 -08003710 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003711 if (mHotseat != null) {
3712 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003713 }
3714 }
3715
Adam Cohendcd297f2013-06-18 13:13:40 -07003716 @Override
3717 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003718 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003719
Adam Cohen5084cba2013-09-03 12:01:16 -07003720 // If there are no screens, we need to have an empty screen
3721 if (orderedScreenIds.size() == 0) {
3722 mWorkspace.addExtraEmptyScreen();
3723 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003724
3725 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003726 // setCurrentPage() so ensure that all pages are added before calling this).
3727 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003728 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3729 mWorkspace.createCustomContentPage();
3730 }
Winson Chung64359a52013-07-08 17:17:08 -07003731 }
3732
3733 @Override
3734 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003735 // Log to disk
3736 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3737 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3738 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003739 int count = orderedScreenIds.size();
3740 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003741 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003742 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003743 }
3744
Adam Cohen39a06042013-07-19 14:30:12 -07003745 private boolean shouldShowWeightWatcher() {
3746 String spKey = LauncherAppState.getSharedPreferencesKey();
3747 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003748 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003749
3750 return show;
3751 }
3752
3753 private void toggleShowWeightWatcher() {
3754 String spKey = LauncherAppState.getSharedPreferencesKey();
3755 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3756 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3757
3758 show = !show;
3759
3760 SharedPreferences.Editor editor = sp.edit();
3761 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3762 editor.commit();
3763
3764 if (mWeightWatcher != null) {
3765 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3766 }
3767 }
3768
Winson Chungd64d1762013-08-20 14:37:16 -07003769 public void bindAppsAdded(final ArrayList<Long> newScreens,
3770 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003771 final ArrayList<ItemInfo> addAnimated,
3772 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003773 Runnable r = new Runnable() {
3774 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003775 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003776 }
3777 };
3778 if (waitUntilResume(r)) {
3779 return;
3780 }
3781
Winson Chungd64d1762013-08-20 14:37:16 -07003782 // Add the new screens
3783 bindAddScreens(newScreens);
3784
3785 // We add the items without animation on non-visible pages, and with
3786 // animations on the new page (which we will try and snap to).
3787 if (!addNotAnimated.isEmpty()) {
3788 bindItems(addNotAnimated, 0,
3789 addNotAnimated.size(), false);
3790 }
3791 if (!addAnimated.isEmpty()) {
3792 bindItems(addAnimated, 0,
3793 addAnimated.size(), true);
3794 }
Winson Chungc58497e2013-09-03 17:48:37 -07003795
Winson Chung87412982013-10-03 18:34:14 -07003796 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003797 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003798
Winson Chungc58497e2013-09-03 17:48:37 -07003799 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3800 addedApps != null && mAppsCustomizeContent != null) {
3801 mAppsCustomizeContent.addApps(addedApps);
3802 }
Winson Chungd64d1762013-08-20 14:37:16 -07003803 }
3804
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003805 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003806 * Bind the items start-end from the list.
3807 *
3808 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003809 */
Winson Chung64359a52013-07-08 17:17:08 -07003810 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3811 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003812 Runnable r = new Runnable() {
3813 public void run() {
3814 bindItems(shortcuts, start, end, forceAnimateIcons);
3815 }
3816 };
3817 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003818 return;
3819 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003820
Winson Chungf0c6ae02012-03-21 16:10:31 -07003821 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003822 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3823 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003824 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003825 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003826 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003827 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003828 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003829
3830 // Short circuit if we are loading dock items for a configuration which has no dock
3831 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3832 mHotseat == null) {
3833 continue;
3834 }
3835
Joe Onorato9c1289c2009-08-17 11:03:03 -04003836 switch (item.itemType) {
3837 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3838 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003839 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003840 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003841
Winson Chung64359a52013-07-08 17:17:08 -07003842 /*
3843 * TODO: FIX collision case
3844 */
Winson Chungce376632013-07-11 16:12:41 -07003845 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3846 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3847 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3848 throw new RuntimeException("OCCUPIED");
3849 }
Winson Chung64359a52013-07-08 17:17:08 -07003850 }
3851
Adam Cohendcd297f2013-06-18 13:13:40 -07003852 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3853 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003854 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003855 // Animate all the applications up now
3856 shortcut.setAlpha(0f);
3857 shortcut.setScaleX(0f);
3858 shortcut.setScaleY(0f);
3859 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003860 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003861 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003862 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003863 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003864 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003865 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003866 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003867 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3868 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003869 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003870 default:
3871 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003872 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003873 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003874
Winson Chung997a9232013-07-24 15:33:46 -07003875 if (animateIcons) {
3876 // Animate to the correct page
3877 if (newShortcutsScreenId > -1) {
3878 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003879 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003880 final Runnable startBounceAnimRunnable = new Runnable() {
3881 public void run() {
3882 anim.playTogether(bounceAnims);
3883 anim.start();
3884 }
3885 };
Winson Chung997a9232013-07-24 15:33:46 -07003886 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003887 // We post the animation slightly delayed to prevent slowdowns
3888 // when we are loading right after we return to launcher.
3889 mWorkspace.postDelayed(new Runnable() {
3890 public void run() {
3891 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003892 mWorkspace.postDelayed(startBounceAnimRunnable,
3893 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003894 }
3895 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003896 } else {
3897 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003898 }
3899 }
Winson Chung64359a52013-07-08 17:17:08 -07003900 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003901 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003902 }
3903
Joe Onorato9c1289c2009-08-17 11:03:03 -04003904 /**
3905 * Implementation of the method from LauncherModel.Callbacks.
3906 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003907 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003908 Runnable r = new Runnable() {
3909 public void run() {
3910 bindFolders(folders);
3911 }
3912 };
3913 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003914 return;
3915 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003916 sFolders.clear();
3917 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003918 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003919
3920 /**
3921 * Add the views for a widget to the workspace.
3922 *
3923 * Implementation of the method from LauncherModel.Callbacks.
3924 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003925 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003926 Runnable r = new Runnable() {
3927 public void run() {
3928 bindAppWidget(item);
3929 }
3930 };
3931 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003932 return;
3933 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003934
Daniel Sandler843e8602010-06-07 14:59:01 -04003935 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3936 if (DEBUG_WIDGETS) {
3937 Log.d(TAG, "bindAppWidget: " + item);
3938 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003939 final Workspace workspace = mWorkspace;
3940
3941 final int appWidgetId = item.appWidgetId;
3942 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003943 if (DEBUG_WIDGETS) {
3944 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3945 }
3946
Joe Onorato9c1289c2009-08-17 11:03:03 -04003947 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3948
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003950 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003951
Adam Cohendcd297f2013-06-18 13:13:40 -07003952 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003953 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003954 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3955
Joe Onorato9c1289c2009-08-17 11:03:03 -04003956 workspace.requestLayout();
3957
Daniel Sandler843e8602010-06-07 14:59:01 -04003958 if (DEBUG_WIDGETS) {
3959 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3960 + (SystemClock.uptimeMillis()-start) + "ms");
3961 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003962 }
3963
Adam Cohen1462de32012-07-24 22:34:36 -07003964 public void onPageBoundSynchronously(int page) {
3965 mSynchronouslyBoundPages.add(page);
3966 }
3967
Joe Onorato9c1289c2009-08-17 11:03:03 -04003968 /**
3969 * Callback saying that there aren't any more items to bind.
3970 *
3971 * Implementation of the method from LauncherModel.Callbacks.
3972 */
Adam Cohene25af792013-06-06 23:08:25 -07003973 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003974 Runnable r = new Runnable() {
3975 public void run() {
3976 finishBindingItems(upgradePath);
3977 }
3978 };
3979 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003980 return;
3981 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003982 if (mSavedState != null) {
3983 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003984 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003985 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003986 mSavedState = null;
3987 }
3988
Adam Cohen1462de32012-07-24 22:34:36 -07003989 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003990
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003991 // If we received the result of any pending adds while the loader was running (e.g. the
3992 // widget configuration forced an orientation change), process them now.
3993 for (int i = 0; i < sPendingAddList.size(); i++) {
3994 completeAdd(sPendingAddList.get(i));
3995 }
3996 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003997
Winson Chungc51db6a2011-10-05 11:44:49 -07003998 // Update the market app icon as necessary (the other icons will be managed in response to
3999 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004000 if (!DISABLE_MARKET_BUTTON) {
4001 updateAppMarketIcon();
4002 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004003
Winson Chungf0c6ae02012-03-21 16:10:31 -07004004 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07004005 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004006 mWorkspace.getUniqueComponents(true, null);
4007 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004008 }
Adam Cohen99894d92013-06-14 11:22:59 -07004009
Adam Cohen66a01fd2013-06-11 12:48:00 -07004010 mWorkspace.post(new Runnable() {
4011 @Override
4012 public void run() {
4013 onFinishBindingItems();
4014 }
4015 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07004016 }
4017
Winson Chunga0b7e862013-09-05 16:03:15 -07004018 public boolean isAllAppsButtonRank(int rank) {
4019 if (mHotseat != null) {
4020 return mHotseat.isAllAppsButtonRank(rank);
4021 }
4022 return false;
4023 }
4024
Winson Chunga2413752012-04-03 14:22:34 -07004025 private boolean canRunNewAppsAnimation() {
4026 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4027 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4028 }
4029
Winson Chungc9168342013-06-26 14:54:55 -07004030 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4031 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4032 PropertyValuesHolder.ofFloat("alpha", 1f),
4033 PropertyValuesHolder.ofFloat("scaleX", 1f),
4034 PropertyValuesHolder.ofFloat("scaleY", 1f));
4035 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4036 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4037 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4038 return bounceAnim;
4039 }
4040
Adam Cohen27772732013-11-11 14:00:56 +00004041 public boolean useVerticalBarLayout() {
4042 return LauncherAppState.getInstance().getDynamicGrid().
4043 getDeviceProfile().isVerticalBarLayout();
4044 }
4045
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004046 protected Rect getSearchBarBounds() {
4047 return LauncherAppState.getInstance().getDynamicGrid().
4048 getDeviceProfile().getSearchBarBounds();
4049 }
4050
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004051 @Override
4052 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004053 boolean searchVisible = updateGlobalSearchIcon();
4054 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004055 if (mSearchDropTargetBar != null) {
4056 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4057 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004058 }
4059
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004060 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004061 * Add the icons for all apps.
4062 *
4063 * Implementation of the method from LauncherModel.Callbacks.
4064 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004065 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07004066 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
4067 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4068 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4069 getHotseat().addAllAppsFolder(mIconCache, apps,
4070 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4071 }
4072 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004073 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004074 if (mAppsCustomizeContent != null) {
4075 mAppsCustomizeContent.onPackagesUpdated(
4076 LauncherModel.getSortedWidgetsAndShortcuts(this));
4077 }
Winson Chungc58497e2013-09-03 17:48:37 -07004078 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004079 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004080 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004081 mAppsCustomizeContent.onPackagesUpdated(
4082 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004083 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004084 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004085 }
4086
4087 /**
4088 * A package was updated.
4089 *
4090 * Implementation of the method from LauncherModel.Callbacks.
4091 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004092 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004093 Runnable r = new Runnable() {
4094 public void run() {
4095 bindAppsUpdated(apps);
4096 }
4097 };
4098 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004099 return;
4100 }
4101
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004102 if (mWorkspace != null) {
4103 mWorkspace.updateShortcuts(apps);
4104 }
Winson Chungc58497e2013-09-03 17:48:37 -07004105
4106 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4107 mAppsCustomizeContent != null) {
4108 mAppsCustomizeContent.updateApps(apps);
4109 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004110 }
4111
4112 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004113 * A package was uninstalled. We take both the super set of packageNames
4114 * in addition to specific applications to remove, the reason being that
4115 * this can be called when a package is updated as well. In that scenario,
4116 * we only remove specific components from the workspace, where as
4117 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004118 *
4119 * Implementation of the method from LauncherModel.Callbacks.
4120 */
Winson Chung83892cc2013-05-01 16:53:33 -07004121 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Winson Chungdf95eb12013-10-16 14:57:07 -07004122 final ArrayList<AppInfo> appInfos) {
Winson Chungd64d1762013-08-20 14:37:16 -07004123 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004124 public void run() {
Winson Chungdf95eb12013-10-16 14:57:07 -07004125 bindComponentsRemoved(packageNames, appInfos);
Winson Chung83892cc2013-05-01 16:53:33 -07004126 }
Winson Chungd64d1762013-08-20 14:37:16 -07004127 };
4128 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004129 return;
4130 }
4131
Winson Chungdf95eb12013-10-16 14:57:07 -07004132 if (!packageNames.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004133 mWorkspace.removeItemsByPackageName(packageNames);
Winson Chungdf95eb12013-10-16 14:57:07 -07004134 }
4135 if (!appInfos.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004136 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004137 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004138
Winson Chunga1820962011-10-03 16:31:06 -07004139 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004140 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004141
Winson Chungdf95eb12013-10-16 14:57:07 -07004142 // Update AllApps
Winson Chungc58497e2013-09-03 17:48:37 -07004143 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4144 mAppsCustomizeContent != null) {
4145 mAppsCustomizeContent.removeApps(appInfos);
4146 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004147 }
Joe Onoratobe386092009-11-17 17:32:16 -08004148
4149 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004150 * A number of packages were updated.
4151 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004152 private ArrayList<Object> mWidgetsAndShortcuts;
4153 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004154 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004155 bindPackagesUpdated(mWidgetsAndShortcuts);
4156 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004157 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004158 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004159 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4160 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4161 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004162 return;
4163 }
4164
Winson Chung64359a52013-07-08 17:17:08 -07004165 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004166 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004167 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004168 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004169 }
4170
Winson Chung400438b2011-01-16 17:53:48 -08004171 private int mapConfigurationOriActivityInfoOri(int configOri) {
4172 final Display d = getWindowManager().getDefaultDisplay();
4173 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4174 switch (d.getRotation()) {
4175 case Surface.ROTATION_0:
4176 case Surface.ROTATION_180:
4177 // We are currently in the same basic orientation as the natural orientation
4178 naturalOri = configOri;
4179 break;
4180 case Surface.ROTATION_90:
4181 case Surface.ROTATION_270:
4182 // We are currently in the other basic orientation to the natural orientation
4183 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4184 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4185 break;
4186 }
4187
4188 int[] oriMap = {
4189 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4190 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4191 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4192 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4193 };
4194 // Since the map starts at portrait, we need to offset if this device's natural orientation
4195 // is landscape.
4196 int indexOffset = 0;
4197 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4198 indexOffset = 1;
4199 }
4200 return oriMap[(d.getRotation() + indexOffset) % 4];
4201 }
Adam Cohen446e9402011-09-15 18:21:21 -07004202
Winson Chung4b919f82012-05-01 10:44:08 -07004203 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004204 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004205 getResources().getBoolean(R.bool.allow_rotation);
4206 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004207 }
Winson Chung4b919f82012-05-01 10:44:08 -07004208 public void lockScreenOrientation() {
4209 if (isRotationEnabled()) {
4210 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4211 .getConfiguration().orientation));
4212 }
4213 }
4214 public void unlockScreenOrientation(boolean immediate) {
4215 if (isRotationEnabled()) {
4216 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004217 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004218 } else {
4219 mHandler.postDelayed(new Runnable() {
4220 public void run() {
4221 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4222 }
4223 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004224 }
Winson Chung4b919f82012-05-01 10:44:08 -07004225 }
Winson Chung400438b2011-01-16 17:53:48 -08004226 }
4227
Adam Cohenb54a5982014-01-08 15:21:04 -08004228 private boolean shouldRunFirstRunActivity() {
4229 return !ActivityManager.isRunningInTestHarness();
4230 }
4231
Winson Chung82f55532011-08-09 14:14:23 -07004232 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004233 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004234 if (DISABLE_CLINGS) {
4235 return false;
4236 }
4237
Winson Chung3a6e7f32013-10-09 15:50:52 -07004238 // For now, limit only to phones
4239 LauncherAppState app = LauncherAppState.getInstance();
4240 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
4241 if (grid.isTablet()) {
4242 return false;
4243 }
Winson Chung13dbfe12013-10-31 11:42:39 -07004244 if (grid.isLandscape) {
4245 return false;
4246 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004247
Brett Chabot2a9e2282011-08-23 15:03:13 -07004248 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004249 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004250
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004251 // Disable clings for accessibility when explore by touch is enabled
4252 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4253 ACCESSIBILITY_SERVICE);
4254 if (a11yManager.isTouchExplorationEnabled()) {
4255 return false;
4256 }
4257
Michael Jurkae233a8b2013-03-19 13:49:20 +01004258 // Restricted secondary users (child mode) will potentially have very few apps
4259 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004260// boolean supportsLimitedUsers =
4261// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4262// Account[] accounts = AccountManager.get(this).getAccounts();
4263// if (supportsLimitedUsers && accounts.length == 0) {
4264// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4265// Bundle restrictions = um.getUserRestrictions();
4266// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4267// return false;
4268// }
4269// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004270 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004271 }
Michael Jurka22143132012-10-04 17:42:38 +02004272
Winson Chungfa545132013-09-26 17:45:32 -07004273 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004274 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004275 Cling cling = (Cling) findViewById(clingId);
4276 View scrim = null;
4277 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004278 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004279 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004280 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004281 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004282 cling.show(animate, SHOW_CLING_DURATION);
4283
4284 if (dimNavBarVisibilty) {
4285 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4286 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004287 }
4288 }
4289 return cling;
4290 }
Michael Jurka22143132012-10-04 17:42:38 +02004291
Winson Chungaf40f202013-09-18 18:26:31 -07004292 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4293 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004294 // To catch cases where siblings of top-level views are made invisible, just check whether
4295 // the cling is directly set to GONE before dismissing it.
4296 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004297 final Runnable cleanUpClingCb = new Runnable() {
4298 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004299 cling.cleanup();
Adam Cohenb54a5982014-01-08 15:21:04 -08004300 SharedPreferences.Editor editor = mSharedPrefs.edit();
4301 editor.putBoolean(flag, true);
4302 editor.apply();
Winson Chungaf40f202013-09-18 18:26:31 -07004303 if (postAnimationCb != null) {
4304 postAnimationCb.run();
4305 }
4306 }
4307 };
4308 if (duration <= 0) {
4309 cleanUpClingCb.run();
4310 } else {
4311 cling.hide(duration, cleanUpClingCb);
4312 }
Michael Jurka22143132012-10-04 17:42:38 +02004313 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004314
4315 if (restoreNavBarVisibilty) {
4316 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4317 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4318 }
Winson Chung82f55532011-08-09 14:14:23 -07004319 }
4320 }
Michael Jurka22143132012-10-04 17:42:38 +02004321
Winson Chung9d9d74f2011-09-19 11:49:12 -07004322 private void removeCling(int id) {
4323 final View cling = findViewById(id);
4324 if (cling != null) {
4325 final ViewGroup parent = (ViewGroup) cling.getParent();
4326 parent.post(new Runnable() {
4327 @Override
4328 public void run() {
4329 parent.removeView(cling);
4330 }
4331 });
Michael Jurka22143132012-10-04 17:42:38 +02004332 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004333 }
4334 }
Michael Jurka974c3862012-05-22 22:00:31 -07004335
4336 private boolean skipCustomClingIfNoAccounts() {
4337 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4338 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4339 if (customCling) {
4340 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004341 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004342 Account[] accounts = am.getAccountsByType("com.google");
4343 return accounts.length == 0;
4344 }
4345 return false;
4346 }
4347
Winson Chung82e5c982013-10-09 12:04:50 -07004348 public void updateCustomContentHintVisibility() {
4349 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4350 String ccHintStr = getFirstRunCustomContentHint();
4351
4352 if (mWorkspace.hasCustomContent()) {
4353 // Show the custom content hint if ccHintStr is not empty
4354 if (cling != null) {
4355 setCustomContentHintVisibility(cling, ccHintStr, true, true);
4356 }
4357 } else {
4358 // Hide the custom content hint
4359 if (cling != null) {
4360 setCustomContentHintVisibility(cling, ccHintStr, false, true);
4361 }
4362 }
4363 }
4364
4365 private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible,
4366 boolean animate) {
4367 final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4368 if (ccHint != null) {
4369 if (visible && !ccHintStr.isEmpty()) {
4370 ccHint.setText(ccHintStr);
4371 ccHint.setVisibility(View.VISIBLE);
4372 if (animate) {
4373 ccHint.setAlpha(0f);
4374 ccHint.animate().alpha(1f)
4375 .setDuration(SHOW_CLING_DURATION)
4376 .start();
4377 } else {
4378 ccHint.setAlpha(1f);
4379 }
4380 } else {
4381 if (animate) {
4382 ccHint.animate().alpha(0f)
4383 .setDuration(SHOW_CLING_DURATION)
4384 .setListener(new AnimatorListenerAdapter() {
4385 @Override
4386 public void onAnimationEnd(Animator animation) {
4387 ccHint.setVisibility(View.GONE);
4388 }
4389 })
4390 .start();
4391 } else {
4392 ccHint.setAlpha(0f);
4393 ccHint.setVisibility(View.GONE);
4394 }
4395 }
4396 }
4397 }
4398
Adam Cohenb54a5982014-01-08 15:21:04 -08004399 public void showFirstRunActivity() {
4400 if (shouldRunFirstRunActivity() && hasFirstRunActivity()
4401 && !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false)) {
4402 Intent firstRunIntent = getFirstRunActivity();
4403 if (firstRunIntent != null) {
4404 startActivity(firstRunIntent);
4405 markFirstRunActivityShown();
4406 }
4407 }
4408 }
4409
4410 private void markFirstRunActivityShown() {
4411 SharedPreferences.Editor editor = mSharedPrefs.edit();
4412 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4413 editor.apply();
4414 }
4415
Winson Chungaf40f202013-09-18 18:26:31 -07004416 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004417 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004418 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004419 !skipCustomClingIfNoAccounts() ) {
Adam Cohenb54a5982014-01-08 15:21:04 -08004420
4421
Michael Jurka45355c42012-10-08 13:21:35 +02004422 // If we're not using the default workspace layout, replace workspace cling
4423 // with a custom workspace cling (usually specified in an overlay)
4424 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004425 if (!DISABLE_CUSTOM_CLINGS) {
4426 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4427 getResources().getBoolean(R.bool.config_useCustomClings)) {
4428 // Use a custom cling
4429 View cling = findViewById(R.id.workspace_cling);
4430 ViewGroup clingParent = (ViewGroup) cling.getParent();
4431 int clingIndex = clingParent.indexOfChild(cling);
4432 clingParent.removeViewAt(clingIndex);
4433 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4434 clingParent.addView(customCling, clingIndex);
4435 customCling.setId(R.id.workspace_cling);
4436 }
4437 }
4438 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4439 if (cling != null) {
4440 String sbHintStr = getFirstRunClingSearchBarHint();
4441 String ccHintStr = getFirstRunCustomContentHint();
4442 if (!sbHintStr.isEmpty()) {
4443 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4444 sbHint.setText(sbHintStr);
4445 sbHint.setVisibility(View.VISIBLE);
4446 }
Winson Chung82e5c982013-10-09 12:04:50 -07004447 setCustomContentHintVisibility(cling, ccHintStr, true, false);
Michael Jurka45355c42012-10-08 13:21:35 +02004448 }
Winson Chungfa545132013-09-26 17:45:32 -07004449 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004450 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004451 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004452 }
4453 }
Winson Chungaf40f202013-09-18 18:26:31 -07004454
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004455 /**
4456 * Called when the SearchBar hint should be changed.
4457 *
4458 * @param hint the hint to be displayed in the search bar.
4459 */
4460 protected void onSearchBarHintChanged(String hint) {
4461 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4462 if (cling != null && cling.getVisibility() == View.VISIBLE && !hint.isEmpty()) {
4463 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4464 sbHint.setText(hint);
4465 sbHint.setVisibility(View.VISIBLE);
4466 }
4467 }
4468
Winson Chunge6eabff2013-09-24 11:01:23 -07004469 protected String getFirstRunClingSearchBarHint() {
4470 return "";
4471 }
4472 protected String getFirstRunCustomContentHint() {
4473 return "";
4474 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004475 protected int getFirstRunFocusedHotseatAppDrawableId() {
4476 return -1;
4477 }
4478 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4479 return null;
4480 }
4481 protected int getFirstRunFocusedHotseatAppRank() {
4482 return -1;
4483 }
4484 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4485 return "";
4486 }
4487 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4488 return "";
4489 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004490
Winson Chungaf40f202013-09-18 18:26:31 -07004491 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004492 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004493 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004494 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004495 Cling c = initCling(R.id.workspace_cling, 0, false, true);
4496
4497 // Set the focused hotseat app if there is one
4498 c.setFocusedHotseatApp(getFirstRunFocusedHotseatAppDrawableId(),
4499 getFirstRunFocusedHotseatAppRank(),
4500 getFirstRunFocusedHotseatAppComponentName(),
4501 getFirstRunFocusedHotseatAppBubbleTitle(),
4502 getFirstRunFocusedHotseatAppBubbleDescription());
Winson Chung9d9d74f2011-09-19 11:49:12 -07004503 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004504 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004505 }
4506 }
4507 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004508 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004509 if (isClingsEnabled() &&
4510 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004511 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4512 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004513 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004514 } else {
4515 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004516 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004517 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004518 }
Michael Jurka104c4562013-07-08 18:03:46 -07004519 protected SharedPreferences getSharedPrefs() {
4520 return mSharedPrefs;
4521 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004522 public boolean isFolderClingVisible() {
4523 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004524 if (cling != null) {
4525 return cling.getVisibility() == View.VISIBLE;
4526 }
4527 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004528 }
Winson Chungaf40f202013-09-18 18:26:31 -07004529 public void dismissFirstRunCling(View v) {
4530 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4531 Runnable cb = new Runnable() {
4532 public void run() {
4533 // Show the workspace cling next
4534 showFirstRunWorkspaceCling();
4535 }
4536 };
4537 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4538 DISMISS_CLING_DURATION, false);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004539
4540 // Fade out the search bar for the workspace cling coming up
4541 mSearchDropTargetBar.hideSearchBar(true);
Winson Chungaf40f202013-09-18 18:26:31 -07004542 }
Winson Chung82f55532011-08-09 14:14:23 -07004543 public void dismissWorkspaceCling(View v) {
4544 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004545 Runnable cb = null;
4546 if (v == null) {
4547 cb = new Runnable() {
4548 public void run() {
4549 mWorkspace.enterOverviewMode();
4550 }
4551 };
4552 }
4553 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4554 DISMISS_CLING_DURATION, true);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004555
4556 // Fade in the search bar
4557 mSearchDropTargetBar.showSearchBar(true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004558 }
4559 public void dismissFolderCling(View v) {
4560 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004561 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4562 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004563 }
4564
Mathew Inwood72fbec12013-11-19 15:45:07 +00004565 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
4566 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
4567 if (ri == null) {
4568 return null;
4569 }
4570 return new AppInfo(getPackageManager(), ri, mIconCache, null);
4571 }
4572
4573 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4574 Bitmap icon) {
4575 return new ShortcutInfo(shortcutIntent, caption, icon);
4576 }
4577
4578 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4579 dragView.setTag(dragInfo);
4580 mWorkspace.onDragStartedWithItem(dragView);
4581 mWorkspace.beginDragShared(dragView, source);
4582 }
4583
Winson Chung80baf5a2010-08-09 16:03:15 -07004584 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004585 * Prints out out state for debugging.
4586 */
4587 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004588 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004589 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004590 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4591 Log.d(TAG, "mRestoring=" + mRestoring);
4592 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4593 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004594 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004595 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004596
Winson Chung785d2eb2011-04-14 16:08:02 -07004597 if (mAppsCustomizeContent != null) {
4598 mAppsCustomizeContent.dumpState();
4599 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004600 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004601 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004602
4603 @Override
4604 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4605 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004606 synchronized (sDumpLogs) {
4607 writer.println(" ");
4608 writer.println("Debug logs: ");
4609 for (int i = 0; i < sDumpLogs.size(); i++) {
4610 writer.println(" " + sDumpLogs.get(i));
4611 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004612 }
4613 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004614
4615 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004616 if (DEBUG_DUMP_LOG) {
4617 synchronized (sDumpLogs) {
4618 Log.d(TAG, "");
4619 Log.d(TAG, "*********************");
4620 Log.d(TAG, "Launcher debug logs: ");
4621 for (int i = 0; i < sDumpLogs.size(); i++) {
4622 Log.d(TAG, " " + sDumpLogs.get(i));
4623 }
4624 Log.d(TAG, "*********************");
4625 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004626 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004627 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004628 }
4629
4630 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004631 addDumpLog(tag, log, null, debugLog);
4632 }
4633
4634 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004635 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004636 if (e != null) {
4637 Log.d(tag, log, e);
4638 } else {
4639 Log.d(tag, log);
4640 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004641 }
Winson Chungede41292013-09-19 16:27:36 -07004642 if (DEBUG_DUMP_LOG) {
4643 sDateStamp.setTime(System.currentTimeMillis());
4644 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004645 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4646 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004647 }
Winson Chungede41292013-09-19 16:27:36 -07004648 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004649 }
4650
Winson Chungede41292013-09-19 16:27:36 -07004651 public void dumpLogsToLocalData() {
4652 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004653 new AsyncTask<Void, Void, Void>() {
4654 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004655 boolean success = false;
4656 sDateStamp.setTime(sRunStart);
4657 String FILENAME = sDateStamp.getMonth() + "-"
4658 + sDateStamp.getDay() + "_"
4659 + sDateStamp.getHours() + "-"
4660 + sDateStamp.getMinutes() + "_"
4661 + sDateStamp.getSeconds() + ".txt";
4662
4663 FileOutputStream fos = null;
4664 File outFile = null;
4665 try {
4666 outFile = new File(getFilesDir(), FILENAME);
4667 outFile.createNewFile();
4668 fos = new FileOutputStream(outFile);
4669 } catch (Exception e) {
4670 e.printStackTrace();
4671 }
4672 if (fos != null) {
4673 PrintWriter writer = new PrintWriter(fos);
4674
4675 writer.println(" ");
4676 writer.println("Debug logs: ");
4677 synchronized (sDumpLogs) {
4678 for (int i = 0; i < sDumpLogs.size(); i++) {
4679 writer.println(" " + sDumpLogs.get(i));
4680 }
4681 }
4682 writer.close();
4683 }
4684 try {
4685 if (fos != null) {
4686 fos.close();
4687 success = true;
4688 }
4689 } catch (IOException e) {
4690 e.printStackTrace();
4691 }
Michael Jurka43467462013-11-14 12:03:58 +01004692 return null;
Winson Chungede41292013-09-19 16:27:36 -07004693 }
Michael Jurka43467462013-11-14 12:03:58 +01004694 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004695 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004696 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004697}
Michael Jurka2763be32011-02-24 11:19:57 -08004698
Michael Jurkaabded662011-03-04 12:06:57 -08004699interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004700 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004701 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004702 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004703 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004704 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004705}