blob: 8ef28de711759b7cb22d3838cef3537ff5c8fe96 [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";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800158 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Winson Chung2672ff92012-05-04 16:22:30 -0700160 // The Intent extra that defines whether to ignore the launch animation
161 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400162 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 // Type: int
165 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700166 // Type: int
167 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700169 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
170 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
172 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700173 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700175 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: boolean
177 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
178 // Type: long
179 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700180 // Type: int
181 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
182 // Type: int
183 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
184 // Type: parcelable
185 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000186 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800187 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000188 // Type: int[]
189 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100191 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700192 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100193 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700194 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100195 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700196
Adam Cohen39a06042013-07-19 14:30:12 -0700197 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700198 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700199
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700200 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700201 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700202 private State mState = State.WORKSPACE;
203 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700204
Joe Onorato9c1289c2009-08-17 11:03:03 -0400205 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700206 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
207 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Winson Chungaf40f202013-09-18 18:26:31 -0700208 private static final int SHOW_CLING_DURATION = 250;
209 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800212 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000214 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
215 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
216
Winson Chunga2413752012-04-03 14:22:34 -0700217 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700218 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
219 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700220 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700221
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800222 private final BroadcastReceiver mCloseSystemDialogsReceiver
223 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800224 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
225
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 private LayoutInflater mInflater;
227
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700229 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800230 private DragLayer mDragLayer;
231 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700232 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700233
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700234 private AppWidgetManager mAppWidgetManager;
235 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Michael Jurkac9d95c52011-08-29 14:03:34 -0700237 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700238 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800239 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700240
Michael Jurka0280c3b2010-09-17 15:00:07 -0700241 private int[] mTmpAddItemCellCoordinates = new int[2];
242
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800243 private FolderInfo mFolderInfo;
244
Winson Chung3d503fb2011-07-13 17:25:49 -0700245 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700246 private View mOverviewPanel;
247
Michael Jurka838a4ca2011-02-07 13:33:06 -0800248 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700249
Winson Chungc51db6a2011-10-05 11:44:49 -0700250 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700251 private AppsCustomizeTabHost mAppsCustomizeTabHost;
252 private AppsCustomizePagedView mAppsCustomizeContent;
253 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100254 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700257 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
258 // scroll issues (because the workspace may not have been measured yet) and extra work.
259 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
260 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261
262 private SpannableStringBuilder mDefaultKeySsb = null;
263
Joe Onorato9c1289c2009-08-17 11:03:03 -0400264 private boolean mWorkspaceLoading = true;
265
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800266 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 private boolean mRestoring;
268 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700269 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
Michael Jurka1e2f4652013-07-08 18:03:46 -0700271 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700272 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
273
Winson Chung4a2afa32012-07-19 14:53:05 -0700274 // Keep track of whether the user has left launcher
275 private static boolean sPausedFromUserAction = false;
276
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 private Bundle mSavedInstanceState;
278
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800280 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800281 private boolean mUserPresent = true;
282 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700283 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800284 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700285 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700286 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400287
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700288 private static LocaleConfiguration sLocaleConfiguration = null;
289
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700290 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700291
Adam Cohen61f560d2013-09-30 15:58:20 -0700292 private View.OnTouchListener mHapticFeedbackTouchListener;
293
Adam Cohended9f8d2010-11-03 13:25:16 -0700294 // Related to the auto-advancing of widgets
295 private final int ADVANCE_MSG = 1;
296 private final int mAdvanceInterval = 20000;
297 private final int mAdvanceStagger = 250;
298 private long mAutoAdvanceSentTime;
299 private long mAutoAdvanceTimeLeft = -1;
300 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
301 new HashMap<View, AppWidgetProviderInfo>();
302
Winson Chung400438b2011-01-16 17:53:48 -0800303 // Determines how long to wait after a rotation before restoring the screen orientation to
304 // match the sensor state.
305 private final int mRestoreScreenOrientationDelay = 500;
306
Michael Jurka4ef207b2010-11-29 17:05:45 -0800307 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700308 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
309 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
310 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800311
Winson Chungd64a6662013-09-30 11:06:59 -0700312 private Intent mAppMarketIntent = null;
313 private static final boolean DISABLE_MARKET_BUTTON = true;
314
Craig Mautner360310b2012-10-26 15:13:08 -0700315 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700316
Adam Cohen1462de32012-07-24 22:34:36 -0700317 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700318 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700319
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700320 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700321 static Date sDateStamp = new Date();
322 static DateFormat sDateFormat =
323 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
324 static long sRunStart = System.currentTimeMillis();
325 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700326
Winson Chung46353de2012-02-16 14:05:10 -0800327 // We only want to get the SharedPreferences once since it does an FS stat each time we get
328 // it from the context.
329 private SharedPreferences mSharedPrefs;
330
Adam Cohene25af792013-06-06 23:08:25 -0700331 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
332
Winson Chungf0c6ae02012-03-21 16:10:31 -0700333 // Holds the page that we need to animate to, and the icon views that we need to animate up
334 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700335 private ImageView mFolderIconImageView;
336 private Bitmap mFolderIconBitmap;
337 private Canvas mFolderIconCanvas;
338 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700339
Michael Jurkaddd62e92011-02-16 17:49:14 -0800340 private BubbleTextView mWaitingForResume;
341
Michael Jurka22143132012-10-04 17:42:38 +0200342 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
343 = new HideFromAccessibilityHelper();
344
Michael Jurkac1f5d262011-09-30 19:32:27 -0700345 private Runnable mBuildLayersRunnable = new Runnable() {
346 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700347 if (mWorkspace != null) {
348 mWorkspace.buildPageHardwareLayers();
349 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700350 }
351 };
352
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800353 private static ArrayList<PendingAddArguments> sPendingAddList
354 = new ArrayList<PendingAddArguments>();
355
Michael Jurka7267fa52013-09-26 15:29:57 -0700356 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800357
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358 private static class PendingAddArguments {
359 int requestCode;
360 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700361 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700362 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800363 int cellX;
364 int cellY;
365 }
366
Daniel Sandlerff02d492013-08-05 02:12:05 -0400367 private Stats mStats;
368
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800369 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800370 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700371 }
372
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 @Override
374 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700375 if (DEBUG_STRICT_MODE) {
376 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
377 .detectDiskReads()
378 .detectDiskWrites()
379 .detectNetwork() // or .detectAll() for all detectable problems
380 .penaltyLog()
381 .build());
382 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
383 .detectLeakedSqlLiteObjects()
384 .detectLeakedClosableObjects()
385 .penaltyLog()
386 .penaltyDeath()
387 .build());
388 }
389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400391
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400392 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400393 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700394
395 // Determine the dynamic grid properties
396 Point smallestSize = new Point();
397 Point largestSize = new Point();
398 Point realSize = new Point();
399 Display display = getWindowManager().getDefaultDisplay();
400 display.getCurrentSizeRange(smallestSize, largestSize);
401 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700402 DisplayMetrics dm = new DisplayMetrics();
403 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700404
Winson Chung5f8afe62013-08-12 16:19:28 -0700405 // Lazy-initialize the dynamic grid
406 DeviceProfile grid = app.initDynamicGrid(this,
407 Math.min(smallestSize.x, smallestSize.y),
408 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700409 realSize.x, realSize.y,
410 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700411
412 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400413 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700414 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800415 mModel = app.setLauncher(this);
416 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700417 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400418 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700420
Daniel Sandlerff02d492013-08-05 02:12:05 -0400421 mStats = new Stats(this);
422
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700423 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700424
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700425 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
426 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700427
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700428 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
429 // this also ensures that any synchronous binding below doesn't re-trigger another
430 // LauncherModel load.
431 mPaused = false;
432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200434 android.os.Debug.startMethodTracing(
435 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 }
437
Adam Cohen53805212013-10-01 10:39:23 -0700438
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100443 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800445 registerContentObservers();
446
Joe Onorato7c312c12009-08-13 21:36:53 -0700447 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700448
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 mSavedState = savedInstanceState;
450 restoreState(mSavedState);
451
452 if (PROFILE_STARTUP) {
453 android.os.Debug.stopMethodTracing();
454 }
455
456 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700457 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700458 // If the user leaves launcher, then we should just load items asynchronously when
459 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500460 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700461 } else {
462 // We only load the page synchronously if the user rotates (or triggers a
463 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800464 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700465 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466 }
467
468 // For handling default keys
469 mDefaultKeySsb = new SpannableStringBuilder();
470 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800471
472 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
473 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800474
Adam Cohenf9426d52012-06-04 17:26:21 -0700475 updateGlobalIcons();
476
477 // On large interfaces, we want the screen to auto-rotate based on the current orientation
478 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700479
480 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700481 }
482
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 protected void onUserLeaveHint() {
484 super.onUserLeaveHint();
485 sPausedFromUserAction = true;
486 }
487
Winson Chung98ca0f72013-07-29 12:58:51 -0700488 /** To be overriden by subclasses to hint to Launcher that we have custom content */
489 protected boolean hasCustomContentToLeft() {
490 return false;
491 }
492
Dave Hawkeya8881582013-09-17 15:55:33 -0600493 /**
494 * To be overridden by subclasses to create the custom content and call
495 * {@link #addToCustomContentPage}. This will only be invoked if
496 * {@link #hasCustomContentToLeft()} is {@code true}.
497 */
498 protected void addCustomContentToLeft() {
499 }
500
501 /**
502 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
503 * ensure the custom content page is added or removed if necessary.
504 */
505 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600506 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600507 // Not bound yet, wait for bindScreens to be called.
508 return;
509 }
510
511 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
512 // Create the custom content page and call the subclass to populate it.
513 mWorkspace.createCustomContentPage();
514 addCustomContentToLeft();
515 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
516 mWorkspace.removeCustomContentPage();
517 }
518 }
519
Adam Cohenf9426d52012-06-04 17:26:21 -0700520 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700521 boolean searchVisible = false;
522 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800523 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700524 int coi = getCurrentOrientationIndexForGlobalIcons();
525 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
526 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700527 if (!DISABLE_MARKET_BUTTON) {
528 updateAppMarketIcon();
529 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700530 searchVisible = updateGlobalSearchIcon();
531 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700532 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700533 if (sGlobalSearchIcon[coi] != null) {
534 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700535 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700536 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700537 if (sVoiceSearchIcon[coi] != null) {
538 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700539 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700540 }
Winson Chungd64a6662013-09-30 11:06:59 -0700541 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700542 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800543 }
Winson Chungadf0c182012-08-23 14:59:07 -0700544 if (mSearchDropTargetBar != null) {
545 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
546 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800547 }
Romain Guycbb89e42009-06-08 15:52:54 -0700548
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800549 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700550 if (sLocaleConfiguration == null) {
551 new AsyncTask<Void, Void, LocaleConfiguration>() {
552 @Override
553 protected LocaleConfiguration doInBackground(Void... unused) {
554 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
555 readConfiguration(Launcher.this, localeConfiguration);
556 return localeConfiguration;
557 }
558
559 @Override
560 protected void onPostExecute(LocaleConfiguration result) {
561 sLocaleConfiguration = result;
562 checkForLocaleChange(); // recursive, but now with a locale configuration
563 }
564 }.execute();
565 return;
566 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700567
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800568 final Configuration configuration = getResources().getConfiguration();
569
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700570 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 final String locale = configuration.locale.toString();
572
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700573 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574 final int mcc = configuration.mcc;
575
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 final int mnc = configuration.mnc;
578
Romain Guy84f296c2009-11-04 15:00:44 -0800579 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800580
Romain Guy84f296c2009-11-04 15:00:44 -0800581 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700582 sLocaleConfiguration.locale = locale;
583 sLocaleConfiguration.mcc = mcc;
584 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700585
Joe Onorato0589f0f2010-02-08 13:44:00 -0800586 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700587
588 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100589 new AsyncTask<Void, Void, Void>() {
590 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700591 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100592 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700593 }
Michael Jurka43467462013-11-14 12:03:58 +0100594 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700595 }
596 }
597
598 private static class LocaleConfiguration {
599 public String locale;
600 public int mcc = -1;
601 public int mnc = -1;
602 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700603
Romain Guy98d01652009-06-30 16:21:04 -0700604 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
605 DataInputStream in = null;
606 try {
607 in = new DataInputStream(context.openFileInput(PREFERENCES));
608 configuration.locale = in.readUTF();
609 configuration.mcc = in.readInt();
610 configuration.mnc = in.readInt();
611 } catch (FileNotFoundException e) {
612 // Ignore
613 } catch (IOException e) {
614 // Ignore
615 } finally {
616 if (in != null) {
617 try {
618 in.close();
619 } catch (IOException e) {
620 // Ignore
621 }
622 }
623 }
624 }
625
626 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
627 DataOutputStream out = null;
628 try {
629 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
630 out.writeUTF(configuration.locale);
631 out.writeInt(configuration.mcc);
632 out.writeInt(configuration.mnc);
633 out.flush();
634 } catch (FileNotFoundException e) {
635 // Ignore
636 } catch (IOException e) {
637 //noinspection ResultOfMethodCallIgnored
638 context.getFileStreamPath(PREFERENCES).delete();
639 } finally {
640 if (out != null) {
641 try {
642 out.close();
643 } catch (IOException e) {
644 // Ignore
645 }
646 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800647 }
648 }
649
Anton Hanssona2f665f2013-09-26 12:18:32 +0100650 public Stats getStats() {
651 return mStats;
652 }
653
Bjorn Bringertc459e522013-06-07 19:36:01 +0100654 public LayoutInflater getInflater() {
655 return mInflater;
656 }
657
Adam Cohen716b51e2011-06-30 12:09:54 -0700658 public DragLayer getDragLayer() {
659 return mDragLayer;
660 }
661
Winson Chung36a62fe2012-05-06 18:04:42 -0700662 boolean isDraggingEnabled() {
663 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
664 // that is subsequently removed from the workspace in startBinding().
665 return !mModel.isLoadingWorkspace();
666 }
667
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 static int getScreen() {
669 synchronized (sLock) {
670 return sScreen;
671 }
672 }
673
674 static void setScreen(int screen) {
675 synchronized (sLock) {
676 sScreen = screen;
677 }
678 }
679
Winson Chung557d6ed2011-07-08 15:34:52 -0700680 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000681 * Copied from View -- the View version of the method isn't called
682 * anywhere else in our process and only exists for API level 17+,
683 * so it's ok to keep our own version with no API requirement.
684 */
685 public static int generateViewId() {
686 for (;;) {
687 final int result = sNextGeneratedId.get();
688 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
689 int newValue = result + 1;
690 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
691 if (sNextGeneratedId.compareAndSet(result, newValue)) {
692 return result;
693 }
694 }
695 }
696
697 public int getViewIdForItem(ItemInfo info) {
698 // This cast is safe given the > 2B range for int.
699 int itemId = (int) info.id;
700 if (mItemIdToViewId.containsKey(itemId)) {
701 return mItemIdToViewId.get(itemId);
702 }
703 int viewId = generateViewId();
704 mItemIdToViewId.put(itemId, viewId);
705 return viewId;
706 }
707
708 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700709 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
710 * a configuration step, this allows the proper animations to run after other transitions.
711 */
712 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700713 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800714 switch (args.requestCode) {
715 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700716 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700717 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800718 break;
719 case REQUEST_PICK_SHORTCUT:
720 processShortcut(args.intent);
721 break;
722 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700723 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700724 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700725 result = true;
726 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800727 case REQUEST_CREATE_APPWIDGET:
728 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700729 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700730 result = true;
731 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800732 }
Michael Jurka27614d22012-04-02 06:40:22 -0700733 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
734 // if you turned the screen off and then back while in All Apps, Launcher would not
735 // return to the workspace. Clearing mAddInfo.container here fixes this issue
736 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700737 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 }
739
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700741 protected void onActivityResult(
742 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700743 // Reset the startActivity waiting flag
744 mWaitingForResult = false;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800745 int pendingAddWidgetId = mPendingAddWidgetId;
746 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700747
Adam Cohenad4e15c2013-10-17 16:21:35 -0700748 Runnable exitSpringLoaded = new Runnable() {
749 @Override
750 public void run() {
751 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
752 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
753 }
754 };
755
Michael Jurka8b805b12012-04-18 14:23:14 -0700756 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700757 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700758 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
759 if (resultCode == RESULT_CANCELED) {
760 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700761 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
762 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700763 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700764 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
765 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 }
767 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200768 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
769 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
770 mWorkspace.exitOverviewMode(false);
771 }
772 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700773 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200774
Adam Cohened66b2b2012-01-23 17:28:51 -0800775 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
776 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700777
Adam Cohened66b2b2012-01-23 17:28:51 -0800778 // We have special handling for widgets
779 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800780 final int appWidgetId;
781 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
782 : -1;
783 if (widgetId < 0) {
784 appWidgetId = pendingAddWidgetId;
785 } else {
786 appWidgetId = widgetId;
787 }
788
Adam Cohenad4e15c2013-10-17 16:21:35 -0700789 final int result;
790 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800791 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700792 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
793 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700794 result = RESULT_CANCELED;
795 completeTwoStageWidgetDrop(result, appWidgetId);
796 onComplete = new Runnable() {
797 @Override
798 public void run() {
799 exitSpringLoadedDragModeDelayed(false, 0, null);
800 }
801 };
Winson Chung5aaab772012-04-27 15:24:02 -0700802 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700803 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700804 final CellLayout dropLayout =
805 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
806 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700807 onComplete = new Runnable() {
808 @Override
809 public void run() {
810 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700811 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 }
813 };
Winson Chung5aaab772012-04-27 15:24:02 -0700814 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700815 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
816 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800817 return;
818 }
819
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800820 // The pattern used here is that a user PICKs a specific application,
821 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700822
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
824 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700825 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800826 final PendingAddArguments args = new PendingAddArguments();
827 args.requestCode = requestCode;
828 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700829 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700830 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700831 args.cellX = mPendingAddInfo.cellX;
832 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800833 if (isWorkspaceLocked()) {
834 sPendingAddList.add(args);
835 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700836 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800837 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700838 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
839 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700840 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700841 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
842 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800844 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800845 }
846
847 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700848 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700849 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800850 Runnable onCompleteRunnable = null;
851 int animationType = 0;
852
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700853 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800854 if (resultCode == RESULT_OK) {
855 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
856 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700857 mPendingAddWidgetInfo);
858 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800859 onCompleteRunnable = new Runnable() {
860 @Override
861 public void run() {
862 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700863 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700864 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
865 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 }
867 };
868 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800869 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800870 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800871 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700872 if (mDragLayer.getAnimatedView() != null) {
873 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
874 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
875 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700876 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700877 // The animated view may be null in the case of a rotation during widget configuration
878 onCompleteRunnable.run();
879 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800880 }
881
882 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700883 protected void onStop() {
884 super.onStop();
885 FirstFrameAnimatorHelper.setIsVisible(false);
886 }
887
888 @Override
889 protected void onStart() {
890 super.onStart();
891 FirstFrameAnimatorHelper.setIsVisible(true);
892 }
893
894 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800895 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200896 long startTime = 0;
897 if (DEBUG_RESUME_TIME) {
898 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400899 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700902
Winson Chung4a2afa32012-07-19 14:53:05 -0700903 // Restore the previous launcher state
904 if (mOnResumeState == State.WORKSPACE) {
905 showWorkspace(false);
906 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800907 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700908 }
909 mOnResumeState = State.NONE;
910
Craig Mautner360310b2012-10-26 15:13:08 -0700911 // Background was set to gradient in onPause(), restore to black if in all apps.
912 setWorkspaceBackground(mState == State.WORKSPACE);
913
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800914 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700915 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700916 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400917 mWorkspaceLoading = true;
Derek Prothro7aff3992013-12-10 14:00:37 -0500918 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400919 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700920 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800921 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700922 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200923 // We might have postponed some bind calls until onResume (see waitUntilResume) --
924 // execute them here
925 long startTimeCallbacks = 0;
926 if (DEBUG_RESUME_TIME) {
927 startTimeCallbacks = System.currentTimeMillis();
928 }
929
930 if (mAppsCustomizeContent != null) {
931 mAppsCustomizeContent.setBulkBind(true);
932 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700933 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
934 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200935 }
936 if (mAppsCustomizeContent != null) {
937 mAppsCustomizeContent.setBulkBind(false);
938 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700939 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200940 if (DEBUG_RESUME_TIME) {
941 Log.d(TAG, "Time spent processing callbacks in onResume: " +
942 (System.currentTimeMillis() - startTimeCallbacks));
943 }
Michael Jurka447bf842013-05-15 14:52:15 +0200944 }
Michael Jurka54554252013-08-01 12:52:23 +0200945 if (mOnResumeCallbacks.size() > 0) {
946 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
947 mOnResumeCallbacks.get(i).run();
948 }
949 mOnResumeCallbacks.clear();
950 }
Winson Chunge4e50662012-01-23 14:45:13 -0800951
952 // Reset the pressed state of icons that were locked in the press state while activities
953 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800954 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800955 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800956 mWaitingForResume.setStayPressed(false);
957 }
Winson Chunge4e50662012-01-23 14:45:13 -0800958 if (mAppsCustomizeContent != null) {
959 // Resets the previous all apps icon press state
960 mAppsCustomizeContent.resetDrawableState();
961 }
Winson Chung82963d52013-10-09 11:20:57 -0700962
Adam Cohen06dff352012-06-01 17:17:08 -0700963 // It is possible that widgets can receive updates while launcher is not in the foreground.
964 // Consequently, the widgets will be inflated in the orientation of the foreground activity
965 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
966 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700967 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700968
Winson Chung780fe592013-09-26 14:48:44 -0700969 // Process any items that were added while Launcher was away.
970 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
971
Winson Chung5841efa2013-09-30 18:06:44 -0700972 // Update the voice search button proxy
973 updateVoiceButtonProxyVisible(false);
974
Adam Cohenf9426d52012-06-04 17:26:21 -0700975 // Again, as with the above scenario, it's possible that one or more of the global icons
976 // were updated in the wrong orientation.
977 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200978 if (DEBUG_RESUME_TIME) {
979 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
980 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700981
982 if (mWorkspace.getCustomContentCallbacks() != null) {
983 // If we are resuming and the custom content is the current page, we call onShow().
984 // It is also poassible that onShow will instead be called slightly after first layout
985 // if PagedView#setRestorePage was set to the custom content page in onCreate().
986 if (mWorkspace.isOnOrMovingToCustomContent()) {
987 mWorkspace.getCustomContentCallbacks().onShow();
988 }
989 }
Adam Cohenedaaa302013-10-01 17:33:27 -0700990 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -0700991 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -0700992 }
993
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800994 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700995 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700996 // Ensure that items added to Launcher are queued until Launcher returns
997 InstallShortcutReceiver.enableInstallQueue();
998
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700999 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001000 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001001 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001002 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001003
1004 // We call onHide() aggressively. The custom content callbacks should be able to
1005 // debounce excess onHide calls.
1006 if (mWorkspace.getCustomContentCallbacks() != null) {
1007 mWorkspace.getCustomContentCallbacks().onHide();
1008 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001009 }
Romain Guycbb89e42009-06-08 15:52:54 -07001010
Adam Cohen66a01fd2013-06-11 12:48:00 -07001011 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -07001012 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -06001013 addCustomContentToLeft();
1014 }
Adam Cohen66a01fd2013-06-11 12:48:00 -07001015 }
1016
Adam Cohenbffe7452013-07-22 18:21:45 -07001017 QSBScroller mQsbScroller = new QSBScroller() {
1018 int scrollY = 0;
1019
1020 @Override
1021 public void setScrollY(int scroll) {
1022 scrollY = scroll;
1023
1024 if (mWorkspace.isOnOrMovingToCustomContent()) {
1025 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001026 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001027 }
1028 }
1029 };
1030
1031 public void resetQSBScroll() {
1032 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001033 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001034 }
1035
1036 public interface CustomContentCallbacks {
1037 // Custom content is completely shown
1038 public void onShow();
1039
1040 // Custom content is completely hidden
1041 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001042
1043 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1044 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001045 }
1046
Adam Cohen30bacb22013-08-29 14:25:25 -07001047 protected void startSettings() {
1048 }
1049
Adam Cohenbffe7452013-07-22 18:21:45 -07001050 public interface QSBScroller {
1051 public void setScrollY(int scrollY);
1052 }
1053
Winson Chung98ca0f72013-07-29 12:58:51 -07001054 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001055 CustomContentCallbacks callbacks, String description) {
1056 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001057 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001058 }
1059
Adam Cohenedb40762013-07-18 16:45:45 -07001060 // The custom content needs to offset its content to account for the QSB
1061 public int getTopOffsetForCustomContent() {
1062 return mWorkspace.getPaddingTop();
1063 }
1064
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001065 @Override
1066 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001067 // Flag the loader to stop early before switching
1068 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001069 if (mAppsCustomizeContent != null) {
1070 mAppsCustomizeContent.surrender();
1071 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001072 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001073 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001074
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001075 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001076 @Override
1077 public void onWindowFocusChanged(boolean hasFocus) {
1078 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001079 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001080 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001081
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 private boolean acceptFilter() {
1083 final InputMethodManager inputManager = (InputMethodManager)
1084 getSystemService(Context.INPUT_METHOD_SERVICE);
1085 return !inputManager.isFullscreenMode();
1086 }
1087
1088 @Override
1089 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001090 final int uniChar = event.getUnicodeChar();
1091 final boolean handled = super.onKeyDown(keyCode, event);
1092 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1093 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1095 keyCode, event);
1096 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001097 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001098 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001099 // showSearchDialog()
1100 // If there are multiple keystrokes before the search dialog takes focus,
1101 // onSearchRequested() will be called for every keystroke,
1102 // but it is idempotent, so it's fine.
1103 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001104 }
1105 }
1106
Joe Onorato8a9625e2010-01-28 15:55:35 -08001107 // Eat the long press event so the keyboard doesn't come up.
1108 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1109 return true;
1110 }
1111
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 return handled;
1113 }
1114
Karl Rosaen138a0412009-04-23 19:00:21 -07001115 private String getTypedText() {
1116 return mDefaultKeySsb.toString();
1117 }
1118
1119 private void clearTypedText() {
1120 mDefaultKeySsb.clear();
1121 mDefaultKeySsb.clearSpans();
1122 Selection.setSelection(mDefaultKeySsb, 0);
1123 }
1124
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001126 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1127 * State
1128 */
1129 private static State intToState(int stateOrdinal) {
1130 State state = State.WORKSPACE;
1131 final State[] stateValues = State.values();
1132 for (int i = 0; i < stateValues.length; i++) {
1133 if (stateValues[i].ordinal() == stateOrdinal) {
1134 state = stateValues[i];
1135 break;
1136 }
1137 }
1138 return state;
1139 }
1140
1141 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 * Restores the previous state, if it exists.
1143 *
1144 * @param savedState The previous state.
1145 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001146 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 private void restoreState(Bundle savedState) {
1148 if (savedState == null) {
1149 return;
1150 }
1151
Michael Jurka883f55b2010-10-21 15:47:14 -07001152 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001153 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001154 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001155 }
1156
Adam Cohen21cd0022013-10-09 18:57:02 -07001157 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1158 PagedView.INVALID_RESTORE_PAGE);
1159 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001160 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 }
1162
Winson Chung3d503fb2011-07-13 17:25:49 -07001163 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001164 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001165
Winson Chung3d503fb2011-07-13 17:25:49 -07001166 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1167 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001168 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001169 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1170 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001171 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1172 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1173 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001174 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001175 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001176 mRestoring = true;
1177 }
1178
1179 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1180 if (renameFolder) {
1181 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001182 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 mRestoring = true;
1184 }
Winson Chunga12a2502010-12-20 14:41:35 -08001185
Winson Chung785d2eb2011-04-14 16:08:02 -07001186 // Restore the AppsCustomize tab
1187 if (mAppsCustomizeTabHost != null) {
1188 String curTab = savedState.getString("apps_customize_currentTab");
1189 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001190 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001191 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001192 mAppsCustomizeContent.loadAssociatedPages(
1193 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001194 }
1195
Winson Chung5afbf7b2011-07-25 11:53:08 -07001196 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1197 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001198 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001199 mItemIdToViewId = (HashMap<Integer, Integer>)
1200 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 }
1202
1203 /**
1204 * Finds all the views we need and configure them properly.
1205 */
1206 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001207 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001208
Craig Mautner360310b2012-10-26 15:13:08 -07001209 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001210 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1211 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001212
John Spurlock77e1f472013-09-11 10:09:51 -04001213 mLauncherView.setSystemUiVisibility(
1214 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001215 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216
Winson Chung4c98d922011-05-31 16:50:48 -07001217 // Setup the drag layer
1218 mDragLayer.setup(this, dragController);
1219
Winson Chung3d503fb2011-07-13 17:25:49 -07001220 // Setup the hotseat
1221 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1222 if (mHotseat != null) {
1223 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001224 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001225 }
1226
Adam Cohenf358a4b2013-07-23 16:47:31 -07001227 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001228 View widgetButton = findViewById(R.id.widget_button);
1229 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001230 @Override
1231 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001232 if (!mWorkspace.isSwitchingState()) {
1233 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
1234 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001235 }
1236 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001237 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1238
1239 View wallpaperButton = findViewById(R.id.wallpaper_button);
1240 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001241 @Override
1242 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001243 if (!mWorkspace.isSwitchingState()) {
1244 startWallpaper();
1245 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001246 }
1247 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001248 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1249
1250 View settingsButton = findViewById(R.id.settings_button);
1251 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001252 @Override
1253 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001254 if (!mWorkspace.isSwitchingState()) {
1255 startSettings();
1256 }
Adam Cohen30bacb22013-08-29 14:25:25 -07001257 }
1258 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001259 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001260 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001261
Winson Chung4c98d922011-05-31 16:50:48 -07001262 // Setup the workspace
1263 mWorkspace.setHapticFeedbackEnabled(false);
1264 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001265 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001266 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001267
Winson Chungf0ea4d32011-06-06 14:27:16 -07001268 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001269 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001270
Winson Chungf0ea4d32011-06-06 14:27:16 -07001271 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001272 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001273 mAppsCustomizeContent = (AppsCustomizePagedView)
1274 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1275 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001276
Winson Chung3d503fb2011-07-13 17:25:49 -07001277 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001278 dragController.setDragScoller(mWorkspace);
1279 dragController.setScrollView(mDragLayer);
1280 dragController.setMoveTarget(mWorkspace);
1281 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001282 if (mSearchDropTargetBar != null) {
1283 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001284 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001285
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001286 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001287 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001288 mWeightWatcher = new WeightWatcher(this);
1289 mWeightWatcher.setAlpha(0.5f);
1290 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001291 new FrameLayout.LayoutParams(
1292 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001293 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001294 Gravity.BOTTOM)
1295 );
Adam Cohen39a06042013-07-19 14:30:12 -07001296
1297 boolean show = shouldShowWeightWatcher();
1298 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001299 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 }
1301
1302 /**
1303 * Creates a view representing a shortcut.
1304 *
1305 * @param info The data structure describing the shortcut.
1306 *
1307 * @return A View inflated from R.layout.application.
1308 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001309 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001311 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312 }
1313
1314 /**
1315 * Creates a view representing a shortcut inflated from the specified resource.
1316 *
1317 * @param layoutResId The id of the XML layout used to create the shortcut.
1318 * @param parent The group the shortcut belongs to.
1319 * @param info The data structure describing the shortcut.
1320 *
1321 * @return A View inflated from layoutResId.
1322 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001323 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001324 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1325 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327 return favorite;
1328 }
1329
1330 /**
1331 * Add an application shortcut to the workspace.
1332 *
1333 * @param data The intent describing the application.
1334 * @param cellInfo The position on screen where to create the shortcut.
1335 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001336 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001337 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001338 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001339
Adam Cohenfbba09b2011-07-18 21:43:05 -07001340 // First we check if we already know the exact location where we want to add this item.
1341 if (cellX >= 0 && cellY >= 0) {
1342 cellXY[0] = cellX;
1343 cellXY[1] = cellY;
1344 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001345 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001346 return;
1347 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001348
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001349 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001350
Romain Guy73b979d2009-06-09 12:57:21 -07001351 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001352 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001354 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001355 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001356 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001357 } else {
1358 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359 }
1360 }
Romain Guycbb89e42009-06-08 15:52:54 -07001361
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 /**
1363 * Add a shortcut to the workspace.
1364 *
1365 * @param data The intent describing the shortcut.
1366 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001368 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001369 int cellY) {
1370 int[] cellXY = mTmpAddItemCellCoordinates;
1371 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001372 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001373
Michael Jurkad3ef3062010-11-23 16:23:58 -08001374 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001375
Adam Cohen558baaf2011-08-15 15:22:57 -07001376 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001377 if (info == null) {
1378 return;
1379 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001380 final View view = createShortcut(info);
1381
Adam Cohenfbba09b2011-07-18 21:43:05 -07001382 // First we check if we already know the exact location where we want to add this item.
1383 if (cellX >= 0 && cellY >= 0) {
1384 cellXY[0] = cellX;
1385 cellXY[1] = cellY;
1386 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001387
1388 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001389 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001390 true, null,null)) {
1391 return;
1392 }
1393 DragObject dragObject = new DragObject();
1394 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001395 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1396 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001397 return;
1398 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001399 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001400 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001401 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001402 foundCellSpan = (result != null);
1403 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001404 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001405 }
1406
1407 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001408 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 return;
1410 }
1411
Adam Cohendcd297f2013-06-18 13:13:40 -07001412 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001413
1414 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001415 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001416 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 }
1418 }
1419
Adam Cohen2f093b62012-04-30 18:59:53 -07001420 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1421 int minHeight) {
1422 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001423 // We want to account for the extra amount of padding that we are adding to the widget
1424 // to ensure that it gets the full amount of space that it has requested
1425 int requiredWidth = minWidth + padding.left + padding.right;
1426 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001427 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001428 }
1429
Adam Cohen2f093b62012-04-30 18:59:53 -07001430 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1431 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001432 }
1433
Adam Cohen2f093b62012-04-30 18:59:53 -07001434 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1435 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001436 }
1437
Adam Cohen2f093b62012-04-30 18:59:53 -07001438 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1439 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001440 }
1441
Adam Cohen2f093b62012-04-30 18:59:53 -07001442 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1443 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001444 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001445 }
1446
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001448 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001449 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001450 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001451 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001453 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001454 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1455 if (appWidgetInfo == null) {
1456 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1457 }
Romain Guycbb89e42009-06-08 15:52:54 -07001458
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001459 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001460 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001461
Adam Cohen2f093b62012-04-30 18:59:53 -07001462 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1463 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001464
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001465 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001466 // We have saved the position to which the widget was dragged-- this really only matters
1467 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001468 int[] cellXY = mTmpAddItemCellCoordinates;
1469 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001470 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001471 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001472 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1473 cellXY[0] = mPendingAddInfo.cellX;
1474 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001475 spanXY[0] = mPendingAddInfo.spanX;
1476 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001477 foundCellSpan = true;
1478 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001479 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001480 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001481 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1482 spanXY[1], cellXY, finalSpan);
1483 spanXY[0] = finalSpan[0];
1484 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001485 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001486 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001487 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001488 }
1489
Michael Jurka0280c3b2010-09-17 15:00:07 -07001490 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001491 if (appWidgetId != -1) {
1492 // Deleting an app widget ID is a void call but writes to disk before returning
1493 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001494 new AsyncTask<Void, Void, Void>() {
1495 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001496 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001497 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001498 }
Michael Jurka43467462013-11-14 12:03:58 +01001499 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001500 }
Winson Chung93eef082012-03-23 15:59:27 -07001501 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001502 return;
1503 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001505 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001506 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1507 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001508 launcherInfo.spanX = spanXY[0];
1509 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001510 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1511 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001512
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001514 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515
1516 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001517 if (hostView == null) {
1518 // Perform actual inflation because we're live
1519 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1520 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1521 } else {
1522 // The AppWidgetHostView has already been inflated and instantiated
1523 launcherInfo.hostView = hostView;
1524 }
Romain Guycbb89e42009-06-08 15:52:54 -07001525
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001527 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001528 launcherInfo.notifyWidgetSizeChanged(this);
1529
Adam Cohendcd297f2013-06-18 13:13:40 -07001530 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001531 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001532
1533 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001534 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001535 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536 }
Romain Guycbb89e42009-06-08 15:52:54 -07001537
Adam Cohended9f8d2010-11-03 13:25:16 -07001538 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1539 @Override
1540 public void onReceive(Context context, Intent intent) {
1541 final String action = intent.getAction();
1542 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1543 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001544 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001545 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001546
Winson Chungc100e8e2011-08-09 16:02:43 -07001547 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001548 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001549 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001550 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001551 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001552 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1553 mUserPresent = true;
1554 updateRunning();
1555 }
1556 }
1557 };
1558
1559 @Override
1560 public void onAttachedToWindow() {
1561 super.onAttachedToWindow();
1562
1563 // Listen for broadcasts related to user-presence
1564 final IntentFilter filter = new IntentFilter();
1565 filter.addAction(Intent.ACTION_SCREEN_OFF);
1566 filter.addAction(Intent.ACTION_USER_PRESENT);
1567 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001568 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001569 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001570 mVisible = true;
1571 }
1572
1573 @Override
1574 public void onDetachedFromWindow() {
1575 super.onDetachedFromWindow();
1576 mVisible = false;
1577
Adam Cohend113e0c2010-11-11 10:48:05 -08001578 if (mAttached) {
1579 unregisterReceiver(mReceiver);
1580 mAttached = false;
1581 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001582 updateRunning();
1583 }
1584
1585 public void onWindowVisibilityChanged(int visibility) {
1586 mVisible = visibility == View.VISIBLE;
1587 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001588 // The following code used to be in onResume, but it turns out onResume is called when
1589 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1590 // is a more appropriate event to handle
1591 if (mVisible) {
1592 mAppsCustomizeTabHost.onWindowVisible();
1593 if (!mWorkspaceLoading) {
1594 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001595 // We want to let Launcher draw itself at least once before we force it to build
1596 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001597 // apps is nice and speedy.
1598 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001599 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001600 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001601 if (mStarted) return;
1602 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001603 // We delay the layer building a bit in order to give
1604 // other message processing a time to run. In particular
1605 // this avoids a delay in hiding the IME if it was
1606 // currently shown, because doing that may involve
1607 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001608 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001609 final ViewTreeObserver.OnDrawListener listener = this;
1610 mWorkspace.post(new Runnable() {
1611 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001612 if (mWorkspace != null &&
1613 mWorkspace.getViewTreeObserver() != null) {
1614 mWorkspace.getViewTreeObserver().
1615 removeOnDrawListener(listener);
1616 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001617 }
1618 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001619 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001620 }
1621 });
1622 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001623 // When Launcher comes back to foreground, a different Activity might be responsible for
1624 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001625 if (!DISABLE_MARKET_BUTTON) {
1626 updateAppMarketIcon();
1627 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001628 clearTypedText();
1629 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001630 }
1631
1632 private void sendAdvanceMessage(long delay) {
1633 mHandler.removeMessages(ADVANCE_MSG);
1634 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1635 mHandler.sendMessageDelayed(msg, delay);
1636 mAutoAdvanceSentTime = System.currentTimeMillis();
1637 }
1638
1639 private void updateRunning() {
1640 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1641 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1642 mAutoAdvanceRunning = autoAdvanceRunning;
1643 if (autoAdvanceRunning) {
1644 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1645 sendAdvanceMessage(delay);
1646 } else {
1647 if (!mWidgetsToAdvance.isEmpty()) {
1648 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1649 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1650 }
1651 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001652 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001653 }
1654 }
1655 }
1656
1657 private final Handler mHandler = new Handler() {
1658 @Override
1659 public void handleMessage(Message msg) {
1660 if (msg.what == ADVANCE_MSG) {
1661 int i = 0;
1662 for (View key: mWidgetsToAdvance.keySet()) {
1663 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1664 final int delay = mAdvanceStagger * i;
1665 if (v instanceof Advanceable) {
1666 postDelayed(new Runnable() {
1667 public void run() {
1668 ((Advanceable) v).advance();
1669 }
1670 }, delay);
1671 }
1672 i++;
1673 }
1674 sendAdvanceMessage(mAdvanceInterval);
1675 }
1676 }
1677 };
1678
1679 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001680 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001681 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1682 if (v instanceof Advanceable) {
1683 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001684 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001685 updateRunning();
1686 }
1687 }
1688
1689 void removeWidgetToAutoAdvance(View hostView) {
1690 if (mWidgetsToAdvance.containsKey(hostView)) {
1691 mWidgetsToAdvance.remove(hostView);
1692 updateRunning();
1693 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001694 }
1695
Joe Onorato9c1289c2009-08-17 11:03:03 -04001696 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001697 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001698 launcherInfo.hostView = null;
1699 }
1700
Winson Chung93eef082012-03-23 15:59:27 -07001701 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1702 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1703 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001704 }
1705
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001706 public LauncherAppWidgetHost getAppWidgetHost() {
1707 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 }
Romain Guycbb89e42009-06-08 15:52:54 -07001709
Winson Chunga9abd0e2010-10-27 17:18:37 -07001710 public LauncherModel getModel() {
1711 return mModel;
1712 }
1713
Bjorn Bringertc459e522013-06-07 19:36:01 +01001714 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001715 getWindow().closeAllPanels();
1716
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001717 // Whatever we were doing is hereby canceled.
1718 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001719 }
1720
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 @Override
1722 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001723 long startTime = 0;
1724 if (DEBUG_RESUME_TIME) {
1725 startTime = System.currentTimeMillis();
1726 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 super.onNewIntent(intent);
1728
1729 // Close the menu
1730 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001731 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001732 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001733
Adam Cohened307df2013-10-02 09:37:31 -07001734 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1735 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1736 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001737
Adam Cohen6fecd412013-10-02 17:41:50 -07001738 if (mWorkspace == null) {
1739 // Can be cases where mWorkspace is null, this prevents a NPE
1740 return;
1741 }
1742 Folder openFolder = mWorkspace.getOpenFolder();
1743 // In all these cases, only animate if we're already on home
1744 mWorkspace.exitWidgetResizeMode();
1745 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001746 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001747 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001748 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001749
Adam Cohen6fecd412013-10-02 17:41:50 -07001750 closeFolder();
1751 exitSpringLoadedDragMode();
1752
1753 // If we are already on home, then just animate back to the workspace,
1754 // otherwise, just wait until onResume to set the state back to Workspace
1755 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001756 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001757 } else {
1758 mOnResumeState = State.WORKSPACE;
1759 }
1760
1761 final View v = getWindow().peekDecorView();
1762 if (v != null && v.getWindowToken() != null) {
1763 InputMethodManager imm = (InputMethodManager)getSystemService(
1764 INPUT_METHOD_SERVICE);
1765 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1766 }
1767
1768 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001769 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001770 mAppsCustomizeTabHost.reset();
1771 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001772
1773 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 }
Adam Cohened307df2013-10-02 09:37:31 -07001775
Michael Jurka447bf842013-05-15 14:52:15 +02001776 if (DEBUG_RESUME_TIME) {
1777 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1778 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779 }
1780
Adam Coppa120b8e2013-11-12 16:26:04 +00001781 /**
1782 * Override point for subclasses to prevent movement to the default screen when the home
1783 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1784 */
1785 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1786 return true;
1787 }
1788
1789 /**
1790 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1791 */
1792 protected void onHomeIntent() {
1793 // Do nothing
1794 }
1795
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001797 public void onRestoreInstanceState(Bundle state) {
1798 super.onRestoreInstanceState(state);
1799 for (int page: mSynchronouslyBoundPages) {
1800 mWorkspace.restoreInstanceStateForChild(page);
1801 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 }
1803
1804 @Override
1805 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001806 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001807 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1808 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001809 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001810 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811
Michael Jurka883f55b2010-10-21 15:47:14 -07001812 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001813 // We close any open folder since it will not be re-opened, and we need to make sure
1814 // this state is reflected.
1815 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816
Adam Cohendcd297f2013-06-18 13:13:40 -07001817 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001818 mWaitingForResult) {
1819 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001820 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001821 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1822 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001823 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1824 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1825 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001826 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 }
1828
1829 if (mFolderInfo != null && mWaitingForResult) {
1830 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1831 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1832 }
Michael Jurka946ad472010-07-09 18:05:18 -07001833
Winson Chung785d2eb2011-04-14 16:08:02 -07001834 // Save the current AppsCustomize tab
1835 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001836 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1837 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001838 if (currentTabTag != null) {
1839 outState.putString("apps_customize_currentTab", currentTabTag);
1840 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001841 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1842 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001843 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001844 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
1846
1847 @Override
1848 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001850
Winson Chunge7a03942011-08-05 15:05:12 -07001851 // Remove all pending runnables
1852 mHandler.removeMessages(ADVANCE_MSG);
1853 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001854 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001855
Winson Chungcd2b0142011-06-08 16:02:26 -07001856 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001857 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001858 mModel.stopLoader();
1859 app.setLauncher(null);
1860
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001862 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001863 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001864 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001866 mAppWidgetHost = null;
1867
1868 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001869
1870 TextKeyListener.getInstance().release();
1871
Winson Chung81b52252012-08-27 15:34:29 -07001872 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1873 // to prevent leaking Launcher activities on orientation change.
1874 if (mModel != null) {
1875 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1876 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001877
1878 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001879 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001880
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001881 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001882 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001883 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001884 mWorkspace = null;
1885 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001886
Michael Jurka2ecf9952012-06-18 12:52:28 -07001887 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 }
1889
Adam Cohena9cf38f2011-05-02 15:36:58 -07001890 public DragController getDragController() {
1891 return mDragController;
1892 }
1893
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 @Override
1895 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001896 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 super.startActivityForResult(intent, requestCode);
1898 }
1899
Winson Chung70d72102011-08-12 11:24:35 -07001900 /**
1901 * Indicates that we want global search for this activity by setting the globalSearch
1902 * argument for {@link #startSearch} to true.
1903 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001904 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001905 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001907
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001908 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001909
Karl Rosaen138a0412009-04-23 19:00:21 -07001910 if (initialQuery == null) {
1911 // Use any text typed in the launcher as the initial query
1912 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001913 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 if (appSearchData == null) {
1915 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001916 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 }
Winson Chungadf0c182012-08-23 14:59:07 -07001918 Rect sourceBounds = new Rect();
1919 if (mSearchDropTargetBar != null) {
1920 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1921 }
Romain Guycbb89e42009-06-08 15:52:54 -07001922
Bjorn Bringertc459e522013-06-07 19:36:01 +01001923 startSearch(initialQuery, selectInitialQuery,
1924 appSearchData, sourceBounds);
1925 }
1926
1927 public void startSearch(String initialQuery,
1928 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001929 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001930 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001931 }
1932
1933 /**
1934 * Starts the global search activity. This code is a copied from SearchManager
1935 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001936 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001937 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001938 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001939 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1940 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1941 if (globalSearchActivity == null) {
1942 Log.w(TAG, "No global search activity found.");
1943 return;
1944 }
1945 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1946 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1947 intent.setComponent(globalSearchActivity);
1948 // Make sure that we have a Bundle to put source in
1949 if (appSearchData == null) {
1950 appSearchData = new Bundle();
1951 } else {
1952 appSearchData = new Bundle(appSearchData);
1953 }
1954 // Set source to package name of app that starts global search, if not set already.
1955 if (!appSearchData.containsKey("source")) {
1956 appSearchData.putString("source", getPackageName());
1957 }
1958 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1959 if (!TextUtils.isEmpty(initialQuery)) {
1960 intent.putExtra(SearchManager.QUERY, initialQuery);
1961 }
1962 if (selectInitialQuery) {
1963 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1964 }
1965 intent.setSourceBounds(sourceBounds);
1966 try {
1967 startActivity(intent);
1968 } catch (ActivityNotFoundException ex) {
1969 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 }
1972
Winson Chung70d72102011-08-12 11:24:35 -07001973 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001974 public boolean onPrepareOptionsMenu(Menu menu) {
1975 super.onPrepareOptionsMenu(menu);
Dan Sandler14c6a3f2014-01-07 14:12:27 -05001976 showOverviewMode(true);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001977 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001978 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001980 @Override
1981 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001982 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001983 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001984 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001985 }
1986
Joe Onorato9c1289c2009-08-17 11:03:03 -04001987 public boolean isWorkspaceLocked() {
1988 return mWorkspaceLoading || mWaitingForResult;
1989 }
1990
Michael Jurka0280c3b2010-09-17 15:00:07 -07001991 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001992 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001993 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001994 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1995 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001996 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001997 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001998 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001999
Adam Cohenad4e15c2013-10-17 16:21:35 -07002000 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2001 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2002 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2003 }
2004
2005 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2006 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2007 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002008 if (appWidgetInfo.configure != null) {
2009 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002010 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002011
Bjorn Bringert7984c942009-12-09 15:38:25 +00002012 // Launch over to configure widget, if needed
2013 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002014 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002015 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002016 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002018 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002019 Runnable onComplete = new Runnable() {
2020 @Override
2021 public void run() {
2022 // Exit spring loaded mode if necessary after adding the widget
2023 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2024 null);
2025 }
2026 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002027 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002028 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002029 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 }
2031 }
Romain Guycbb89e42009-06-08 15:52:54 -07002032
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002033 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002034 // Close any folders that may be open.
2035 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002036 mWorkspace.moveToCustomContentScreen(animate);
2037 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002038 /**
2039 * Process a shortcut drop.
2040 *
2041 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002042 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002043 * @param cell The cell it should be added to, optional
2044 * @param position The location on the screen where it was dropped, optional
2045 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002046 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002047 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002048 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002049 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002050 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002051 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002052
2053 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002054 mPendingAddInfo.cellX = cell[0];
2055 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002056 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002057
2058 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2059 createShortcutIntent.setComponent(componentName);
2060 processShortcut(createShortcutIntent);
2061 }
2062
Adam Cohenfbba09b2011-07-18 21:43:05 -07002063 /**
2064 * Process a widget drop.
2065 *
2066 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002067 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002068 * @param cell The cell it should be added to, optional
2069 * @param position The location on the screen where it was dropped, optional
2070 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002071 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002072 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002073 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002074 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002075 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002076 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002077 mPendingAddInfo.minSpanX = info.minSpanX;
2078 mPendingAddInfo.minSpanY = info.minSpanY;
2079
Adam Cohenfbba09b2011-07-18 21:43:05 -07002080 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002081 mPendingAddInfo.cellX = cell[0];
2082 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002083 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002084 if (span != null) {
2085 mPendingAddInfo.spanX = span[0];
2086 mPendingAddInfo.spanY = span[1];
2087 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002088
Adam Cohened66b2b2012-01-23 17:28:51 -08002089 AppWidgetHostView hostView = info.boundWidget;
2090 int appWidgetId;
2091 if (hostView != null) {
2092 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002093 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002094 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002095 // In this case, we either need to start an activity to get permission to bind
2096 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002097 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002098 Bundle options = info.bindOptions;
2099
2100 boolean success = false;
2101 if (options != null) {
2102 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2103 info.componentName, options);
2104 } else {
2105 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2106 info.componentName);
2107 }
2108 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002109 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002110 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002111 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002112 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2113 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2114 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002115 // TODO: we need to make sure that this accounts for the options bundle.
2116 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002117 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2118 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002119 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002120 }
2121
Joe Onoratodeb98af2010-02-19 14:59:39 -08002122 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002123 // Handle case where user selected "Applications"
2124 String applicationName = getResources().getString(R.string.group_applications);
2125 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002126
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002127 if (applicationName != null && applicationName.equals(shortcutName)) {
2128 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2129 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002130
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002131 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2132 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002133 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002134 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002135 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002136 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002137 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 }
2139
Winson Chung24ab2f12010-09-16 14:10:47 -07002140 void processWallpaper(Intent intent) {
2141 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2142 }
2143
Adam Cohendcd297f2013-06-18 13:13:40 -07002144 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002145 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002146 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002147 folderInfo.title = getText(R.string.folder_name);
2148
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002149 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002150 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002151 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002152 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153
2154 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002155 FolderIcon newFolder =
2156 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002157 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002158 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002159 // Force measure the new folder icon
2160 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2161 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002162 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 }
Romain Guycbb89e42009-06-08 15:52:54 -07002164
Joe Onorato9c1289c2009-08-17 11:03:03 -04002165 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002166 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002167 }
2168
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002169 protected void startWallpaper() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002170 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002171 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002172 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002173 }
2174
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002175 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002176 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002177 }
2178
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002179 /**
2180 * Registers various content observers. The current implementation registers
2181 * only a favorites observer to keep track of the favorites applications.
2182 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002183 private void registerContentObservers() {
2184 ContentResolver resolver = getContentResolver();
2185 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2186 true, mWidgetObserver);
2187 }
2188
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 @Override
2190 public boolean dispatchKeyEvent(KeyEvent event) {
2191 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2192 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002193 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002194 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002195 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002196 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002197 dumpState();
2198 return true;
2199 }
2200 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002201 }
2202 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2203 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002204 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002205 return true;
2206 }
2207 }
2208
2209 return super.dispatchKeyEvent(event);
2210 }
2211
Joe Onorato88ec0992009-11-19 13:16:06 -08002212 @Override
2213 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002214 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002215 if (mAppsCustomizeContent.getContentType() ==
2216 AppsCustomizePagedView.ContentType.Applications) {
2217 showWorkspace(true);
2218 } else {
2219 showOverviewMode(true);
2220 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002221 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002222 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002223 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002224 Folder openFolder = mWorkspace.getOpenFolder();
2225 if (openFolder.isEditingName()) {
2226 openFolder.dismissEditingName();
2227 } else {
2228 closeFolder();
2229 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002230 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002231 mWorkspace.exitWidgetResizeMode();
2232
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002233 // Back button is a no-op here, but give at least some feedback for the button press
2234 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002235 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002236 }
2237
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002239 * Re-listen when widgets are reset.
2240 */
2241 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002242 if (mAppWidgetHost != null) {
2243 mAppWidgetHost.startListening();
2244 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002245 }
2246
2247 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002248 * Launches the intent referred by the clicked shortcut.
2249 *
2250 * @param v The view representing the clicked shortcut.
2251 */
2252 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002253 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2254 // view has detached (it's possible for this to happen if the view is removed mid touch).
2255 if (v.getWindowToken() == null) {
2256 return;
2257 }
2258
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002259 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002260 return;
2261 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002262
Adam Cohen1697b792013-09-17 19:08:21 -07002263 if (v instanceof Workspace) {
2264 if (mWorkspace.isInOverviewMode()) {
2265 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002266 }
2267 return;
2268 }
2269
2270 if (v instanceof CellLayout) {
2271 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002272 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002273 }
2274 }
2275
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002276 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002277 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002278 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002279 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2280 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002281
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002282 // Check for special shortcuts
2283 if (intent.getComponent() != null) {
2284 final String shortcutClass = intent.getComponent().getClassName();
2285
2286 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chung82963d52013-10-09 11:20:57 -07002287 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002288 return;
2289 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2290 MemoryDumpActivity.startDump(this);
2291 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002292 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2293 toggleShowWeightWatcher();
2294 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002295 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002296 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002297
2298 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002299 int[] pos = new int[2];
2300 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002301 intent.setSourceBounds(new Rect(pos[0], pos[1],
2302 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002303
2304 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002305
Daniel Sandlerff02d492013-08-05 02:12:05 -04002306 mStats.recordLaunch(intent, shortcut);
2307
Michael Jurkaddd62e92011-02-16 17:49:14 -08002308 if (success && v instanceof BubbleTextView) {
2309 mWaitingForResume = (BubbleTextView) v;
2310 mWaitingForResume.setStayPressed(true);
2311 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002312 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002313 if (v instanceof FolderIcon) {
2314 FolderIcon fi = (FolderIcon) v;
2315 handleFolderClick(fi);
2316 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002317 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002318 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002319 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002320 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002321 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002322 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323 }
2324 }
2325
Michael Jurka0e260592010-06-30 17:07:39 -07002326 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002327 return false;
2328 }
2329
Michael Jurkaaf442092010-06-10 17:01:57 -07002330 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002331 * Event handler for the search button
2332 *
2333 * @param v The view that was clicked.
2334 */
2335 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002336 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2337
Amith Yamasania135ba82011-08-09 17:42:01 -07002338 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002339 }
2340
2341 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002342 * Event handler for the voice button
2343 *
2344 * @param v The view that was clicked.
2345 */
2346 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002347 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002348
Bjorn Bringertc459e522013-06-07 19:36:01 +01002349 startVoice();
2350 }
2351
2352 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002353 try {
2354 final SearchManager searchManager =
2355 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2356 ComponentName activityName = searchManager.getGlobalSearchActivity();
2357 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002358 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002359 if (activityName != null) {
2360 intent.setPackage(activityName.getPackageName());
2361 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002362 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002363 } catch (ActivityNotFoundException e) {
2364 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002365 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002366 startActivitySafely(null, intent, "onClickVoiceButton");
2367 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002368 }
2369
2370 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002371 * Event handler for the "grid" button that appears on the home screen, which
2372 * enters all apps mode.
2373 *
2374 * @param v The view that was clicked.
2375 */
2376 public void onClickAllAppsButton(View v) {
Winson Chunge7e97e62013-12-02 17:02:50 -08002377 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
Michael Jurka5130e402011-10-13 04:55:35 -07002378 }
2379
2380 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002381 // Provide the same haptic feedback that the system offers for virtual keys.
2382 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002383 }
2384
Adam Cohen61f560d2013-09-30 15:58:20 -07002385 public void performHapticFeedbackOnTouchDown(View v) {
2386 // Provide the same haptic feedback that the system offers for virtual keys.
2387 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2388 }
2389
2390 public View.OnTouchListener getHapticFeedbackTouchListener() {
2391 if (mHapticFeedbackTouchListener == null) {
2392 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2393 @Override
2394 public boolean onTouch(View v, MotionEvent event) {
2395 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2396 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2397 }
2398 return false;
2399 }
2400 };
2401 }
2402 return mHapticFeedbackTouchListener;
2403 }
2404
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002405 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002406 if (!DISABLE_MARKET_BUTTON) {
2407 if (mAppMarketIntent != null) {
2408 startActivitySafely(v, mAppMarketIntent, "app market");
2409 } else {
2410 Log.e(TAG, "Invalid app market intent.");
2411 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002412 }
2413 }
2414
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002415 /**
2416 * Called when the user stops interacting with the launcher.
2417 * This implies that the user is now on the homescreen and is not doing housekeeping.
2418 */
2419 protected void onInteractionEnd() {}
2420
2421 /**
2422 * Called when the user starts interacting with the launcher.
2423 * The possible interactions are:
2424 * - open all apps
2425 * - reorder an app shortcut, or a widget
2426 * - open the overview mode.
2427 * This is a good time to stop doing things that only make sense
2428 * when the user is on the homescreen and not doing housekeeping.
2429 */
2430 protected void onInteractionBegin() {}
2431
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002432 void startApplicationDetailsActivity(ComponentName componentName) {
2433 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002434 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2435 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002436 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002437 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002438 }
2439
Michael Jurka1e2f4652013-07-08 18:03:46 -07002440 // returns true if the activity was started
2441 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002442 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002443 // System applications cannot be installed. For now, show a toast explaining that.
2444 // We may give them the option of disabling apps this way.
2445 int messageId = R.string.uninstall_system_app_text;
2446 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002447 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002448 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002449 String packageName = componentName.getPackageName();
2450 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002451 Intent intent = new Intent(
2452 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002453 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2454 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002455 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002456 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002457 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002458 }
2459
Michael Jurka86a720e2012-05-09 11:23:23 -07002460 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002461 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002462
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002463 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002464 // Only launch using the new animation if the shortcut has not opted out (this is a
2465 // private contract between launcher and may be ignored in the future).
2466 boolean useLaunchAnimation = (v != null) &&
2467 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2468 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002469 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2470 v.getMeasuredWidth(), v.getMeasuredHeight());
2471
2472 startActivity(intent, opts.toBundle());
2473 } else {
2474 startActivity(intent);
2475 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002476 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002477 } catch (SecurityException e) {
2478 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002479 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002480 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002481 "or use the exported attribute for this activity. "
2482 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002483 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002484 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002485 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002486
Michael Jurka86a720e2012-05-09 11:23:23 -07002487 boolean startActivitySafely(View v, Intent intent, Object tag) {
2488 boolean success = false;
2489 try {
2490 success = startActivity(v, intent, tag);
2491 } catch (ActivityNotFoundException e) {
2492 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2493 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2494 }
2495 return success;
2496 }
2497
Adam Cohena9cf38f2011-05-02 15:36:58 -07002498 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002499 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002500 Folder openFolder = mWorkspace.getFolderForTag(info);
2501
2502 // If the folder info reports that the associated folder is open, then verify that
2503 // it is actually opened. There have been a few instances where this gets out of sync.
2504 if (info.opened && openFolder == null) {
2505 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002506 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002507 info.opened = false;
2508 }
2509
Adam Cohenfb91f302012-06-11 15:45:18 -07002510 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002511 // Close any open folder
2512 closeFolder();
2513 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002514 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002515 } else {
2516 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002517 int folderScreen;
2518 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002519 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002520 // .. and close it
2521 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002522 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002523 // Close any folder open on the current screen
2524 closeFolder();
2525 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002526 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002527 }
2528 }
2529 }
2530 }
2531
Adam Cohen268c4752012-06-06 17:47:33 -07002532 /**
2533 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2534 * in the DragLayer in the exact absolute location of the original FolderIcon.
2535 */
2536 private void copyFolderIconToImage(FolderIcon fi) {
2537 final int width = fi.getMeasuredWidth();
2538 final int height = fi.getMeasuredHeight();
2539
2540 // Lazy load ImageView, Bitmap and Canvas
2541 if (mFolderIconImageView == null) {
2542 mFolderIconImageView = new ImageView(this);
2543 }
2544 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2545 mFolderIconBitmap.getHeight() != height) {
2546 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2547 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2548 }
2549
2550 DragLayer.LayoutParams lp;
2551 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2552 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2553 } else {
2554 lp = new DragLayer.LayoutParams(width, height);
2555 }
2556
Adam Cohen307fe232012-08-16 17:55:58 -07002557 // The layout from which the folder is being opened may be scaled, adjust the starting
2558 // view size by this scale factor.
2559 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002560 lp.customPosition = true;
2561 lp.x = mRectForFolderAnimation.left;
2562 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002563 lp.width = (int) (scale * width);
2564 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002565
2566 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2567 fi.draw(mFolderIconCanvas);
2568 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002569 if (fi.getFolder() != null) {
2570 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2571 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002572 }
Adam Cohen268c4752012-06-06 17:47:33 -07002573 // Just in case this image view is still in the drag layer from a previous animation,
2574 // we remove it and re-add it.
2575 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2576 mDragLayer.removeView(mFolderIconImageView);
2577 }
2578 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002579 if (fi.getFolder() != null) {
2580 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002581 }
Adam Cohen268c4752012-06-06 17:47:33 -07002582 }
2583
Adam Cohen2801caf2011-05-13 20:57:39 -07002584 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002585 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002586 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2587 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2588 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2589
Adam Cohenc51934b2011-07-26 21:07:43 -07002590 FolderInfo info = (FolderInfo) fi.getTag();
2591 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2592 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002593 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2594 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002595 }
2596
Adam Cohen268c4752012-06-06 17:47:33 -07002597 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2598 copyFolderIconToImage(fi);
2599 fi.setVisibility(View.INVISIBLE);
2600
Michael Jurka2ecf9952012-06-18 12:52:28 -07002601 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002602 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002603 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2604 oa.start();
2605 }
2606
Adam Cohen268c4752012-06-06 17:47:33 -07002607 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002608 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002609 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2610 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2611 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2612
Adam Cohen268c4752012-06-06 17:47:33 -07002613 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002614
Adam Cohen268c4752012-06-06 17:47:33 -07002615 // We remove and re-draw the FolderIcon in-case it has changed
2616 mDragLayer.removeView(mFolderIconImageView);
2617 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002618 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002619 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002620 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002621 oa.addListener(new AnimatorListenerAdapter() {
2622 @Override
2623 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002624 if (cl != null) {
2625 cl.clearFolderLeaveBehind();
2626 // Remove the ImageView copy of the FolderIcon and make the original visible.
2627 mDragLayer.removeView(mFolderIconImageView);
2628 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002629 }
2630 }
2631 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002632 oa.start();
2633 }
2634
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002635 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002636 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002637 * is animated relative to the specified View. If the View is null, no animation
2638 * is played.
2639 *
2640 * @param folderInfo The FolderInfo describing the folder to open.
2641 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002642 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002643 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002644 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002645
Adam Cohena9cf38f2011-05-02 15:36:58 -07002646 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002647
Adam Cohen4554ee12011-08-03 16:13:21 -07002648 // Just verify that the folder hasn't already been added to the DragLayer.
2649 // There was a one-off crash where the folder had a parent already.
2650 if (folder.getParent() == null) {
2651 mDragLayer.addView(folder);
2652 mDragController.addDropTarget((DropTarget) folder);
2653 } else {
2654 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2655 folder.getParent() + ").");
2656 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002657 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002658 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002659
2660 // Notify the accessibility manager that this folder "window" has appeared and occluded
2661 // the workspace items
2662 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2663 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002664 }
2665
2666 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002667 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002668 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002669 if (folder.isEditingName()) {
2670 folder.dismissEditingName();
2671 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002672 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002673
2674 // Dismiss the folder cling
2675 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002676 }
2677 }
2678
2679 void closeFolder(Folder folder) {
2680 folder.getInfo().opened = false;
2681
2682 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2683 if (parent != null) {
2684 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2685 shrinkAndFadeInFolderIcon(fi);
2686 }
2687 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002688
2689 // Notify the accessibility manager that this folder "window" has disappeard and no
2690 // longer occludeds the workspace items
2691 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002692 }
2693
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002694 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002695 if (!isDraggingEnabled()) return false;
2696 if (isWorkspaceLocked()) return false;
2697 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002698
Adam Cohen1697b792013-09-17 19:08:21 -07002699 if (v instanceof Workspace) {
2700 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002701 if (mWorkspace.enterOverviewMode()) {
2702 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2703 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2704 return true;
2705 } else {
2706 return false;
2707 }
Adam Cohen1697b792013-09-17 19:08:21 -07002708 }
Adam Cohen1697b792013-09-17 19:08:21 -07002709 }
2710
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002711 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002712 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 }
2714
Michael Jurka0280c3b2010-09-17 15:00:07 -07002715 resetAddInfo();
2716 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002717 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002718 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002719 return true;
2720 }
2721
Winson Chung3d503fb2011-07-13 17:25:49 -07002722 // The hotseat touch handling does not go through Workspace, and we always allow long press
2723 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002724 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002725 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2726 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002727 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002728 // User long pressed on empty space
2729 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2730 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2731 // Disabling reordering until we sort out some issues.
2732 if (mWorkspace.isInOverviewMode()) {
2733 mWorkspace.startReordering(v);
2734 } else {
2735 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002736 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002737 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002738 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002739 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002740 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002741 }
2742 }
2743 }
2744 return true;
2745 }
2746
Winson Chung3d503fb2011-07-13 17:25:49 -07002747 boolean isHotseatLayout(View layout) {
2748 return mHotseat != null && layout != null &&
2749 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2750 }
2751 Hotseat getHotseat() {
2752 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002753 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002754 View getOverviewPanel() {
2755 return mOverviewPanel;
2756 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002757 SearchDropTargetBar getSearchBar() {
2758 return mSearchDropTargetBar;
2759 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002760
Winson Chung3d503fb2011-07-13 17:25:49 -07002761 /**
2762 * Returns the CellLayout of the specified container at the specified screen.
2763 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002764 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002765 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2766 if (mHotseat != null) {
2767 return mHotseat.getLayout();
2768 } else {
2769 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002770 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002771 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002772 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002773 }
2774 }
2775
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002776 Workspace getWorkspace() {
2777 return mWorkspace;
2778 }
2779
Daniel Sandler843e8602010-06-07 14:59:01 -04002780 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002781 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002782 }
2783
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002784 /**
2785 * Helper method for the cameraZoomIn/cameraZoomOut animations
2786 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002787 * @param scaleFactor The scale factor used for the zoom
2788 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002789 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002790 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002791 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002792 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002793
Craig Mautner360310b2012-10-26 15:13:08 -07002794 private void setWorkspaceBackground(boolean workspace) {
2795 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002796 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002797 }
2798
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002799 void updateWallpaperVisibility(boolean visible) {
2800 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2801 int curflags = getWindow().getAttributes().flags
2802 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2803 if (wpflags != curflags) {
2804 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2805 }
Craig Mautner360310b2012-10-26 15:13:08 -07002806 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002807 }
2808
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002809 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2810 if (v instanceof LauncherTransitionable) {
2811 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2812 }
2813 }
2814
Michael Jurkabed61d22012-02-14 22:51:29 -08002815 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2816 if (v instanceof LauncherTransitionable) {
2817 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2818 }
Winson Chung70442722012-02-10 15:43:22 -08002819
2820 // Update the workspace transition step as well
2821 dispatchOnLauncherTransitionStep(v, 0f);
2822 }
2823
2824 private void dispatchOnLauncherTransitionStep(View v, float t) {
2825 if (v instanceof LauncherTransitionable) {
2826 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2827 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002828 }
2829
2830 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2831 if (v instanceof LauncherTransitionable) {
2832 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2833 }
Winson Chung70442722012-02-10 15:43:22 -08002834
2835 // Update the workspace transition step as well
2836 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002837 }
2838
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002839 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002840 * Things to test when changing the following seven functions.
2841 * - Home from workspace
2842 * - from center screen
2843 * - from other screens
2844 * - Home from all apps
2845 * - from center screen
2846 * - from other screens
2847 * - Back from all apps
2848 * - from center screen
2849 * - from other screens
2850 * - Launch app from workspace and quit
2851 * - with back
2852 * - with home
2853 * - Launch app from all apps and quit
2854 * - with back
2855 * - with home
2856 * - Go to a screen that's not the default, then all
2857 * apps, and launch and app, and go back
2858 * - with back
2859 * -with home
2860 * - On workspace, long press power and go back
2861 * - with back
2862 * - with home
2863 * - On all apps, long press power and go back
2864 * - with back
2865 * - with home
2866 * - On workspace, power off
2867 * - On all apps, power off
2868 * - Launch an app and turn off the screen while in that app
2869 * - Go back with home key
2870 * - Go back with back key TODO: make this not go to workspace
2871 * - From all apps
2872 * - From workspace
2873 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2874 * - From all apps
2875 * - From the center workspace
2876 * - From another workspace
2877 */
2878
2879 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002880 * Zoom the camera out from the workspace to reveal 'toView'.
2881 * Assumes that the view to show is anchored at either the very top or very bottom
2882 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002883 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002884 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002885 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2886 showAppsCustomizeHelper(animated, springLoaded, contentType);
2887 }
2888 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2889 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002890 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002891 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002892 mStateAnimation.cancel();
2893 mStateAnimation = null;
2894 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002895 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002896
Winson Chungf0ea4d32011-06-06 14:27:16 -07002897 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2898 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2899 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002900 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002901 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002902 final int startDelay =
2903 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002904
Michael Jurkab3e22d92011-10-31 15:58:33 -07002905 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002906
Michael Jurkad74c9842011-07-10 12:44:21 -07002907 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002908 Animator workspaceAnim =
2909 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08002910 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08002911 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
2912 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07002913 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2914 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002915
2916 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002917 toView.setScaleX(scale);
2918 toView.setScaleY(scale);
2919 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2920 scaleAnim.
2921 scaleX(1f).scaleY(1f).
2922 setDuration(duration).
2923 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002924
Winson Chungf0ea4d32011-06-06 14:27:16 -07002925 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002926 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002927 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002928 .ofFloat(toView, "alpha", 0f, 1f)
2929 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002930 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002931 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2932 @Override
2933 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002934 if (animation == null) {
2935 throw new RuntimeException("animation is null");
2936 }
Winson Chung70442722012-02-10 15:43:22 -08002937 float t = (Float) animation.getAnimatedValue();
2938 dispatchOnLauncherTransitionStep(fromView, t);
2939 dispatchOnLauncherTransitionStep(toView, t);
2940 }
2941 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002942
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002943 // toView should appear right at the end of the workspace shrink
2944 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002945 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002946 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002947 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002948
2949 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002950 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002951 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002952 // Prepare the position
2953 toView.setTranslationX(0.0f);
2954 toView.setTranslationY(0.0f);
2955 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002956 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002957 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002958 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002959 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002960 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2961 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002962
Winson Chungc7d2b602012-05-16 17:02:20 -07002963 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002964 if (mSearchDropTargetBar != null) {
2965 mSearchDropTargetBar.hideSearchBar(false);
2966 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002967 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002968 });
2969
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002970 if (workspaceAnim != null) {
2971 mStateAnimation.play(workspaceAnim);
2972 }
Michael Jurka1899a362011-11-03 13:50:45 -07002973
2974 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002975
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002976 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2977 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002978
2979 // If any of the objects being animated haven't been measured/laid out
2980 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002981 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002982 (mWorkspace.getMeasuredWidth() == 0) ||
2983 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002984 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002985 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002986
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002987 final AnimatorSet stateAnimation = mStateAnimation;
2988 final Runnable startAnimRunnable = new Runnable() {
2989 public void run() {
2990 // Check that mStateAnimation hasn't changed while
2991 // we waited for a layout/draw pass
2992 if (mStateAnimation != stateAnimation)
2993 return;
2994 setPivotsForZoom(toView, scale);
2995 dispatchOnLauncherTransitionStart(fromView, animated, false);
2996 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002997 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002998 }
2999 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003000 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003001 final ViewTreeObserver observer = toView.getViewTreeObserver();
3002 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3003 public void onGlobalLayout() {
3004 startAnimRunnable.run();
3005 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3006 }
3007 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003008 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003009 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003010 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003011 } else {
3012 toView.setTranslationX(0.0f);
3013 toView.setTranslationY(0.0f);
3014 toView.setScaleX(1.0f);
3015 toView.setScaleY(1.0f);
3016 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003017 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003018
Daniel Sandlere4f98912013-06-25 15:13:26 -04003019 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003020 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003021 if (mSearchDropTargetBar != null) {
3022 mSearchDropTargetBar.hideSearchBar(false);
3023 }
Michael Jurkaabded662011-03-04 12:06:57 -08003024 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003025 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003026 dispatchOnLauncherTransitionStart(fromView, animated, false);
3027 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003028 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003029 dispatchOnLauncherTransitionStart(toView, animated, false);
3030 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003031 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003032 }
3033
3034 /**
3035 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003036 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003037 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003038 */
Adam Cohened307df2013-10-02 09:37:31 -07003039 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003040 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003041
Michael Jurkab3e22d92011-10-31 15:58:33 -07003042 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003043 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003044 mStateAnimation.cancel();
3045 mStateAnimation = null;
3046 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003047 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003048
Winson Chungf0ea4d32011-06-06 14:27:16 -07003049 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003050 final int fadeOutDuration =
3051 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003052 final float scaleFactor = (float)
3053 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3054 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003055 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003056 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003057 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003058 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3059 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003060 toState, animated, stagger, -1);
3061 } else if (toState == Workspace.State.SPRING_LOADED ||
3062 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003063 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003064 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003065 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003066
Michael Jurkab3e22d92011-10-31 15:58:33 -07003067 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003068 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003069 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003070 final LauncherViewPropertyAnimator scaleAnim =
3071 new LauncherViewPropertyAnimator(fromView);
3072 scaleAnim.
3073 scaleX(scaleFactor).scaleY(scaleFactor).
3074 setDuration(duration).
3075 setInterpolator(new Workspace.ZoomInInterpolator());
3076
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003077 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003078 .ofFloat(fromView, "alpha", 1f, 0f)
3079 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003080 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003081 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3082 @Override
3083 public void onAnimationUpdate(ValueAnimator animation) {
3084 float t = 1f - (Float) animation.getAnimatedValue();
3085 dispatchOnLauncherTransitionStep(fromView, t);
3086 dispatchOnLauncherTransitionStep(toView, t);
3087 }
3088 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003089
Michael Jurka2ecf9952012-06-18 12:52:28 -07003090 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003091
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003092 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3093 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003094 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003095
3096 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003097 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003098 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003099 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003100 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3101 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003102 if (onCompleteRunnable != null) {
3103 onCompleteRunnable.run();
3104 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003105 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003106 }
3107 });
3108
Winson Chungf0ea4d32011-06-06 14:27:16 -07003109 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003110 if (workspaceAnim != null) {
3111 mStateAnimation.play(workspaceAnim);
3112 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003113 dispatchOnLauncherTransitionStart(fromView, animated, true);
3114 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003115 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003116 } else {
3117 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003118 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003119 dispatchOnLauncherTransitionStart(fromView, animated, true);
3120 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003121 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003122 dispatchOnLauncherTransitionStart(toView, animated, true);
3123 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003124 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003125 }
3126
Michael Jurkae326f182011-11-21 14:05:46 -08003127 @Override
3128 public void onTrimMemory(int level) {
3129 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003130 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003131 mAppsCustomizeTabHost.onTrimMemory();
3132 }
3133 }
3134
Adam Cohened307df2013-10-02 09:37:31 -07003135 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003136 showWorkspace(animated, null);
3137 }
3138
Adam Cohened307df2013-10-02 09:37:31 -07003139 protected void showWorkspace() {
3140 showWorkspace(true);
3141 }
3142
Adam Cohened66b2b2012-01-23 17:28:51 -08003143 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003144 if (mWorkspace.isInOverviewMode()) {
3145 mWorkspace.exitOverviewMode(animated);
3146 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003147 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003148 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003149 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003150 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003151
Winson Chungc7d2b602012-05-16 17:02:20 -07003152 // Show the search bar (only animate if we were showing the drop target bar in spring
3153 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003154 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003155 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003156 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003157
Michael Jurkab3e22d92011-10-31 15:58:33 -07003158 // Set focus to the AppsCustomize button
3159 if (mAllAppsButton != null) {
3160 mAllAppsButton.requestFocus();
3161 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003162 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003163
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003164 // Change the state *after* we've called all the transition code
3165 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003166
Winson Chung5fb63472011-02-02 17:03:37 -08003167 // Resume the auto-advance of widgets
3168 mUserPresent = true;
3169 updateRunning();
3170
alanv1d4fde62012-10-17 13:15:47 -07003171 // Send an accessibility event to announce the context change
3172 getWindow().getDecorView()
3173 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003174
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003175 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003176 }
3177
Adam Cohened307df2013-10-02 09:37:31 -07003178 void showOverviewMode(boolean animated) {
3179 mWorkspace.setVisibility(View.VISIBLE);
3180 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3181 mState = State.WORKSPACE;
3182 onWorkspaceShown(animated);
3183 }
3184
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003185 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003186 }
3187
Winson Chung82963d52013-10-09 11:20:57 -07003188 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3189 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003190 if (mState != State.WORKSPACE) return;
3191
Winson Chung82963d52013-10-09 11:20:57 -07003192 if (resetPageToZero) {
3193 mAppsCustomizeTabHost.reset();
3194 }
Winson Chungc58497e2013-09-03 17:48:37 -07003195 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003196 mAppsCustomizeTabHost.requestFocus();
3197
Michael Jurkab3e22d92011-10-31 15:58:33 -07003198 // Change the state *after* we've called all the transition code
3199 mState = State.APPS_CUSTOMIZE;
3200
3201 // Pause the auto-advance of widgets until we are out of AllApps
3202 mUserPresent = false;
3203 updateRunning();
3204 closeFolder();
3205
3206 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003207 getWindow().getDecorView()
3208 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003209 }
3210
Adam Cohen7777d962011-08-18 18:58:38 -07003211 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003212 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003213 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003214 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003215 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003216 }
Adam Cohen7777d962011-08-18 18:58:38 -07003217
Adam Cohenad4e15c2013-10-17 16:21:35 -07003218 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003219 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003220 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3221
Winson Chunge7a03942011-08-05 15:05:12 -07003222 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003223 @Override
3224 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003225 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003226 // Before we show workspace, hide all apps again because
3227 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3228 // clean up our state transition functions
3229 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003230 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003231 } else {
3232 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003233 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003234 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003235 }, delay);
3236
Winson Chung557d6ed2011-07-08 15:34:52 -07003237 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003238
Michael Jurkad3ef3062010-11-23 16:23:58 -08003239 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003240 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003241 final boolean animated = true;
3242 final boolean springLoaded = true;
3243 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003244 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003245 }
3246 // Otherwise, we are not in spring loaded mode, so don't do anything.
3247 }
3248
Michael Jurkab3e22d92011-10-31 15:58:33 -07003249 void lockAllApps() {
3250 // TODO
3251 }
3252
3253 void unlockAllApps() {
3254 // TODO
3255 }
3256
Winson Chungf0ea4d32011-06-06 14:27:16 -07003257 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003258 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003259 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003260 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003261 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003262 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003263 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003264 int duration = 0;
3265 if (mSearchDropTargetBar != null) {
3266 duration = mSearchDropTargetBar.getTransitionInDuration();
3267 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003268 mHotseat.animate().alpha(1f).setDuration(duration);
3269 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003270 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003271 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003272 }
3273 }
3274 }
3275
3276 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003277 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003278 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003279 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003280 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003281 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003282 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003283 int duration = 0;
3284 if (mSearchDropTargetBar != null) {
3285 duration = mSearchDropTargetBar.getTransitionOutDuration();
3286 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003287 mHotseat.animate().alpha(0f).setDuration(duration);
3288 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003289 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003290 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003291 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003292 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003293 }
3294
Patrick Dubroy5f445422011-02-18 14:35:21 -08003295 /**
3296 * Add an item from all apps or customize onto the given workspace screen.
3297 * If layout is null, add to the current screen.
3298 */
3299 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003300 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003301 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003302 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003303 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003304
Winson Chungdff8ebb2011-09-08 17:25:31 -07003305 /** Maps the current orientation to an index for referencing orientation correct global icons */
3306 private int getCurrentOrientationIndexForGlobalIcons() {
3307 // default - 0, landscape - 1
3308 switch (getResources().getConfiguration().orientation) {
3309 case Configuration.ORIENTATION_LANDSCAPE:
3310 return 1;
3311 default:
3312 return 0;
3313 }
3314 }
3315
Michael Jurkaae65ee32012-04-30 11:45:54 -07003316 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003317 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003318 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003319 // Look for the toolbar icon specified in the activity meta-data
3320 Bundle metaData = packageManager.getActivityInfo(
3321 activityName, PackageManager.GET_META_DATA).metaData;
3322 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003323 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003324 if (iconResId != 0) {
3325 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003326 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003327 }
3328 }
3329 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003330 // This can happen if the activity defines an invalid drawable
3331 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3332 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003333 } catch (Resources.NotFoundException nfe) {
3334 // This can happen if the activity defines an invalid drawable
3335 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3336 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003337 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003338 return null;
3339 }
3340
3341 // if successful in getting icon, return it; otherwise, set button to use default drawable
3342 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003343 int buttonId, ComponentName activityName, int fallbackDrawableId,
3344 String toolbarResourceName) {
3345 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003346 Resources r = getResources();
3347 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3348 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003349
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003350 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003351 // If we were unable to find the icon via the meta-data, use a generic one
3352 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003353 toolbarIcon = r.getDrawable(fallbackDrawableId);
3354 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003355 if (button != null) {
3356 button.setCompoundDrawables(toolbarIcon, null, null, null);
3357 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003358 return null;
3359 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003360 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003361 if (button != null) {
3362 button.setCompoundDrawables(toolbarIcon, null, null, null);
3363 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003364 return toolbarIcon.getConstantState();
3365 }
3366 }
3367
3368 // if successful in getting icon, return it; otherwise, set button to use default drawable
3369 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003370 int buttonId, ComponentName activityName, int fallbackDrawableId,
3371 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003372 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003373 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003374
Michael Jurka19e0fc52011-07-22 18:00:21 -07003375 if (button != null) {
3376 // If we were unable to find the icon via the meta-data, use a
3377 // generic one
3378 if (toolbarIcon == null) {
3379 button.setImageResource(fallbackDrawableId);
3380 } else {
3381 button.setImageDrawable(toolbarIcon);
3382 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003383 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003384
3385 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3386
Michael Jurka0423dcf2010-10-05 14:56:18 -07003387 }
3388
Winson Chung1b884092012-06-08 17:13:02 -07003389 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003390 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003391 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003392 }
3393
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003394 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003395 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003396 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003397 }
3398
Winson Chungbb185bd2011-11-21 12:31:42 -08003399 private void invalidatePressedFocusedStates(View container, View button) {
3400 if (container instanceof HolographicLinearLayout) {
3401 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3402 layout.invalidatePressedFocusedStates();
3403 } else if (button instanceof HolographicImageView) {
3404 HolographicImageView view = (HolographicImageView) button;
3405 view.invalidatePressedFocusedStates();
3406 }
3407 }
3408
Cristina Stancu476493b2013-08-07 17:20:14 +01003409 public View getQsbBar() {
3410 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003411 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3412 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003413 }
3414 return mQsbBar;
3415 }
3416
3417 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003418 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003419 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003420 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003421 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003422
Winson Chung1cad91e2011-05-25 17:41:01 -07003423 final SearchManager searchManager =
3424 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3425 ComponentName activityName = searchManager.getGlobalSearchActivity();
3426 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003427 int coi = getCurrentOrientationIndexForGlobalIcons();
3428 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003429 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3430 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3431 if (sGlobalSearchIcon[coi] == null) {
3432 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3433 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3434 TOOLBAR_ICON_METADATA_NAME);
3435 }
3436
Winson Chungc51db6a2011-10-05 11:44:49 -07003437 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3438 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003439 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003440 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003441 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003442 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003443 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3444 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003445 if (searchButton != null) searchButton.setVisibility(View.GONE);
3446 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003447 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003448 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003449 }
3450 }
3451
Cristina Stancu476493b2013-08-07 17:20:14 +01003452 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003453 final View searchButtonContainer = findViewById(R.id.search_button_container);
3454 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003455 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003456 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003457 }
3458
Cristina Stancu476493b2013-08-07 17:20:14 +01003459 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003460 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003461 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003462
Winson Chungc51db6a2011-10-05 11:44:49 -07003463 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003464 final SearchManager searchManager =
3465 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3466 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3467
3468 ComponentName activityName = null;
3469 if (globalSearchActivity != null) {
3470 // Check if the global search activity handles voice search
3471 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3472 intent.setPackage(globalSearchActivity.getPackageName());
3473 activityName = intent.resolveActivity(getPackageManager());
3474 }
3475
3476 if (activityName == null) {
3477 // Fallback: check if an activity other than the global search activity
3478 // resolves this
3479 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3480 activityName = intent.resolveActivity(getPackageManager());
3481 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003482 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003483 int coi = getCurrentOrientationIndexForGlobalIcons();
3484 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003485 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3486 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3487 if (sVoiceSearchIcon[coi] == null) {
3488 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3489 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3490 TOOLBAR_ICON_METADATA_NAME);
3491 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003492 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003493 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003494 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003495 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003496 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003497 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003498 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003499 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003500 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003501 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003502 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003503 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003504
Cristina Stancu476493b2013-08-07 17:20:14 +01003505 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003506 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3507 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003508 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003509 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003510 }
3511
Winson Chung5841efa2013-09-30 18:06:44 -07003512 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003513 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3514 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003515 boolean visible = !forceDisableVoiceButtonProxy &&
3516 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003517 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003518 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003519 }
3520 }
Winson Chung5841efa2013-09-30 18:06:44 -07003521
3522 /**
3523 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3524 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3525 */
3526 public void disableVoiceButtonProxy(boolean disabled) {
3527 updateVoiceButtonProxyVisible(disabled);
3528 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003529 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003530 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003531 */
3532 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003533 if (!DISABLE_MARKET_BUTTON) {
3534 final View marketButton = findViewById(R.id.market_button);
3535 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3536 // Find the app market activity by resolving an intent.
3537 // (If multiple app markets are installed, it will return the ResolverActivity.)
3538 ComponentName activityName = intent.resolveActivity(getPackageManager());
3539 if (activityName != null) {
3540 int coi = getCurrentOrientationIndexForGlobalIcons();
3541 mAppMarketIntent = intent;
3542 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3543 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3544 TOOLBAR_ICON_METADATA_NAME);
3545 marketButton.setVisibility(View.VISIBLE);
3546 } else {
3547 // We should hide and disable the view so that we don't try and restore the visibility
3548 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3549 marketButton.setVisibility(View.GONE);
3550 marketButton.setEnabled(false);
3551 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003552 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003553 }
3554
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003555 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003556 if (!DISABLE_MARKET_BUTTON) {
3557 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3558 Resources r = getResources();
3559 Drawable marketIconDrawable = d.newDrawable(r);
3560 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3561 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3562 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003563
Winson Chungd64a6662013-09-30 11:06:59 -07003564 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3565 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003566 }
3567
Michael Jurkad7c28052012-04-27 15:43:36 -07003568 @Override
3569 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003570 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003571 final List<CharSequence> text = event.getText();
3572 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003573 // Populate event with a fake title based on the current state.
3574 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003575 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003576 } else {
3577 text.add(getString(R.string.all_apps_home_button_label));
3578 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003579 return result;
3580 }
3581
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003582 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003583 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003584 */
3585 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3586 @Override
3587 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003588 closeSystemDialogs();
3589 }
3590 }
3591
3592 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003593 * Receives notifications whenever the appwidgets are reset.
3594 */
3595 private class AppWidgetResetObserver extends ContentObserver {
3596 public AppWidgetResetObserver() {
3597 super(new Handler());
3598 }
3599
3600 @Override
3601 public void onChange(boolean selfChange) {
3602 onAppWidgetReset();
3603 }
3604 }
3605
3606 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003607 * If the activity is currently paused, signal that we need to run the passed Runnable
3608 * in onResume.
3609 *
3610 * This needs to be called from incoming places where resources might have been loaded
3611 * while we are paused. That is becaues the Configuration might be wrong
3612 * when we're not running, and if it comes back to what it was when we
3613 * were paused, we are not restarted.
3614 *
3615 * Implementation of the method from LauncherModel.Callbacks.
3616 *
3617 * @return true if we are currently paused. The caller might be able to
3618 * skip some work in that case since we will come back again.
3619 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003620 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003621 if (mPaused) {
3622 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003623 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003624 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003625 }
3626 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003627 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003628 return true;
3629 } else {
3630 return false;
3631 }
3632 }
3633
Michael Jurkac402cd92013-05-20 15:49:32 +02003634 private boolean waitUntilResume(Runnable run) {
3635 return waitUntilResume(run, false);
3636 }
3637
Michael Jurka1e2f4652013-07-08 18:03:46 -07003638 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003639 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003640 }
3641
Michael Jurka7607c2f2013-04-03 14:33:19 -07003642 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003643 * If the activity is currently paused, signal that we need to re-run the loader
3644 * in onResume.
3645 *
3646 * This needs to be called from incoming places where resources might have been loaded
3647 * while we are paused. That is becaues the Configuration might be wrong
3648 * when we're not running, and if it comes back to what it was when we
3649 * were paused, we are not restarted.
3650 *
3651 * Implementation of the method from LauncherModel.Callbacks.
3652 *
3653 * @return true if we are currently paused. The caller might be able to
3654 * skip some work in that case since we will come back again.
3655 */
3656 public boolean setLoadOnResume() {
3657 if (mPaused) {
3658 Log.i(TAG, "setLoadOnResume");
3659 mOnResumeNeedsLoad = true;
3660 return true;
3661 } else {
3662 return false;
3663 }
3664 }
3665
3666 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003667 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003668 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003669 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003670 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003671 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003672 } else {
3673 return SCREEN_COUNT / 2;
3674 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003675 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003676
Joe Onorato9c1289c2009-08-17 11:03:03 -04003677 /**
3678 * Refreshes the shortcuts shown on the workspace.
3679 *
3680 * Implementation of the method from LauncherModel.Callbacks.
3681 */
3682 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003683 // If we're starting binding all over again, clear any bind calls we'd postponed in
3684 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3685 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003686 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003687
Winson Chungd64d1762013-08-20 14:37:16 -07003688 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003689 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003690 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003691
Michael Jurka05bf644e2011-11-30 20:28:53 -08003692 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003693 if (mHotseat != null) {
3694 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003695 }
3696 }
3697
Adam Cohendcd297f2013-06-18 13:13:40 -07003698 @Override
3699 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003700 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003701
Adam Cohen5084cba2013-09-03 12:01:16 -07003702 // If there are no screens, we need to have an empty screen
3703 if (orderedScreenIds.size() == 0) {
3704 mWorkspace.addExtraEmptyScreen();
3705 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003706
3707 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003708 // setCurrentPage() so ensure that all pages are added before calling this).
3709 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003710 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3711 mWorkspace.createCustomContentPage();
3712 }
Winson Chung64359a52013-07-08 17:17:08 -07003713 }
3714
3715 @Override
3716 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003717 // Log to disk
3718 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3719 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3720 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003721 int count = orderedScreenIds.size();
3722 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003723 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003724 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003725 }
3726
Adam Cohen39a06042013-07-19 14:30:12 -07003727 private boolean shouldShowWeightWatcher() {
3728 String spKey = LauncherAppState.getSharedPreferencesKey();
3729 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003730 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003731
3732 return show;
3733 }
3734
3735 private void toggleShowWeightWatcher() {
3736 String spKey = LauncherAppState.getSharedPreferencesKey();
3737 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3738 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3739
3740 show = !show;
3741
3742 SharedPreferences.Editor editor = sp.edit();
3743 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3744 editor.commit();
3745
3746 if (mWeightWatcher != null) {
3747 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3748 }
3749 }
3750
Winson Chungd64d1762013-08-20 14:37:16 -07003751 public void bindAppsAdded(final ArrayList<Long> newScreens,
3752 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003753 final ArrayList<ItemInfo> addAnimated,
3754 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003755 Runnable r = new Runnable() {
3756 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003757 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003758 }
3759 };
3760 if (waitUntilResume(r)) {
3761 return;
3762 }
3763
Winson Chungd64d1762013-08-20 14:37:16 -07003764 // Add the new screens
3765 bindAddScreens(newScreens);
3766
3767 // We add the items without animation on non-visible pages, and with
3768 // animations on the new page (which we will try and snap to).
3769 if (!addNotAnimated.isEmpty()) {
3770 bindItems(addNotAnimated, 0,
3771 addNotAnimated.size(), false);
3772 }
3773 if (!addAnimated.isEmpty()) {
3774 bindItems(addAnimated, 0,
3775 addAnimated.size(), true);
3776 }
Winson Chungc58497e2013-09-03 17:48:37 -07003777
Winson Chung87412982013-10-03 18:34:14 -07003778 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003779 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003780
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003781 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003782 addedApps != null && mAppsCustomizeContent != null) {
3783 mAppsCustomizeContent.addApps(addedApps);
3784 }
Winson Chungd64d1762013-08-20 14:37:16 -07003785 }
3786
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003787 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003788 * Bind the items start-end from the list.
3789 *
3790 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003791 */
Winson Chung64359a52013-07-08 17:17:08 -07003792 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3793 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003794 Runnable r = new Runnable() {
3795 public void run() {
3796 bindItems(shortcuts, start, end, forceAnimateIcons);
3797 }
3798 };
3799 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003800 return;
3801 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003802
Winson Chungf0c6ae02012-03-21 16:10:31 -07003803 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003804 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3805 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003806 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003807 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003808 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003809 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003810 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003811
3812 // Short circuit if we are loading dock items for a configuration which has no dock
3813 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3814 mHotseat == null) {
3815 continue;
3816 }
3817
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818 switch (item.itemType) {
3819 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3820 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003821 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003822 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003823
Winson Chung64359a52013-07-08 17:17:08 -07003824 /*
3825 * TODO: FIX collision case
3826 */
Winson Chungce376632013-07-11 16:12:41 -07003827 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3828 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3829 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3830 throw new RuntimeException("OCCUPIED");
3831 }
Winson Chung64359a52013-07-08 17:17:08 -07003832 }
3833
Adam Cohendcd297f2013-06-18 13:13:40 -07003834 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3835 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003836 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003837 // Animate all the applications up now
3838 shortcut.setAlpha(0f);
3839 shortcut.setScaleX(0f);
3840 shortcut.setScaleY(0f);
3841 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003842 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003843 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003844 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003845 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003846 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003847 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003848 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003849 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3850 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003851 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003852 default:
3853 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003855 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003856
Winson Chung997a9232013-07-24 15:33:46 -07003857 if (animateIcons) {
3858 // Animate to the correct page
3859 if (newShortcutsScreenId > -1) {
3860 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003861 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003862 final Runnable startBounceAnimRunnable = new Runnable() {
3863 public void run() {
3864 anim.playTogether(bounceAnims);
3865 anim.start();
3866 }
3867 };
Winson Chung997a9232013-07-24 15:33:46 -07003868 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003869 // We post the animation slightly delayed to prevent slowdowns
3870 // when we are loading right after we return to launcher.
3871 mWorkspace.postDelayed(new Runnable() {
3872 public void run() {
3873 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003874 mWorkspace.postDelayed(startBounceAnimRunnable,
3875 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003876 }
3877 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003878 } else {
3879 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003880 }
3881 }
Winson Chung64359a52013-07-08 17:17:08 -07003882 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003883 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003884 }
3885
Joe Onorato9c1289c2009-08-17 11:03:03 -04003886 /**
3887 * Implementation of the method from LauncherModel.Callbacks.
3888 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003889 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003890 Runnable r = new Runnable() {
3891 public void run() {
3892 bindFolders(folders);
3893 }
3894 };
3895 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003896 return;
3897 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003898 sFolders.clear();
3899 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003900 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003901
3902 /**
3903 * Add the views for a widget to the workspace.
3904 *
3905 * Implementation of the method from LauncherModel.Callbacks.
3906 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003907 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003908 Runnable r = new Runnable() {
3909 public void run() {
3910 bindAppWidget(item);
3911 }
3912 };
3913 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003914 return;
3915 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003916
Daniel Sandler843e8602010-06-07 14:59:01 -04003917 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3918 if (DEBUG_WIDGETS) {
3919 Log.d(TAG, "bindAppWidget: " + item);
3920 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003921 final Workspace workspace = mWorkspace;
3922
3923 final int appWidgetId = item.appWidgetId;
3924 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003925 if (DEBUG_WIDGETS) {
3926 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3927 }
3928
Joe Onorato9c1289c2009-08-17 11:03:03 -04003929 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3930
Joe Onorato9c1289c2009-08-17 11:03:03 -04003931 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003932 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003933
Adam Cohendcd297f2013-06-18 13:13:40 -07003934 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003936 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3937
Joe Onorato9c1289c2009-08-17 11:03:03 -04003938 workspace.requestLayout();
3939
Daniel Sandler843e8602010-06-07 14:59:01 -04003940 if (DEBUG_WIDGETS) {
3941 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3942 + (SystemClock.uptimeMillis()-start) + "ms");
3943 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003944 }
3945
Adam Cohen1462de32012-07-24 22:34:36 -07003946 public void onPageBoundSynchronously(int page) {
3947 mSynchronouslyBoundPages.add(page);
3948 }
3949
Joe Onorato9c1289c2009-08-17 11:03:03 -04003950 /**
3951 * Callback saying that there aren't any more items to bind.
3952 *
3953 * Implementation of the method from LauncherModel.Callbacks.
3954 */
Adam Cohene25af792013-06-06 23:08:25 -07003955 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003956 Runnable r = new Runnable() {
3957 public void run() {
3958 finishBindingItems(upgradePath);
3959 }
3960 };
3961 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003962 return;
3963 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003964 if (mSavedState != null) {
3965 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003966 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003967 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003968 mSavedState = null;
3969 }
3970
Adam Cohen1462de32012-07-24 22:34:36 -07003971 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003972
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003973 // If we received the result of any pending adds while the loader was running (e.g. the
3974 // widget configuration forced an orientation change), process them now.
3975 for (int i = 0; i < sPendingAddList.size(); i++) {
3976 completeAdd(sPendingAddList.get(i));
3977 }
3978 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003979
Winson Chungc51db6a2011-10-05 11:44:49 -07003980 // Update the market app icon as necessary (the other icons will be managed in response to
3981 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003982 if (!DISABLE_MARKET_BUTTON) {
3983 updateAppMarketIcon();
3984 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003985
Winson Chungf0c6ae02012-03-21 16:10:31 -07003986 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003987 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003988 mWorkspace.getUniqueComponents(true, null);
3989 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003990 }
Adam Cohen99894d92013-06-14 11:22:59 -07003991
Adam Cohen66a01fd2013-06-11 12:48:00 -07003992 mWorkspace.post(new Runnable() {
3993 @Override
3994 public void run() {
3995 onFinishBindingItems();
3996 }
3997 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003998 }
3999
Winson Chunga0b7e862013-09-05 16:03:15 -07004000 public boolean isAllAppsButtonRank(int rank) {
4001 if (mHotseat != null) {
4002 return mHotseat.isAllAppsButtonRank(rank);
4003 }
4004 return false;
4005 }
4006
Winson Chunga2413752012-04-03 14:22:34 -07004007 private boolean canRunNewAppsAnimation() {
4008 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4009 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4010 }
4011
Winson Chungc9168342013-06-26 14:54:55 -07004012 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4013 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4014 PropertyValuesHolder.ofFloat("alpha", 1f),
4015 PropertyValuesHolder.ofFloat("scaleX", 1f),
4016 PropertyValuesHolder.ofFloat("scaleY", 1f));
4017 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4018 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4019 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4020 return bounceAnim;
4021 }
4022
Adam Cohen27772732013-11-11 14:00:56 +00004023 public boolean useVerticalBarLayout() {
4024 return LauncherAppState.getInstance().getDynamicGrid().
4025 getDeviceProfile().isVerticalBarLayout();
4026 }
4027
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004028 protected Rect getSearchBarBounds() {
4029 return LauncherAppState.getInstance().getDynamicGrid().
4030 getDeviceProfile().getSearchBarBounds();
4031 }
4032
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004033 @Override
4034 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004035 boolean searchVisible = updateGlobalSearchIcon();
4036 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004037 if (mSearchDropTargetBar != null) {
4038 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4039 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004040 }
4041
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004042 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004043 * Add the icons for all apps.
4044 *
4045 * Implementation of the method from LauncherModel.Callbacks.
4046 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004047 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004048 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004049 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4050 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4051 getHotseat().addAllAppsFolder(mIconCache, apps,
4052 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4053 }
4054 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004055 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004056 if (mAppsCustomizeContent != null) {
4057 mAppsCustomizeContent.onPackagesUpdated(
4058 LauncherModel.getSortedWidgetsAndShortcuts(this));
4059 }
Winson Chungc58497e2013-09-03 17:48:37 -07004060 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004061 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004062 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004063 mAppsCustomizeContent.onPackagesUpdated(
4064 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004065 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004066 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004067 }
4068
4069 /**
4070 * A package was updated.
4071 *
4072 * Implementation of the method from LauncherModel.Callbacks.
4073 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004074 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004075 Runnable r = new Runnable() {
4076 public void run() {
4077 bindAppsUpdated(apps);
4078 }
4079 };
4080 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004081 return;
4082 }
4083
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004084 if (mWorkspace != null) {
4085 mWorkspace.updateShortcuts(apps);
4086 }
Winson Chungc58497e2013-09-03 17:48:37 -07004087
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004088 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004089 mAppsCustomizeContent != null) {
4090 mAppsCustomizeContent.updateApps(apps);
4091 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004092 }
4093
4094 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004095 * A package was uninstalled. We take both the super set of packageNames
4096 * in addition to specific applications to remove, the reason being that
4097 * this can be called when a package is updated as well. In that scenario,
4098 * we only remove specific components from the workspace, where as
4099 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004100 *
4101 * Implementation of the method from LauncherModel.Callbacks.
4102 */
Winson Chung83892cc2013-05-01 16:53:33 -07004103 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Winson Chungdf95eb12013-10-16 14:57:07 -07004104 final ArrayList<AppInfo> appInfos) {
Winson Chungd64d1762013-08-20 14:37:16 -07004105 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004106 public void run() {
Winson Chungdf95eb12013-10-16 14:57:07 -07004107 bindComponentsRemoved(packageNames, appInfos);
Winson Chung83892cc2013-05-01 16:53:33 -07004108 }
Winson Chungd64d1762013-08-20 14:37:16 -07004109 };
4110 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004111 return;
4112 }
4113
Winson Chungdf95eb12013-10-16 14:57:07 -07004114 if (!packageNames.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004115 mWorkspace.removeItemsByPackageName(packageNames);
Winson Chungdf95eb12013-10-16 14:57:07 -07004116 }
4117 if (!appInfos.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004118 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004119 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004120
Winson Chunga1820962011-10-03 16:31:06 -07004121 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004122 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004123
Winson Chungdf95eb12013-10-16 14:57:07 -07004124 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004125 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004126 mAppsCustomizeContent != null) {
4127 mAppsCustomizeContent.removeApps(appInfos);
4128 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004129 }
Joe Onoratobe386092009-11-17 17:32:16 -08004130
4131 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004132 * A number of packages were updated.
4133 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004134 private ArrayList<Object> mWidgetsAndShortcuts;
4135 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004136 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004137 bindPackagesUpdated(mWidgetsAndShortcuts);
4138 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004139 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004140 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004141 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4142 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4143 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004144 return;
4145 }
4146
Winson Chung64359a52013-07-08 17:17:08 -07004147 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004148 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004149 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004150 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004151 }
4152
Winson Chung400438b2011-01-16 17:53:48 -08004153 private int mapConfigurationOriActivityInfoOri(int configOri) {
4154 final Display d = getWindowManager().getDefaultDisplay();
4155 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4156 switch (d.getRotation()) {
4157 case Surface.ROTATION_0:
4158 case Surface.ROTATION_180:
4159 // We are currently in the same basic orientation as the natural orientation
4160 naturalOri = configOri;
4161 break;
4162 case Surface.ROTATION_90:
4163 case Surface.ROTATION_270:
4164 // We are currently in the other basic orientation to the natural orientation
4165 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4166 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4167 break;
4168 }
4169
4170 int[] oriMap = {
4171 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4172 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4173 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4174 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4175 };
4176 // Since the map starts at portrait, we need to offset if this device's natural orientation
4177 // is landscape.
4178 int indexOffset = 0;
4179 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4180 indexOffset = 1;
4181 }
4182 return oriMap[(d.getRotation() + indexOffset) % 4];
4183 }
Adam Cohen446e9402011-09-15 18:21:21 -07004184
Winson Chung4b919f82012-05-01 10:44:08 -07004185 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004186 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004187 getResources().getBoolean(R.bool.allow_rotation);
4188 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004189 }
Winson Chung4b919f82012-05-01 10:44:08 -07004190 public void lockScreenOrientation() {
4191 if (isRotationEnabled()) {
4192 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4193 .getConfiguration().orientation));
4194 }
4195 }
4196 public void unlockScreenOrientation(boolean immediate) {
4197 if (isRotationEnabled()) {
4198 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004199 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004200 } else {
4201 mHandler.postDelayed(new Runnable() {
4202 public void run() {
4203 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4204 }
4205 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004206 }
Winson Chung4b919f82012-05-01 10:44:08 -07004207 }
Winson Chung400438b2011-01-16 17:53:48 -08004208 }
4209
Winson Chung82f55532011-08-09 14:14:23 -07004210 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004211 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004212 if (DISABLE_CLINGS) {
4213 return false;
4214 }
4215
Winson Chung3a6e7f32013-10-09 15:50:52 -07004216 // For now, limit only to phones
4217 LauncherAppState app = LauncherAppState.getInstance();
4218 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
4219 if (grid.isTablet()) {
4220 return false;
4221 }
Winson Chung13dbfe12013-10-31 11:42:39 -07004222 if (grid.isLandscape) {
4223 return false;
4224 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004225
Brett Chabot2a9e2282011-08-23 15:03:13 -07004226 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004227 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004228
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004229 // Disable clings for accessibility when explore by touch is enabled
4230 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4231 ACCESSIBILITY_SERVICE);
4232 if (a11yManager.isTouchExplorationEnabled()) {
4233 return false;
4234 }
4235
Michael Jurkae233a8b2013-03-19 13:49:20 +01004236 // Restricted secondary users (child mode) will potentially have very few apps
4237 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004238// boolean supportsLimitedUsers =
4239// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4240// Account[] accounts = AccountManager.get(this).getAccounts();
4241// if (supportsLimitedUsers && accounts.length == 0) {
4242// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4243// Bundle restrictions = um.getUserRestrictions();
4244// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4245// return false;
4246// }
4247// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004248 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004249 }
Michael Jurka22143132012-10-04 17:42:38 +02004250
Winson Chungfa545132013-09-26 17:45:32 -07004251 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004252 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004253 Cling cling = (Cling) findViewById(clingId);
4254 View scrim = null;
4255 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004256 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004257 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004258 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004259 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004260 cling.show(animate, SHOW_CLING_DURATION);
4261
4262 if (dimNavBarVisibilty) {
4263 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4264 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004265 }
4266 }
4267 return cling;
4268 }
Michael Jurka22143132012-10-04 17:42:38 +02004269
Winson Chungaf40f202013-09-18 18:26:31 -07004270 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4271 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004272 // To catch cases where siblings of top-level views are made invisible, just check whether
4273 // the cling is directly set to GONE before dismissing it.
4274 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004275 final Runnable cleanUpClingCb = new Runnable() {
4276 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004277 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004278 // We should update the shared preferences on a background thread
Michael Jurka43467462013-11-14 12:03:58 +01004279 new AsyncTask<Void, Void, Void>() {
4280 public Void doInBackground(Void ... args) {
Winson Chung46353de2012-02-16 14:05:10 -08004281 SharedPreferences.Editor editor = mSharedPrefs.edit();
4282 editor.putBoolean(flag, true);
4283 editor.commit();
Michael Jurka43467462013-11-14 12:03:58 +01004284 return null;
Winson Chung46353de2012-02-16 14:05:10 -08004285 }
Michael Jurka43467462013-11-14 12:03:58 +01004286 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungaf40f202013-09-18 18:26:31 -07004287 if (postAnimationCb != null) {
4288 postAnimationCb.run();
4289 }
4290 }
4291 };
4292 if (duration <= 0) {
4293 cleanUpClingCb.run();
4294 } else {
4295 cling.hide(duration, cleanUpClingCb);
4296 }
Michael Jurka22143132012-10-04 17:42:38 +02004297 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004298
4299 if (restoreNavBarVisibilty) {
4300 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4301 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4302 }
Winson Chung82f55532011-08-09 14:14:23 -07004303 }
4304 }
Michael Jurka22143132012-10-04 17:42:38 +02004305
Winson Chung9d9d74f2011-09-19 11:49:12 -07004306 private void removeCling(int id) {
4307 final View cling = findViewById(id);
4308 if (cling != null) {
4309 final ViewGroup parent = (ViewGroup) cling.getParent();
4310 parent.post(new Runnable() {
4311 @Override
4312 public void run() {
4313 parent.removeView(cling);
4314 }
4315 });
Michael Jurka22143132012-10-04 17:42:38 +02004316 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004317 }
4318 }
Michael Jurka974c3862012-05-22 22:00:31 -07004319
4320 private boolean skipCustomClingIfNoAccounts() {
4321 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4322 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4323 if (customCling) {
4324 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004325 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004326 Account[] accounts = am.getAccountsByType("com.google");
4327 return accounts.length == 0;
4328 }
4329 return false;
4330 }
4331
Winson Chung82e5c982013-10-09 12:04:50 -07004332 public void updateCustomContentHintVisibility() {
4333 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4334 String ccHintStr = getFirstRunCustomContentHint();
4335
4336 if (mWorkspace.hasCustomContent()) {
4337 // Show the custom content hint if ccHintStr is not empty
4338 if (cling != null) {
4339 setCustomContentHintVisibility(cling, ccHintStr, true, true);
4340 }
4341 } else {
4342 // Hide the custom content hint
4343 if (cling != null) {
4344 setCustomContentHintVisibility(cling, ccHintStr, false, true);
4345 }
4346 }
4347 }
4348
4349 private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible,
4350 boolean animate) {
4351 final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4352 if (ccHint != null) {
4353 if (visible && !ccHintStr.isEmpty()) {
4354 ccHint.setText(ccHintStr);
4355 ccHint.setVisibility(View.VISIBLE);
4356 if (animate) {
4357 ccHint.setAlpha(0f);
4358 ccHint.animate().alpha(1f)
4359 .setDuration(SHOW_CLING_DURATION)
4360 .start();
4361 } else {
4362 ccHint.setAlpha(1f);
4363 }
4364 } else {
4365 if (animate) {
4366 ccHint.animate().alpha(0f)
4367 .setDuration(SHOW_CLING_DURATION)
4368 .setListener(new AnimatorListenerAdapter() {
4369 @Override
4370 public void onAnimationEnd(Animator animation) {
4371 ccHint.setVisibility(View.GONE);
4372 }
4373 })
4374 .start();
4375 } else {
4376 ccHint.setAlpha(0f);
4377 ccHint.setVisibility(View.GONE);
4378 }
4379 }
4380 }
4381 }
4382
Winson Chungaf40f202013-09-18 18:26:31 -07004383 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004384 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004385 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004386 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004387 // If we're not using the default workspace layout, replace workspace cling
4388 // with a custom workspace cling (usually specified in an overlay)
4389 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004390 if (!DISABLE_CUSTOM_CLINGS) {
4391 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4392 getResources().getBoolean(R.bool.config_useCustomClings)) {
4393 // Use a custom cling
4394 View cling = findViewById(R.id.workspace_cling);
4395 ViewGroup clingParent = (ViewGroup) cling.getParent();
4396 int clingIndex = clingParent.indexOfChild(cling);
4397 clingParent.removeViewAt(clingIndex);
4398 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4399 clingParent.addView(customCling, clingIndex);
4400 customCling.setId(R.id.workspace_cling);
4401 }
4402 }
4403 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4404 if (cling != null) {
4405 String sbHintStr = getFirstRunClingSearchBarHint();
4406 String ccHintStr = getFirstRunCustomContentHint();
4407 if (!sbHintStr.isEmpty()) {
4408 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4409 sbHint.setText(sbHintStr);
4410 sbHint.setVisibility(View.VISIBLE);
4411 }
Winson Chung82e5c982013-10-09 12:04:50 -07004412 setCustomContentHintVisibility(cling, ccHintStr, true, false);
Michael Jurka45355c42012-10-08 13:21:35 +02004413 }
Winson Chungfa545132013-09-26 17:45:32 -07004414 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004415 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004416 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004417 }
4418 }
Winson Chungaf40f202013-09-18 18:26:31 -07004419
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004420 /**
4421 * Called when the SearchBar hint should be changed.
4422 *
4423 * @param hint the hint to be displayed in the search bar.
4424 */
4425 protected void onSearchBarHintChanged(String hint) {
4426 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4427 if (cling != null && cling.getVisibility() == View.VISIBLE && !hint.isEmpty()) {
4428 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4429 sbHint.setText(hint);
4430 sbHint.setVisibility(View.VISIBLE);
4431 }
4432 }
4433
Winson Chunge6eabff2013-09-24 11:01:23 -07004434 protected String getFirstRunClingSearchBarHint() {
4435 return "";
4436 }
4437 protected String getFirstRunCustomContentHint() {
4438 return "";
4439 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004440 protected int getFirstRunFocusedHotseatAppDrawableId() {
4441 return -1;
4442 }
4443 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4444 return null;
4445 }
4446 protected int getFirstRunFocusedHotseatAppRank() {
4447 return -1;
4448 }
4449 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4450 return "";
4451 }
4452 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4453 return "";
4454 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004455
Winson Chungaf40f202013-09-18 18:26:31 -07004456 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004457 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004458 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004459 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004460 Cling c = initCling(R.id.workspace_cling, 0, false, true);
4461
4462 // Set the focused hotseat app if there is one
4463 c.setFocusedHotseatApp(getFirstRunFocusedHotseatAppDrawableId(),
4464 getFirstRunFocusedHotseatAppRank(),
4465 getFirstRunFocusedHotseatAppComponentName(),
4466 getFirstRunFocusedHotseatAppBubbleTitle(),
4467 getFirstRunFocusedHotseatAppBubbleDescription());
Winson Chung9d9d74f2011-09-19 11:49:12 -07004468 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004469 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004470 }
4471 }
4472 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004473 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004474 if (isClingsEnabled() &&
4475 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004476 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4477 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004478 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004479 } else {
4480 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004481 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004482 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004483 }
Michael Jurka104c4562013-07-08 18:03:46 -07004484 protected SharedPreferences getSharedPrefs() {
4485 return mSharedPrefs;
4486 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004487 public boolean isFolderClingVisible() {
4488 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004489 if (cling != null) {
4490 return cling.getVisibility() == View.VISIBLE;
4491 }
4492 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004493 }
Winson Chungaf40f202013-09-18 18:26:31 -07004494 public void dismissFirstRunCling(View v) {
4495 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4496 Runnable cb = new Runnable() {
4497 public void run() {
4498 // Show the workspace cling next
4499 showFirstRunWorkspaceCling();
4500 }
4501 };
4502 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4503 DISMISS_CLING_DURATION, false);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004504
4505 // Fade out the search bar for the workspace cling coming up
4506 mSearchDropTargetBar.hideSearchBar(true);
Winson Chungaf40f202013-09-18 18:26:31 -07004507 }
Winson Chung82f55532011-08-09 14:14:23 -07004508 public void dismissWorkspaceCling(View v) {
4509 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004510 Runnable cb = null;
4511 if (v == null) {
4512 cb = new Runnable() {
4513 public void run() {
4514 mWorkspace.enterOverviewMode();
4515 }
4516 };
4517 }
4518 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4519 DISMISS_CLING_DURATION, true);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004520
4521 // Fade in the search bar
4522 mSearchDropTargetBar.showSearchBar(true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004523 }
4524 public void dismissFolderCling(View v) {
4525 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004526 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4527 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004528 }
4529
Mathew Inwood72fbec12013-11-19 15:45:07 +00004530 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
4531 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
4532 if (ri == null) {
4533 return null;
4534 }
4535 return new AppInfo(getPackageManager(), ri, mIconCache, null);
4536 }
4537
4538 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4539 Bitmap icon) {
4540 return new ShortcutInfo(shortcutIntent, caption, icon);
4541 }
4542
4543 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4544 dragView.setTag(dragInfo);
4545 mWorkspace.onDragStartedWithItem(dragView);
4546 mWorkspace.beginDragShared(dragView, source);
4547 }
4548
Winson Chung80baf5a2010-08-09 16:03:15 -07004549 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004550 * Prints out out state for debugging.
4551 */
4552 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004553 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004554 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004555 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4556 Log.d(TAG, "mRestoring=" + mRestoring);
4557 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4558 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004559 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004560 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004561
Winson Chung785d2eb2011-04-14 16:08:02 -07004562 if (mAppsCustomizeContent != null) {
4563 mAppsCustomizeContent.dumpState();
4564 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004565 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004566 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004567
4568 @Override
4569 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4570 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004571 synchronized (sDumpLogs) {
4572 writer.println(" ");
4573 writer.println("Debug logs: ");
4574 for (int i = 0; i < sDumpLogs.size(); i++) {
4575 writer.println(" " + sDumpLogs.get(i));
4576 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004577 }
4578 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004579
4580 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004581 if (DEBUG_DUMP_LOG) {
4582 synchronized (sDumpLogs) {
4583 Log.d(TAG, "");
4584 Log.d(TAG, "*********************");
4585 Log.d(TAG, "Launcher debug logs: ");
4586 for (int i = 0; i < sDumpLogs.size(); i++) {
4587 Log.d(TAG, " " + sDumpLogs.get(i));
4588 }
4589 Log.d(TAG, "*********************");
4590 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004591 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004592 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004593 }
4594
4595 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004596 addDumpLog(tag, log, null, debugLog);
4597 }
4598
4599 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004600 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004601 if (e != null) {
4602 Log.d(tag, log, e);
4603 } else {
4604 Log.d(tag, log);
4605 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004606 }
Winson Chungede41292013-09-19 16:27:36 -07004607 if (DEBUG_DUMP_LOG) {
4608 sDateStamp.setTime(System.currentTimeMillis());
4609 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004610 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4611 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004612 }
Winson Chungede41292013-09-19 16:27:36 -07004613 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004614 }
4615
Winson Chungede41292013-09-19 16:27:36 -07004616 public void dumpLogsToLocalData() {
4617 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004618 new AsyncTask<Void, Void, Void>() {
4619 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004620 boolean success = false;
4621 sDateStamp.setTime(sRunStart);
4622 String FILENAME = sDateStamp.getMonth() + "-"
4623 + sDateStamp.getDay() + "_"
4624 + sDateStamp.getHours() + "-"
4625 + sDateStamp.getMinutes() + "_"
4626 + sDateStamp.getSeconds() + ".txt";
4627
4628 FileOutputStream fos = null;
4629 File outFile = null;
4630 try {
4631 outFile = new File(getFilesDir(), FILENAME);
4632 outFile.createNewFile();
4633 fos = new FileOutputStream(outFile);
4634 } catch (Exception e) {
4635 e.printStackTrace();
4636 }
4637 if (fos != null) {
4638 PrintWriter writer = new PrintWriter(fos);
4639
4640 writer.println(" ");
4641 writer.println("Debug logs: ");
4642 synchronized (sDumpLogs) {
4643 for (int i = 0; i < sDumpLogs.size(); i++) {
4644 writer.println(" " + sDumpLogs.get(i));
4645 }
4646 }
4647 writer.close();
4648 }
4649 try {
4650 if (fos != null) {
4651 fos.close();
4652 success = true;
4653 }
4654 } catch (IOException e) {
4655 e.printStackTrace();
4656 }
Michael Jurka43467462013-11-14 12:03:58 +01004657 return null;
Winson Chungede41292013-09-19 16:27:36 -07004658 }
Michael Jurka43467462013-11-14 12:03:58 +01004659 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004660 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004661 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004662}
Michael Jurka2763be32011-02-24 11:19:57 -08004663
Michael Jurkaabded662011-03-04 12:06:57 -08004664interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004665 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004666 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004667 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004668 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004669 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004670}