blob: f83652023c4a8fcd42f7a084b9edf4c2d273adda [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080026import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080036import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040037import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080038import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070041import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070042import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070043import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080044import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070046import android.content.pm.PackageManager.NameNotFoundException;
Mathew Inwood72fbec12013-11-19 15:45:07 +000047import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070053import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040057import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070058import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020060import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080061import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070062import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070063import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040064import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070069import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070071import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Display;
74import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
76import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.MotionEvent;
80import android.view.Surface;
81import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070082import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.ViewGroup;
85import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080086import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070089import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080090import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
93import android.widget.FrameLayout;
94import android.widget.ImageView;
95import android.widget.TextView;
96import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070097
Daniel Sandler325dc232013-06-05 22:57:57 -040098import com.android.launcher3.DropTarget.DragObject;
Anjali Koppalf5d29132014-02-28 13:33:27 -080099import com.android.launcher3.PagedView.PageSwitchListener;
Romain Guyedcce092010-03-04 13:03:17 -0800100
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.DataInputStream;
102import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700103import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700108import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700109import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700111import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700114import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000115import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116
Winson Chunga6945242014-01-08 14:04:34 -0800117
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,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700123 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
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
Dan Sandlerd5024042014-01-09 15:01:33 -0500133 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800160 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161
Winson Chung2672ff92012-05-04 16:22:30 -0700162 // The Intent extra that defines whether to ignore the launch animation
163 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400164 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700165
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 // Type: int
167 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700168 // Type: int
169 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700171 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
172 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
174 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700175 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700177 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 // Type: boolean
179 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
180 // Type: long
181 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700182 // Type: int
183 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
184 // Type: int
185 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
186 // Type: parcelable
187 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000188 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800189 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000190 // Type: int[]
191 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192
Adam Cohenb54a5982014-01-08 15:21:04 -0800193
Adam Cohen432609a2014-03-13 17:03:22 -0700194 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800195 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
196
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100197 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700198 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100199 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700200 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100201 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700202
Adam Cohen39a06042013-07-19 14:30:12 -0700203 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700204 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700205
Winson Chunga6945242014-01-08 14:04:34 -0800206 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
207
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700208 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700209 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700210 private State mState = State.WORKSPACE;
211 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700212
Joe Onorato9c1289c2009-08-17 11:03:03 -0400213 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700214 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800215 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT_FOLDER_CLOSE = 400;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700216 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700217 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800220 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000222 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
223 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
224
Winson Chunga2413752012-04-03 14:22:34 -0700225 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700226 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
227 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700228 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700229
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800230 private final BroadcastReceiver mCloseSystemDialogsReceiver
231 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800232 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private LayoutInflater mInflater;
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700237 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800238 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800239 private DragLayer mDragLayer;
240 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700241 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800242 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700243
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700244 private AppWidgetManager mAppWidgetManager;
245 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700246
Michael Jurkac9d95c52011-08-29 14:03:34 -0700247 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700248 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800249 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700250
Michael Jurka0280c3b2010-09-17 15:00:07 -0700251 private int[] mTmpAddItemCellCoordinates = new int[2];
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private FolderInfo mFolderInfo;
254
Winson Chung3d503fb2011-07-13 17:25:49 -0700255 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800256 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700257
Michael Jurka838a4ca2011-02-07 13:33:06 -0800258 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700259
Winson Chungc51db6a2011-10-05 11:44:49 -0700260 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700261 private AppsCustomizeTabHost mAppsCustomizeTabHost;
262 private AppsCustomizePagedView mAppsCustomizeContent;
263 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800264 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
268 // scroll issues (because the workspace may not have been measured yet) and extra work.
269 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
270 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271
272 private SpannableStringBuilder mDefaultKeySsb = null;
273
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274 private boolean mWorkspaceLoading = true;
275
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800276 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 private boolean mRestoring;
278 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700279 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280
Michael Jurka1e2f4652013-07-08 18:03:46 -0700281 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700282 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
283
Winson Chung4a2afa32012-07-19 14:53:05 -0700284 // Keep track of whether the user has left launcher
285 private static boolean sPausedFromUserAction = false;
286
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287 private Bundle mSavedInstanceState;
288
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800290 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800291 private boolean mUserPresent = true;
292 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700293 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800294 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400295
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700296 private static LocaleConfiguration sLocaleConfiguration = null;
297
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700298 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700299
Adam Cohen61f560d2013-09-30 15:58:20 -0700300 private View.OnTouchListener mHapticFeedbackTouchListener;
301
Adam Cohended9f8d2010-11-03 13:25:16 -0700302 // Related to the auto-advancing of widgets
303 private final int ADVANCE_MSG = 1;
304 private final int mAdvanceInterval = 20000;
305 private final int mAdvanceStagger = 250;
306 private long mAutoAdvanceSentTime;
307 private long mAutoAdvanceTimeLeft = -1;
308 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
309 new HashMap<View, AppWidgetProviderInfo>();
310
Winson Chung400438b2011-01-16 17:53:48 -0800311 // Determines how long to wait after a rotation before restoring the screen orientation to
312 // match the sensor state.
313 private final int mRestoreScreenOrientationDelay = 500;
314
Michael Jurka4ef207b2010-11-29 17:05:45 -0800315 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700316 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
317 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
318 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800319
Winson Chungd64a6662013-09-30 11:06:59 -0700320 private Intent mAppMarketIntent = null;
321 private static final boolean DISABLE_MARKET_BUTTON = true;
322
Craig Mautner360310b2012-10-26 15:13:08 -0700323 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700324
Adam Cohen1462de32012-07-24 22:34:36 -0700325 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700326 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700327
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700328 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700329 static Date sDateStamp = new Date();
330 static DateFormat sDateFormat =
331 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
332 static long sRunStart = System.currentTimeMillis();
333 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700334
Winson Chung46353de2012-02-16 14:05:10 -0800335 // We only want to get the SharedPreferences once since it does an FS stat each time we get
336 // it from the context.
337 private SharedPreferences mSharedPrefs;
338
Adam Cohene25af792013-06-06 23:08:25 -0700339 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
340
Winson Chungf0c6ae02012-03-21 16:10:31 -0700341 // Holds the page that we need to animate to, and the icon views that we need to animate up
342 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700343 private ImageView mFolderIconImageView;
344 private Bitmap mFolderIconBitmap;
345 private Canvas mFolderIconCanvas;
346 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700347
Michael Jurkaddd62e92011-02-16 17:49:14 -0800348 private BubbleTextView mWaitingForResume;
349
Michael Jurkac1f5d262011-09-30 19:32:27 -0700350 private Runnable mBuildLayersRunnable = new Runnable() {
351 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700352 if (mWorkspace != null) {
353 mWorkspace.buildPageHardwareLayers();
354 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700355 }
356 };
357
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358 private static ArrayList<PendingAddArguments> sPendingAddList
359 = new ArrayList<PendingAddArguments>();
360
Michael Jurka7267fa52013-09-26 15:29:57 -0700361 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800362
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800363 private static class PendingAddArguments {
364 int requestCode;
365 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700366 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700367 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800368 int cellX;
369 int cellY;
370 }
371
Daniel Sandlerff02d492013-08-05 02:12:05 -0400372 private Stats mStats;
373
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800374 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800375 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 @Override
379 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700380 if (DEBUG_STRICT_MODE) {
381 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
382 .detectDiskReads()
383 .detectDiskWrites()
384 .detectNetwork() // or .detectAll() for all detectable problems
385 .penaltyLog()
386 .build());
387 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
388 .detectLeakedSqlLiteObjects()
389 .detectLeakedClosableObjects()
390 .penaltyLog()
391 .penaltyDeath()
392 .build());
393 }
394
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800395 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400396
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400397 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400398 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700399 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700400 // Determine the dynamic grid properties
401 Point smallestSize = new Point();
402 Point largestSize = new Point();
403 Point realSize = new Point();
404 Display display = getWindowManager().getDefaultDisplay();
405 display.getCurrentSizeRange(smallestSize, largestSize);
406 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700407 DisplayMetrics dm = new DisplayMetrics();
408 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700409
Winson Chung5f8afe62013-08-12 16:19:28 -0700410 // Lazy-initialize the dynamic grid
411 DeviceProfile grid = app.initDynamicGrid(this,
412 Math.min(smallestSize.x, smallestSize.y),
413 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700414 realSize.x, realSize.y,
415 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700416
417 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400418 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700419 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800420 mModel = app.setLauncher(this);
421 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700422 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400423 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800424 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700426
Daniel Sandlerff02d492013-08-05 02:12:05 -0400427 mStats = new Stats(this);
428
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700429 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700430
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700431 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
432 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700433
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700434 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
435 // this also ensures that any synchronous binding below doesn't re-trigger another
436 // LauncherModel load.
437 mPaused = false;
438
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200440 android.os.Debug.startMethodTracing(
441 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 }
443
Adam Cohen53805212013-10-01 10:39:23 -0700444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100449 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800451 registerContentObservers();
452
Joe Onorato7c312c12009-08-13 21:36:53 -0700453 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700454
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 mSavedState = savedInstanceState;
456 restoreState(mSavedState);
457
458 if (PROFILE_STARTUP) {
459 android.os.Debug.stopMethodTracing();
460 }
461
462 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700463 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700464 // If the user leaves launcher, then we should just load items asynchronously when
465 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500466 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700467 } else {
468 // We only load the page synchronously if the user rotates (or triggers a
469 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800470 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800472 }
473
474 // For handling default keys
475 mDefaultKeySsb = new SpannableStringBuilder();
476 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800477
478 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
479 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800480
Adam Cohenf9426d52012-06-04 17:26:21 -0700481 updateGlobalIcons();
482
483 // On large interfaces, we want the screen to auto-rotate based on the current orientation
484 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700485
Adam Cohen432609a2014-03-13 17:03:22 -0700486 if (shouldShowIntroScreen()) {
487 showIntroScreen();
488 } else {
489 showFirstRunActivity();
490 }
491
Winson Chunge43a1e72014-01-15 10:33:02 -0800492 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
493 // on the device, then we always show the first run cling experience (or if there is no
494 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800495 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
496 if (mModel.canMigrateFromOldLauncherDb(this)) {
497 mLauncherClings.showMigrationCling();
498 } else {
499 mLauncherClings.showFirstRunCling();
500 }
Winson Chunga6945242014-01-08 14:04:34 -0800501 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800502 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800503 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700504 }
505
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700506 @Override
507 public void onLauncherProviderChange() { }
508
Winson Chung4a2afa32012-07-19 14:53:05 -0700509 protected void onUserLeaveHint() {
510 super.onUserLeaveHint();
511 sPausedFromUserAction = true;
512 }
513
Winson Chung98ca0f72013-07-29 12:58:51 -0700514 /** To be overriden by subclasses to hint to Launcher that we have custom content */
515 protected boolean hasCustomContentToLeft() {
516 return false;
517 }
518
Dave Hawkeya8881582013-09-17 15:55:33 -0600519 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500520 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600521 * {@link #addToCustomContentPage}. This will only be invoked if
522 * {@link #hasCustomContentToLeft()} is {@code true}.
523 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500524 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600525 }
526
527 /**
528 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
529 * ensure the custom content page is added or removed if necessary.
530 */
531 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600532 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600533 // Not bound yet, wait for bindScreens to be called.
534 return;
535 }
536
537 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
538 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500539 mWorkspace.createCustomContentContainer();
540 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600541 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
542 mWorkspace.removeCustomContentPage();
543 }
544 }
545
Adam Cohenf9426d52012-06-04 17:26:21 -0700546 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700547 boolean searchVisible = false;
548 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800549 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700550 int coi = getCurrentOrientationIndexForGlobalIcons();
551 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
552 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700553 if (!DISABLE_MARKET_BUTTON) {
554 updateAppMarketIcon();
555 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700556 searchVisible = updateGlobalSearchIcon();
557 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700558 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700559 if (sGlobalSearchIcon[coi] != null) {
560 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700561 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700562 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700563 if (sVoiceSearchIcon[coi] != null) {
564 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700565 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700566 }
Winson Chungd64a6662013-09-30 11:06:59 -0700567 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700568 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800569 }
Winson Chungadf0c182012-08-23 14:59:07 -0700570 if (mSearchDropTargetBar != null) {
571 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
572 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 }
Romain Guycbb89e42009-06-08 15:52:54 -0700574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 if (sLocaleConfiguration == null) {
577 new AsyncTask<Void, Void, LocaleConfiguration>() {
578 @Override
579 protected LocaleConfiguration doInBackground(Void... unused) {
580 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
581 readConfiguration(Launcher.this, localeConfiguration);
582 return localeConfiguration;
583 }
584
585 @Override
586 protected void onPostExecute(LocaleConfiguration result) {
587 sLocaleConfiguration = result;
588 checkForLocaleChange(); // recursive, but now with a locale configuration
589 }
590 }.execute();
591 return;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 final Configuration configuration = getResources().getConfiguration();
595
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700596 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 final String locale = configuration.locale.toString();
598
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 final int mcc = configuration.mcc;
601
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final int mnc = configuration.mnc;
604
Romain Guy84f296c2009-11-04 15:00:44 -0800605 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606
Romain Guy84f296c2009-11-04 15:00:44 -0800607 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 sLocaleConfiguration.locale = locale;
609 sLocaleConfiguration.mcc = mcc;
610 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700611
Joe Onorato0589f0f2010-02-08 13:44:00 -0800612 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613
614 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100615 new AsyncTask<Void, Void, Void>() {
616 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100618 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 }
Michael Jurka43467462013-11-14 12:03:58 +0100620 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700621 }
622 }
623
624 private static class LocaleConfiguration {
625 public String locale;
626 public int mcc = -1;
627 public int mnc = -1;
628 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700629
Romain Guy98d01652009-06-30 16:21:04 -0700630 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
631 DataInputStream in = null;
632 try {
633 in = new DataInputStream(context.openFileInput(PREFERENCES));
634 configuration.locale = in.readUTF();
635 configuration.mcc = in.readInt();
636 configuration.mnc = in.readInt();
637 } catch (FileNotFoundException e) {
638 // Ignore
639 } catch (IOException e) {
640 // Ignore
641 } finally {
642 if (in != null) {
643 try {
644 in.close();
645 } catch (IOException e) {
646 // Ignore
647 }
648 }
649 }
650 }
651
652 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
653 DataOutputStream out = null;
654 try {
655 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
656 out.writeUTF(configuration.locale);
657 out.writeInt(configuration.mcc);
658 out.writeInt(configuration.mnc);
659 out.flush();
660 } catch (FileNotFoundException e) {
661 // Ignore
662 } catch (IOException e) {
663 //noinspection ResultOfMethodCallIgnored
664 context.getFileStreamPath(PREFERENCES).delete();
665 } finally {
666 if (out != null) {
667 try {
668 out.close();
669 } catch (IOException e) {
670 // Ignore
671 }
672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
675
Anton Hanssona2f665f2013-09-26 12:18:32 +0100676 public Stats getStats() {
677 return mStats;
678 }
679
Bjorn Bringertc459e522013-06-07 19:36:01 +0100680 public LayoutInflater getInflater() {
681 return mInflater;
682 }
683
Winson Chung36a62fe2012-05-06 18:04:42 -0700684 boolean isDraggingEnabled() {
685 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
686 // that is subsequently removed from the workspace in startBinding().
687 return !mModel.isLoadingWorkspace();
688 }
689
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 static int getScreen() {
691 synchronized (sLock) {
692 return sScreen;
693 }
694 }
695
696 static void setScreen(int screen) {
697 synchronized (sLock) {
698 sScreen = screen;
699 }
700 }
701
Winson Chung557d6ed2011-07-08 15:34:52 -0700702 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000703 * Copied from View -- the View version of the method isn't called
704 * anywhere else in our process and only exists for API level 17+,
705 * so it's ok to keep our own version with no API requirement.
706 */
707 public static int generateViewId() {
708 for (;;) {
709 final int result = sNextGeneratedId.get();
710 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
711 int newValue = result + 1;
712 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
713 if (sNextGeneratedId.compareAndSet(result, newValue)) {
714 return result;
715 }
716 }
717 }
718
719 public int getViewIdForItem(ItemInfo info) {
720 // This cast is safe given the > 2B range for int.
721 int itemId = (int) info.id;
722 if (mItemIdToViewId.containsKey(itemId)) {
723 return mItemIdToViewId.get(itemId);
724 }
725 int viewId = generateViewId();
726 mItemIdToViewId.put(itemId, viewId);
727 return viewId;
728 }
729
730 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700731 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
732 * a configuration step, this allows the proper animations to run after other transitions.
733 */
734 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700735 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800736 switch (args.requestCode) {
737 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700738 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700739 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 break;
741 case REQUEST_PICK_SHORTCUT:
742 processShortcut(args.intent);
743 break;
744 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700745 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700746 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700747 result = true;
748 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800749 case REQUEST_CREATE_APPWIDGET:
750 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700751 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700752 result = true;
753 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800754 }
Michael Jurka27614d22012-04-02 06:40:22 -0700755 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
756 // if you turned the screen off and then back while in All Apps, Launcher would not
757 // return to the workspace. Clearing mAddInfo.container here fixes this issue
758 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700759 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800760 }
761
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700763 protected void onActivityResult(
764 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700765 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700766 setWaitingForResult(false);
Adam Cohen4637b5a2013-11-04 18:21:24 -0800767 int pendingAddWidgetId = mPendingAddWidgetId;
768 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700769
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 Runnable exitSpringLoaded = new Runnable() {
771 @Override
772 public void run() {
773 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
774 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
775 }
776 };
777
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700779 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700780 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
781 if (resultCode == RESULT_CANCELED) {
782 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700783 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
784 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700785 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700786 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
787 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 }
789 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200790 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
791 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
792 mWorkspace.exitOverviewMode(false);
793 }
794 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700795 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200796
Adam Cohened66b2b2012-01-23 17:28:51 -0800797 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
798 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700799
Adam Cohened66b2b2012-01-23 17:28:51 -0800800 // We have special handling for widgets
801 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800802 final int appWidgetId;
803 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
804 : -1;
805 if (widgetId < 0) {
806 appWidgetId = pendingAddWidgetId;
807 } else {
808 appWidgetId = widgetId;
809 }
810
Adam Cohenad4e15c2013-10-17 16:21:35 -0700811 final int result;
812 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800813 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700814 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
815 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700816 result = RESULT_CANCELED;
817 completeTwoStageWidgetDrop(result, appWidgetId);
818 onComplete = new Runnable() {
819 @Override
820 public void run() {
821 exitSpringLoadedDragModeDelayed(false, 0, null);
822 }
823 };
Winson Chung5aaab772012-04-27 15:24:02 -0700824 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700825 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700826 final CellLayout dropLayout =
827 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
828 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700829 onComplete = new Runnable() {
830 @Override
831 public void run() {
832 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700833 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700834 }
835 };
Winson Chung5aaab772012-04-27 15:24:02 -0700836 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700837 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
838 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800839 return;
840 }
841
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 // The pattern used here is that a user PICKs a specific application,
843 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700844
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
846 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700847 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800848 final PendingAddArguments args = new PendingAddArguments();
849 args.requestCode = requestCode;
850 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700851 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700852 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700853 args.cellX = mPendingAddInfo.cellX;
854 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800855 if (isWorkspaceLocked()) {
856 sPendingAddList.add(args);
857 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700858 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800859 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700860 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
861 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700862 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700863 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
864 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800867 }
868
869 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700870 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700871 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 Runnable onCompleteRunnable = null;
873 int animationType = 0;
874
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700875 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800876 if (resultCode == RESULT_OK) {
877 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
878 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700879 mPendingAddWidgetInfo);
880 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800881 onCompleteRunnable = new Runnable() {
882 @Override
883 public void run() {
884 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700885 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700886 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
887 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800888 }
889 };
890 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800891 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800892 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700894 if (mDragLayer.getAnimatedView() != null) {
895 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
896 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
897 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700898 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700899 // The animated view may be null in the case of a rotation during widget configuration
900 onCompleteRunnable.run();
901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 }
903
904 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700905 protected void onStop() {
906 super.onStop();
907 FirstFrameAnimatorHelper.setIsVisible(false);
908 }
909
910 @Override
911 protected void onStart() {
912 super.onStart();
913 FirstFrameAnimatorHelper.setIsVisible(true);
914 }
915
916 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200918 long startTime = 0;
919 if (DEBUG_RESUME_TIME) {
920 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400921 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200922 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800923 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700924
Winson Chung4a2afa32012-07-19 14:53:05 -0700925 // Restore the previous launcher state
926 if (mOnResumeState == State.WORKSPACE) {
927 showWorkspace(false);
928 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800929 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700930 }
931 mOnResumeState = State.NONE;
932
Craig Mautner360310b2012-10-26 15:13:08 -0700933 // Background was set to gradient in onPause(), restore to black if in all apps.
934 setWorkspaceBackground(mState == State.WORKSPACE);
935
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800936 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700937 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700938 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700939 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500940 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400941 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700942 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800943 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700944 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200945 // We might have postponed some bind calls until onResume (see waitUntilResume) --
946 // execute them here
947 long startTimeCallbacks = 0;
948 if (DEBUG_RESUME_TIME) {
949 startTimeCallbacks = System.currentTimeMillis();
950 }
951
952 if (mAppsCustomizeContent != null) {
953 mAppsCustomizeContent.setBulkBind(true);
954 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700955 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
956 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200957 }
958 if (mAppsCustomizeContent != null) {
959 mAppsCustomizeContent.setBulkBind(false);
960 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700961 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200962 if (DEBUG_RESUME_TIME) {
963 Log.d(TAG, "Time spent processing callbacks in onResume: " +
964 (System.currentTimeMillis() - startTimeCallbacks));
965 }
Michael Jurka447bf842013-05-15 14:52:15 +0200966 }
Michael Jurka54554252013-08-01 12:52:23 +0200967 if (mOnResumeCallbacks.size() > 0) {
968 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
969 mOnResumeCallbacks.get(i).run();
970 }
971 mOnResumeCallbacks.clear();
972 }
Winson Chunge4e50662012-01-23 14:45:13 -0800973
974 // Reset the pressed state of icons that were locked in the press state while activities
975 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800976 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800977 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800978 mWaitingForResume.setStayPressed(false);
979 }
Winson Chunge4e50662012-01-23 14:45:13 -0800980 if (mAppsCustomizeContent != null) {
981 // Resets the previous all apps icon press state
982 mAppsCustomizeContent.resetDrawableState();
983 }
Winson Chung82963d52013-10-09 11:20:57 -0700984
Adam Cohen06dff352012-06-01 17:17:08 -0700985 // It is possible that widgets can receive updates while launcher is not in the foreground.
986 // Consequently, the widgets will be inflated in the orientation of the foreground activity
987 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
988 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700989 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700990
Winson Chung780fe592013-09-26 14:48:44 -0700991 // Process any items that were added while Launcher was away.
992 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
993
Winson Chung5841efa2013-09-30 18:06:44 -0700994 // Update the voice search button proxy
995 updateVoiceButtonProxyVisible(false);
996
Adam Cohenf9426d52012-06-04 17:26:21 -0700997 // Again, as with the above scenario, it's possible that one or more of the global icons
998 // were updated in the wrong orientation.
999 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001000 if (DEBUG_RESUME_TIME) {
1001 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1002 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001003
1004 if (mWorkspace.getCustomContentCallbacks() != null) {
1005 // If we are resuming and the custom content is the current page, we call onShow().
1006 // It is also poassible that onShow will instead be called slightly after first layout
1007 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1008 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001009 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001010 }
1011 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001012 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001013 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001014 }
1015
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001017 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001018 // Ensure that items added to Launcher are queued until Launcher returns
1019 InstallShortcutReceiver.enableInstallQueue();
1020
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001021 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001022 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001023 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001024 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001025
1026 // We call onHide() aggressively. The custom content callbacks should be able to
1027 // debounce excess onHide calls.
1028 if (mWorkspace.getCustomContentCallbacks() != null) {
1029 mWorkspace.getCustomContentCallbacks().onHide();
1030 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001031 }
Romain Guycbb89e42009-06-08 15:52:54 -07001032
Adam Cohenbffe7452013-07-22 18:21:45 -07001033 QSBScroller mQsbScroller = new QSBScroller() {
1034 int scrollY = 0;
1035
1036 @Override
1037 public void setScrollY(int scroll) {
1038 scrollY = scroll;
1039
1040 if (mWorkspace.isOnOrMovingToCustomContent()) {
1041 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001042 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001043 }
1044 }
1045 };
1046
1047 public void resetQSBScroll() {
1048 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001049 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001050 }
1051
1052 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001053 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1054 // by a onResume or by scrolling otherwise.
1055 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001056
1057 // Custom content is completely hidden
1058 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001059
1060 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1061 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001062 }
1063
Jorim Jaggid017f882014-01-14 17:08:48 -08001064 protected boolean hasSettings() {
1065 return false;
1066 }
1067
Adam Cohenbffe7452013-07-22 18:21:45 -07001068 public interface QSBScroller {
1069 public void setScrollY(int scrollY);
1070 }
1071
Winson Chung98ca0f72013-07-29 12:58:51 -07001072 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001073 CustomContentCallbacks callbacks, String description) {
1074 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001075 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001076 }
1077
Adam Cohenedb40762013-07-18 16:45:45 -07001078 // The custom content needs to offset its content to account for the QSB
1079 public int getTopOffsetForCustomContent() {
1080 return mWorkspace.getPaddingTop();
1081 }
1082
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001083 @Override
1084 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001085 // Flag the loader to stop early before switching
1086 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001087 if (mAppsCustomizeContent != null) {
1088 mAppsCustomizeContent.surrender();
1089 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001090 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001091 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001092
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001093 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001094 @Override
1095 public void onWindowFocusChanged(boolean hasFocus) {
1096 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001097 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001098 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001099
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 private boolean acceptFilter() {
1101 final InputMethodManager inputManager = (InputMethodManager)
1102 getSystemService(Context.INPUT_METHOD_SERVICE);
1103 return !inputManager.isFullscreenMode();
1104 }
1105
1106 @Override
1107 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001108 final int uniChar = event.getUnicodeChar();
1109 final boolean handled = super.onKeyDown(keyCode, event);
1110 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1111 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1113 keyCode, event);
1114 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001115 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001116 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001117 // showSearchDialog()
1118 // If there are multiple keystrokes before the search dialog takes focus,
1119 // onSearchRequested() will be called for every keystroke,
1120 // but it is idempotent, so it's fine.
1121 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 }
1123 }
1124
Joe Onorato8a9625e2010-01-28 15:55:35 -08001125 // Eat the long press event so the keyboard doesn't come up.
1126 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1127 return true;
1128 }
1129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 return handled;
1131 }
1132
Karl Rosaen138a0412009-04-23 19:00:21 -07001133 private String getTypedText() {
1134 return mDefaultKeySsb.toString();
1135 }
1136
1137 private void clearTypedText() {
1138 mDefaultKeySsb.clear();
1139 mDefaultKeySsb.clearSpans();
1140 Selection.setSelection(mDefaultKeySsb, 0);
1141 }
1142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001144 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1145 * State
1146 */
1147 private static State intToState(int stateOrdinal) {
1148 State state = State.WORKSPACE;
1149 final State[] stateValues = State.values();
1150 for (int i = 0; i < stateValues.length; i++) {
1151 if (stateValues[i].ordinal() == stateOrdinal) {
1152 state = stateValues[i];
1153 break;
1154 }
1155 }
1156 return state;
1157 }
1158
1159 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001160 * Restores the previous state, if it exists.
1161 *
1162 * @param savedState The previous state.
1163 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001164 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 private void restoreState(Bundle savedState) {
1166 if (savedState == null) {
1167 return;
1168 }
1169
Michael Jurka883f55b2010-10-21 15:47:14 -07001170 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001171 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001172 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001173 }
1174
Adam Cohen21cd0022013-10-09 18:57:02 -07001175 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1176 PagedView.INVALID_RESTORE_PAGE);
1177 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001178 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001179 }
1180
Winson Chung3d503fb2011-07-13 17:25:49 -07001181 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001182 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001183
Winson Chung3d503fb2011-07-13 17:25:49 -07001184 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1185 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001186 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001187 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1188 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001189 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1190 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1191 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001192 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001193 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 mRestoring = true;
1195 }
1196
1197 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1198 if (renameFolder) {
1199 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001200 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 mRestoring = true;
1202 }
Winson Chunga12a2502010-12-20 14:41:35 -08001203
Winson Chung785d2eb2011-04-14 16:08:02 -07001204 // Restore the AppsCustomize tab
1205 if (mAppsCustomizeTabHost != null) {
1206 String curTab = savedState.getString("apps_customize_currentTab");
1207 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001208 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001209 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001210 mAppsCustomizeContent.loadAssociatedPages(
1211 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001212 }
1213
Winson Chung5afbf7b2011-07-25 11:53:08 -07001214 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1215 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001216 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001217 mItemIdToViewId = (HashMap<Integer, Integer>)
1218 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 }
1220
1221 /**
1222 * Finds all the views we need and configure them properly.
1223 */
1224 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001225 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001226
Craig Mautner360310b2012-10-26 15:13:08 -07001227 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001228 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1229 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001230 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001231 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001232
John Spurlock77e1f472013-09-11 10:09:51 -04001233 mLauncherView.setSystemUiVisibility(
1234 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001235 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236
Winson Chung4c98d922011-05-31 16:50:48 -07001237 // Setup the drag layer
1238 mDragLayer.setup(this, dragController);
1239
Winson Chung3d503fb2011-07-13 17:25:49 -07001240 // Setup the hotseat
1241 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1242 if (mHotseat != null) {
1243 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001244 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001245 }
1246
Jorim Jaggid017f882014-01-14 17:08:48 -08001247 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001248 View widgetButton = findViewById(R.id.widget_button);
1249 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001250 @Override
1251 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001252 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001253 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001254 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001255 }
1256 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001257 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1258
1259 View wallpaperButton = findViewById(R.id.wallpaper_button);
1260 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001261 @Override
1262 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001263 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001264 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001265 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001266 }
1267 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001268 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1269
1270 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001271 if (hasSettings()) {
1272 settingsButton.setOnClickListener(new OnClickListener() {
1273 @Override
1274 public void onClick(View arg0) {
1275 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001276 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001277 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001278 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001279 });
1280 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1281 } else {
1282 settingsButton.setVisibility(View.GONE);
1283 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1284 lp.gravity = Gravity.END | Gravity.TOP;
1285 widgetButton.requestLayout();
1286 }
1287
Adam Cohendbdff6b2013-09-18 19:09:15 -07001288 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001289
Winson Chung4c98d922011-05-31 16:50:48 -07001290 // Setup the workspace
1291 mWorkspace.setHapticFeedbackEnabled(false);
1292 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001293 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001294 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001295
Winson Chungf0ea4d32011-06-06 14:27:16 -07001296 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001297 mSearchDropTargetBar = (SearchDropTargetBar)
1298 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001299
Winson Chungf0ea4d32011-06-06 14:27:16 -07001300 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001301 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001302 mAppsCustomizeContent = (AppsCustomizePagedView)
1303 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1304 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001305
Winson Chung3d503fb2011-07-13 17:25:49 -07001306 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001307 dragController.setDragScoller(mWorkspace);
1308 dragController.setScrollView(mDragLayer);
1309 dragController.setMoveTarget(mWorkspace);
1310 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001311 if (mSearchDropTargetBar != null) {
1312 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001313 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001314
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001315 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001316 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001317 mWeightWatcher = new WeightWatcher(this);
1318 mWeightWatcher.setAlpha(0.5f);
1319 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001320 new FrameLayout.LayoutParams(
1321 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001322 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001323 Gravity.BOTTOM)
1324 );
Adam Cohen39a06042013-07-19 14:30:12 -07001325
1326 boolean show = shouldShowWeightWatcher();
1327 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001328 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 }
1330
1331 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001332 * Sets the all apps button. This method is called from {@link Hotseat}.
1333 */
1334 public void setAllAppsButton(View allAppsButton) {
1335 mAllAppsButton = allAppsButton;
1336 }
1337
1338 public View getAllAppsButton() {
1339 return mAllAppsButton;
1340 }
1341
1342 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 * Creates a view representing a shortcut.
1344 *
1345 * @param info The data structure describing the shortcut.
1346 *
1347 * @return A View inflated from R.layout.application.
1348 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001349 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001351 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352 }
1353
1354 /**
1355 * Creates a view representing a shortcut inflated from the specified resource.
1356 *
1357 * @param layoutResId The id of the XML layout used to create the shortcut.
1358 * @param parent The group the shortcut belongs to.
1359 * @param info The data structure describing the shortcut.
1360 *
1361 * @return A View inflated from layoutResId.
1362 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001363 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001364 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1365 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 return favorite;
1368 }
1369
1370 /**
1371 * Add an application shortcut to the workspace.
1372 *
1373 * @param data The intent describing the application.
1374 * @param cellInfo The position on screen where to create the shortcut.
1375 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001376 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001377 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001378 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001379
Adam Cohenfbba09b2011-07-18 21:43:05 -07001380 // First we check if we already know the exact location where we want to add this item.
1381 if (cellX >= 0 && cellY >= 0) {
1382 cellXY[0] = cellX;
1383 cellXY[1] = cellY;
1384 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001385 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001386 return;
1387 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001389 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001390
Romain Guy73b979d2009-06-09 12:57:21 -07001391 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001392 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001394 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001395 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001396 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001397 } else {
1398 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 }
1400 }
Romain Guycbb89e42009-06-08 15:52:54 -07001401
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402 /**
1403 * Add a shortcut to the workspace.
1404 *
1405 * @param data The intent describing the shortcut.
1406 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001408 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001409 int cellY) {
1410 int[] cellXY = mTmpAddItemCellCoordinates;
1411 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001412 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001413
Michael Jurkad3ef3062010-11-23 16:23:58 -08001414 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001415
Adam Cohen558baaf2011-08-15 15:22:57 -07001416 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001417 if (info == null) {
1418 return;
1419 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001420 final View view = createShortcut(info);
1421
Adam Cohenfbba09b2011-07-18 21:43:05 -07001422 // First we check if we already know the exact location where we want to add this item.
1423 if (cellX >= 0 && cellY >= 0) {
1424 cellXY[0] = cellX;
1425 cellXY[1] = cellY;
1426 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001427
1428 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001429 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001430 true, null,null)) {
1431 return;
1432 }
1433 DragObject dragObject = new DragObject();
1434 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001435 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1436 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001437 return;
1438 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001439 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001440 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001441 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001442 foundCellSpan = (result != null);
1443 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001444 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001445 }
1446
1447 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001448 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001449 return;
1450 }
1451
Adam Cohendcd297f2013-06-18 13:13:40 -07001452 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
1454 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001455 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001456 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 }
1458 }
1459
Adam Cohen2f093b62012-04-30 18:59:53 -07001460 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1461 int minHeight) {
1462 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001463 // We want to account for the extra amount of padding that we are adding to the widget
1464 // to ensure that it gets the full amount of space that it has requested
1465 int requiredWidth = minWidth + padding.left + padding.right;
1466 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001467 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001468 }
1469
Adam Cohen2f093b62012-04-30 18:59:53 -07001470 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1471 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001472 }
1473
Adam Cohen2f093b62012-04-30 18:59:53 -07001474 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1475 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001476 }
1477
Adam Cohen2f093b62012-04-30 18:59:53 -07001478 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1479 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001480 }
1481
Adam Cohen2f093b62012-04-30 18:59:53 -07001482 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1483 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001484 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001485 }
1486
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001487 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001488 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001490 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001491 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001493 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001494 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1495 if (appWidgetInfo == null) {
1496 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1497 }
Romain Guycbb89e42009-06-08 15:52:54 -07001498
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001499 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001500 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001501
Adam Cohen2f093b62012-04-30 18:59:53 -07001502 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1503 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001504
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001506 // We have saved the position to which the widget was dragged-- this really only matters
1507 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001508 int[] cellXY = mTmpAddItemCellCoordinates;
1509 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001510 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001511 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001512 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1513 cellXY[0] = mPendingAddInfo.cellX;
1514 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001515 spanXY[0] = mPendingAddInfo.spanX;
1516 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001517 foundCellSpan = true;
1518 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001519 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001520 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001521 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1522 spanXY[1], cellXY, finalSpan);
1523 spanXY[0] = finalSpan[0];
1524 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001525 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001526 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001527 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001528 }
1529
Michael Jurka0280c3b2010-09-17 15:00:07 -07001530 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001531 if (appWidgetId != -1) {
1532 // Deleting an app widget ID is a void call but writes to disk before returning
1533 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001534 new AsyncTask<Void, Void, Void>() {
1535 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001536 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001537 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001538 }
Michael Jurka43467462013-11-14 12:03:58 +01001539 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001540 }
Winson Chung93eef082012-03-23 15:59:27 -07001541 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001542 return;
1543 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001545 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001546 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1547 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001548 launcherInfo.spanX = spanXY[0];
1549 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001550 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1551 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001552
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001554 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555
1556 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001557 if (hostView == null) {
1558 // Perform actual inflation because we're live
1559 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1560 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1561 } else {
1562 // The AppWidgetHostView has already been inflated and instantiated
1563 launcherInfo.hostView = hostView;
1564 }
Romain Guycbb89e42009-06-08 15:52:54 -07001565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001567 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001568 launcherInfo.notifyWidgetSizeChanged(this);
1569
Adam Cohendcd297f2013-06-18 13:13:40 -07001570 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001572
1573 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001575 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 }
Romain Guycbb89e42009-06-08 15:52:54 -07001577
Adam Cohended9f8d2010-11-03 13:25:16 -07001578 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1579 @Override
1580 public void onReceive(Context context, Intent intent) {
1581 final String action = intent.getAction();
1582 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1583 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001584 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001585 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001586
Winson Chungc100e8e2011-08-09 16:02:43 -07001587 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001588 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001589 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001590 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001591 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001592 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1593 mUserPresent = true;
1594 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001595 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1596 mModel.resetLoadedState(false, true);
1597 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1598 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1599 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1600 mModel.resetLoadedState(false, true);
1601 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1602 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1603 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001604 }
1605 }
1606 };
1607
1608 @Override
1609 public void onAttachedToWindow() {
1610 super.onAttachedToWindow();
1611
1612 // Listen for broadcasts related to user-presence
1613 final IntentFilter filter = new IntentFilter();
1614 filter.addAction(Intent.ACTION_SCREEN_OFF);
1615 filter.addAction(Intent.ACTION_USER_PRESENT);
Dan Sandlerd5024042014-01-09 15:01:33 -05001616 if (ENABLE_DEBUG_INTENTS) {
1617 filter.addAction(DebugIntents.DELETE_DATABASE);
1618 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1619 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001620 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001621 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001622 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001623 mVisible = true;
1624 }
1625
1626 @Override
1627 public void onDetachedFromWindow() {
1628 super.onDetachedFromWindow();
1629 mVisible = false;
1630
Adam Cohend113e0c2010-11-11 10:48:05 -08001631 if (mAttached) {
1632 unregisterReceiver(mReceiver);
1633 mAttached = false;
1634 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001635 updateRunning();
1636 }
1637
1638 public void onWindowVisibilityChanged(int visibility) {
1639 mVisible = visibility == View.VISIBLE;
1640 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001641 // The following code used to be in onResume, but it turns out onResume is called when
1642 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1643 // is a more appropriate event to handle
1644 if (mVisible) {
1645 mAppsCustomizeTabHost.onWindowVisible();
1646 if (!mWorkspaceLoading) {
1647 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001648 // We want to let Launcher draw itself at least once before we force it to build
1649 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001650 // apps is nice and speedy.
1651 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001652 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001653 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001654 if (mStarted) return;
1655 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001656 // We delay the layer building a bit in order to give
1657 // other message processing a time to run. In particular
1658 // this avoids a delay in hiding the IME if it was
1659 // currently shown, because doing that may involve
1660 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001661 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001662 final ViewTreeObserver.OnDrawListener listener = this;
1663 mWorkspace.post(new Runnable() {
1664 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001665 if (mWorkspace != null &&
1666 mWorkspace.getViewTreeObserver() != null) {
1667 mWorkspace.getViewTreeObserver().
1668 removeOnDrawListener(listener);
1669 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001670 }
1671 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001672 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001673 }
1674 });
1675 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001676 // When Launcher comes back to foreground, a different Activity might be responsible for
1677 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001678 if (!DISABLE_MARKET_BUTTON) {
1679 updateAppMarketIcon();
1680 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001681 clearTypedText();
1682 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001683 }
1684
1685 private void sendAdvanceMessage(long delay) {
1686 mHandler.removeMessages(ADVANCE_MSG);
1687 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1688 mHandler.sendMessageDelayed(msg, delay);
1689 mAutoAdvanceSentTime = System.currentTimeMillis();
1690 }
1691
1692 private void updateRunning() {
1693 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1694 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1695 mAutoAdvanceRunning = autoAdvanceRunning;
1696 if (autoAdvanceRunning) {
1697 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1698 sendAdvanceMessage(delay);
1699 } else {
1700 if (!mWidgetsToAdvance.isEmpty()) {
1701 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1702 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1703 }
1704 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001705 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001706 }
1707 }
1708 }
1709
1710 private final Handler mHandler = new Handler() {
1711 @Override
1712 public void handleMessage(Message msg) {
1713 if (msg.what == ADVANCE_MSG) {
1714 int i = 0;
1715 for (View key: mWidgetsToAdvance.keySet()) {
1716 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1717 final int delay = mAdvanceStagger * i;
1718 if (v instanceof Advanceable) {
1719 postDelayed(new Runnable() {
1720 public void run() {
1721 ((Advanceable) v).advance();
1722 }
1723 }, delay);
1724 }
1725 i++;
1726 }
1727 sendAdvanceMessage(mAdvanceInterval);
1728 }
1729 }
1730 };
1731
1732 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001733 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001734 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1735 if (v instanceof Advanceable) {
1736 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001737 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001738 updateRunning();
1739 }
1740 }
1741
1742 void removeWidgetToAutoAdvance(View hostView) {
1743 if (mWidgetsToAdvance.containsKey(hostView)) {
1744 mWidgetsToAdvance.remove(hostView);
1745 updateRunning();
1746 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001747 }
1748
Joe Onorato9c1289c2009-08-17 11:03:03 -04001749 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001750 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001751 launcherInfo.hostView = null;
1752 }
1753
Winson Chung93eef082012-03-23 15:59:27 -07001754 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1755 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1756 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001757 }
1758
Winson Chunga6945242014-01-08 14:04:34 -08001759 public DragLayer getDragLayer() {
1760 return mDragLayer;
1761 }
1762
1763 public Workspace getWorkspace() {
1764 return mWorkspace;
1765 }
1766
1767 public Hotseat getHotseat() {
1768 return mHotseat;
1769 }
1770
Jorim Jaggid017f882014-01-14 17:08:48 -08001771 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001772 return mOverviewPanel;
1773 }
1774
1775 public SearchDropTargetBar getSearchBar() {
1776 return mSearchDropTargetBar;
1777 }
1778
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001779 public LauncherAppWidgetHost getAppWidgetHost() {
1780 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001781 }
Romain Guycbb89e42009-06-08 15:52:54 -07001782
Winson Chunga9abd0e2010-10-27 17:18:37 -07001783 public LauncherModel getModel() {
1784 return mModel;
1785 }
1786
Winson Chunga6945242014-01-08 14:04:34 -08001787 public LauncherClings getLauncherClings() {
1788 return mLauncherClings;
1789 }
1790
1791 protected SharedPreferences getSharedPrefs() {
1792 return mSharedPrefs;
1793 }
1794
Bjorn Bringertc459e522013-06-07 19:36:01 +01001795 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001796 getWindow().closeAllPanels();
1797
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001798 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001799 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001800 }
1801
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 @Override
1803 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001804 long startTime = 0;
1805 if (DEBUG_RESUME_TIME) {
1806 startTime = System.currentTimeMillis();
1807 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 super.onNewIntent(intent);
1809
1810 // Close the menu
1811 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001812 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001813 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001814
Adam Cohened307df2013-10-02 09:37:31 -07001815 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1816 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1817 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001818
Adam Cohen6fecd412013-10-02 17:41:50 -07001819 if (mWorkspace == null) {
1820 // Can be cases where mWorkspace is null, this prevents a NPE
1821 return;
1822 }
1823 Folder openFolder = mWorkspace.getOpenFolder();
1824 // In all these cases, only animate if we're already on home
1825 mWorkspace.exitWidgetResizeMode();
1826 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001827 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001828 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001829 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001830
Adam Cohen6fecd412013-10-02 17:41:50 -07001831 closeFolder();
1832 exitSpringLoadedDragMode();
1833
1834 // If we are already on home, then just animate back to the workspace,
1835 // otherwise, just wait until onResume to set the state back to Workspace
1836 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001837 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001838 } else {
1839 mOnResumeState = State.WORKSPACE;
1840 }
1841
1842 final View v = getWindow().peekDecorView();
1843 if (v != null && v.getWindowToken() != null) {
1844 InputMethodManager imm = (InputMethodManager)getSystemService(
1845 INPUT_METHOD_SERVICE);
1846 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1847 }
1848
1849 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001850 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001851 mAppsCustomizeTabHost.reset();
1852 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001853
1854 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 }
Adam Cohened307df2013-10-02 09:37:31 -07001856
Michael Jurka447bf842013-05-15 14:52:15 +02001857 if (DEBUG_RESUME_TIME) {
1858 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1859 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001860 }
1861
Adam Coppa120b8e2013-11-12 16:26:04 +00001862 /**
1863 * Override point for subclasses to prevent movement to the default screen when the home
1864 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1865 */
1866 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1867 return true;
1868 }
1869
1870 /**
1871 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1872 */
1873 protected void onHomeIntent() {
1874 // Do nothing
1875 }
1876
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001878 public void onRestoreInstanceState(Bundle state) {
1879 super.onRestoreInstanceState(state);
1880 for (int page: mSynchronouslyBoundPages) {
1881 mWorkspace.restoreInstanceStateForChild(page);
1882 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 }
1884
1885 @Override
1886 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001887 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001888 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1889 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001890 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001891 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892
Michael Jurka883f55b2010-10-21 15:47:14 -07001893 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001894 // We close any open folder since it will not be re-opened, and we need to make sure
1895 // this state is reflected.
1896 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897
Adam Cohendcd297f2013-06-18 13:13:40 -07001898 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001899 mWaitingForResult) {
1900 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001901 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1903 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001904 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1905 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1906 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001907 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 }
1909
1910 if (mFolderInfo != null && mWaitingForResult) {
1911 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1912 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1913 }
Michael Jurka946ad472010-07-09 18:05:18 -07001914
Winson Chung785d2eb2011-04-14 16:08:02 -07001915 // Save the current AppsCustomize tab
1916 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001917 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1918 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001919 if (currentTabTag != null) {
1920 outState.putString("apps_customize_currentTab", currentTabTag);
1921 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001922 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1923 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001924 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001925 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 }
1927
1928 @Override
1929 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001931
Winson Chunge7a03942011-08-05 15:05:12 -07001932 // Remove all pending runnables
1933 mHandler.removeMessages(ADVANCE_MSG);
1934 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001935 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001936
Winson Chungcd2b0142011-06-08 16:02:26 -07001937 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001938 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001939 mModel.stopLoader();
1940 app.setLauncher(null);
1941
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001943 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001945 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001947 mAppWidgetHost = null;
1948
1949 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950
1951 TextKeyListener.getInstance().release();
1952
Winson Chung81b52252012-08-27 15:34:29 -07001953 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1954 // to prevent leaking Launcher activities on orientation change.
1955 if (mModel != null) {
1956 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1957 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001958
1959 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001960 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001961
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001962 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001963 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001964 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001965 mWorkspace = null;
1966 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001967
Michael Jurka2ecf9952012-06-18 12:52:28 -07001968 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 }
1970
Adam Cohena9cf38f2011-05-02 15:36:58 -07001971 public DragController getDragController() {
1972 return mDragController;
1973 }
1974
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 @Override
1976 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001977 if (requestCode >= 0) {
1978 setWaitingForResult(true);
1979 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 super.startActivityForResult(intent, requestCode);
1981 }
1982
Winson Chung70d72102011-08-12 11:24:35 -07001983 /**
1984 * Indicates that we want global search for this activity by setting the globalSearch
1985 * argument for {@link #startSearch} to true.
1986 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001988 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001990
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001991 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001992
Karl Rosaen138a0412009-04-23 19:00:21 -07001993 if (initialQuery == null) {
1994 // Use any text typed in the launcher as the initial query
1995 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001996 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 if (appSearchData == null) {
1998 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001999 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002000 }
Winson Chungadf0c182012-08-23 14:59:07 -07002001 Rect sourceBounds = new Rect();
2002 if (mSearchDropTargetBar != null) {
2003 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2004 }
Romain Guycbb89e42009-06-08 15:52:54 -07002005
Bjorn Bringertc459e522013-06-07 19:36:01 +01002006 startSearch(initialQuery, selectInitialQuery,
2007 appSearchData, sourceBounds);
2008 }
2009
2010 public void startSearch(String initialQuery,
2011 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002012 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002013 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002014 }
2015
2016 /**
2017 * Starts the global search activity. This code is a copied from SearchManager
2018 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002019 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002020 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002021 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002022 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2023 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2024 if (globalSearchActivity == null) {
2025 Log.w(TAG, "No global search activity found.");
2026 return;
2027 }
2028 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2029 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2030 intent.setComponent(globalSearchActivity);
2031 // Make sure that we have a Bundle to put source in
2032 if (appSearchData == null) {
2033 appSearchData = new Bundle();
2034 } else {
2035 appSearchData = new Bundle(appSearchData);
2036 }
2037 // Set source to package name of app that starts global search, if not set already.
2038 if (!appSearchData.containsKey("source")) {
2039 appSearchData.putString("source", getPackageName());
2040 }
2041 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2042 if (!TextUtils.isEmpty(initialQuery)) {
2043 intent.putExtra(SearchManager.QUERY, initialQuery);
2044 }
2045 if (selectInitialQuery) {
2046 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2047 }
2048 intent.setSourceBounds(sourceBounds);
2049 try {
2050 startActivity(intent);
2051 } catch (ActivityNotFoundException ex) {
2052 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2053 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 }
2055
Yura4f93ec62014-02-04 14:15:21 +00002056 public boolean isOnCustomContent() {
2057 return mWorkspace.isOnOrMovingToCustomContent();
2058 }
2059
Winson Chung70d72102011-08-12 11:24:35 -07002060 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002061 public boolean onPrepareOptionsMenu(Menu menu) {
2062 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002063 if (!isOnCustomContent()) {
2064 // Close any open folders
2065 closeFolder();
2066 // Stop resizing any widgets
2067 mWorkspace.exitWidgetResizeMode();
2068 if (!mWorkspace.isInOverviewMode()) {
2069 // Show the overview mode
2070 showOverviewMode(true);
2071 } else {
2072 showWorkspace(true);
2073 }
Winson Chunge0298742014-01-17 12:03:00 -08002074 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002075 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002076 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002078 @Override
2079 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002080 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002081 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002082 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002083 }
2084
Joe Onorato9c1289c2009-08-17 11:03:03 -04002085 public boolean isWorkspaceLocked() {
2086 return mWorkspaceLoading || mWaitingForResult;
2087 }
2088
Adam Cohen517a7f52014-03-01 12:12:59 -08002089 public boolean isWorkspaceLoading() {
2090 return mWorkspaceLoading;
2091 }
2092
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002093 private void setWorkspaceLoading(boolean value) {
2094 boolean isLocked = isWorkspaceLocked();
2095 mWorkspaceLoading = value;
2096 if (isLocked != isWorkspaceLocked()) {
2097 onWorkspaceLockedChanged();
2098 }
2099 }
2100
2101 private void setWaitingForResult(boolean value) {
2102 boolean isLocked = isWorkspaceLocked();
2103 mWaitingForResult = value;
2104 if (isLocked != isWorkspaceLocked()) {
2105 onWorkspaceLockedChanged();
2106 }
2107 }
2108
2109 protected void onWorkspaceLockedChanged() { }
2110
Michael Jurka0280c3b2010-09-17 15:00:07 -07002111 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002112 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002113 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002114 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2115 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002116 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002117 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002118 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002119
Adam Cohenad4e15c2013-10-17 16:21:35 -07002120 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2121 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2122 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2123 }
2124
2125 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2126 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2127 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002128 if (appWidgetInfo.configure != null) {
2129 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002130 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002131
Bjorn Bringert7984c942009-12-09 15:38:25 +00002132 // Launch over to configure widget, if needed
2133 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002134 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002135 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002136 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002138 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002139 Runnable onComplete = new Runnable() {
2140 @Override
2141 public void run() {
2142 // Exit spring loaded mode if necessary after adding the widget
2143 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2144 null);
2145 }
2146 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002147 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002148 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002149 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 }
2151 }
Romain Guycbb89e42009-06-08 15:52:54 -07002152
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002153 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002154 // Close any folders that may be open.
2155 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002156 mWorkspace.moveToCustomContentScreen(animate);
2157 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002158 /**
2159 * Process a shortcut drop.
2160 *
2161 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002162 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002163 * @param cell The cell it should be added to, optional
2164 * @param position The location on the screen where it was dropped, optional
2165 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002166 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002167 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002168 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002169 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002170 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002171 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002172
2173 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002174 mPendingAddInfo.cellX = cell[0];
2175 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002176 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002177
2178 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2179 createShortcutIntent.setComponent(componentName);
2180 processShortcut(createShortcutIntent);
2181 }
2182
Adam Cohenfbba09b2011-07-18 21:43:05 -07002183 /**
2184 * Process a widget drop.
2185 *
2186 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002187 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002188 * @param cell The cell it should be added to, optional
2189 * @param position The location on the screen where it was dropped, optional
2190 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002191 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002192 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002193 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002194 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002195 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002196 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002197 mPendingAddInfo.minSpanX = info.minSpanX;
2198 mPendingAddInfo.minSpanY = info.minSpanY;
2199
Adam Cohenfbba09b2011-07-18 21:43:05 -07002200 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002201 mPendingAddInfo.cellX = cell[0];
2202 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002203 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002204 if (span != null) {
2205 mPendingAddInfo.spanX = span[0];
2206 mPendingAddInfo.spanY = span[1];
2207 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002208
Adam Cohened66b2b2012-01-23 17:28:51 -08002209 AppWidgetHostView hostView = info.boundWidget;
2210 int appWidgetId;
2211 if (hostView != null) {
2212 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002213 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002214 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002215 // In this case, we either need to start an activity to get permission to bind
2216 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002217 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002218 Bundle options = info.bindOptions;
2219
2220 boolean success = false;
2221 if (options != null) {
2222 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2223 info.componentName, options);
2224 } else {
2225 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2226 info.componentName);
2227 }
2228 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002229 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002230 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002231 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002232 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2233 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2234 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002235 // TODO: we need to make sure that this accounts for the options bundle.
2236 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002237 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2238 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002239 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002240 }
2241
Joe Onoratodeb98af2010-02-19 14:59:39 -08002242 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002243 // Handle case where user selected "Applications"
2244 String applicationName = getResources().getString(R.string.group_applications);
2245 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002246
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002247 if (applicationName != null && applicationName.equals(shortcutName)) {
2248 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2249 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002250
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002251 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2252 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002253 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002254 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002255 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002256 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002257 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002258 }
2259
Winson Chung24ab2f12010-09-16 14:10:47 -07002260 void processWallpaper(Intent intent) {
2261 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2262 }
2263
Adam Cohendcd297f2013-06-18 13:13:40 -07002264 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002265 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002266 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002267 folderInfo.title = getText(R.string.folder_name);
2268
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002269 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002270 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002271 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002272 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002273
2274 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002275 FolderIcon newFolder =
2276 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002277 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002278 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002279 // Force measure the new folder icon
2280 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2281 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002282 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002283 }
Romain Guycbb89e42009-06-08 15:52:54 -07002284
Joe Onorato9c1289c2009-08-17 11:03:03 -04002285 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002286 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002287 }
2288
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002289 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002290 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002291 }
2292
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002293 /**
2294 * Registers various content observers. The current implementation registers
2295 * only a favorites observer to keep track of the favorites applications.
2296 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002297 private void registerContentObservers() {
2298 ContentResolver resolver = getContentResolver();
2299 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2300 true, mWidgetObserver);
2301 }
2302
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002303 @Override
2304 public boolean dispatchKeyEvent(KeyEvent event) {
2305 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2306 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002307 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002308 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002309 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002310 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002311 dumpState();
2312 return true;
2313 }
2314 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002315 }
2316 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2317 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002318 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 return true;
2320 }
2321 }
2322
2323 return super.dispatchKeyEvent(event);
2324 }
2325
Joe Onorato88ec0992009-11-19 13:16:06 -08002326 @Override
2327 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002328 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002329 if (mAppsCustomizeContent.getContentType() ==
2330 AppsCustomizePagedView.ContentType.Applications) {
2331 showWorkspace(true);
2332 } else {
2333 showOverviewMode(true);
2334 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002335 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002336 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002337 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002338 Folder openFolder = mWorkspace.getOpenFolder();
2339 if (openFolder.isEditingName()) {
2340 openFolder.dismissEditingName();
2341 } else {
2342 closeFolder();
2343 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002344 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002345 mWorkspace.exitWidgetResizeMode();
2346
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002347 // Back button is a no-op here, but give at least some feedback for the button press
2348 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002349 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002350 }
2351
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002352 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002353 * Re-listen when widgets are reset.
2354 */
2355 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002356 if (mAppWidgetHost != null) {
2357 mAppWidgetHost.startListening();
2358 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002359 }
2360
2361 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362 * Launches the intent referred by the clicked shortcut.
2363 *
2364 * @param v The view representing the clicked shortcut.
2365 */
2366 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002367 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2368 // view has detached (it's possible for this to happen if the view is removed mid touch).
2369 if (v.getWindowToken() == null) {
2370 return;
2371 }
2372
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002373 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002374 return;
2375 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002376
Adam Cohen1697b792013-09-17 19:08:21 -07002377 if (v instanceof Workspace) {
2378 if (mWorkspace.isInOverviewMode()) {
2379 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002380 }
2381 return;
2382 }
2383
2384 if (v instanceof CellLayout) {
2385 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002386 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002387 }
2388 }
2389
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002391 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002392 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002393 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002394 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002395 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002396 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002397 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002398 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002399 }
2400 }
2401
Michael Jurka0e260592010-06-30 17:07:39 -07002402 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002403 return false;
2404 }
2405
Michael Jurkaaf442092010-06-10 17:01:57 -07002406 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002407 * Event handler for the search button
2408 *
2409 * @param v The view that was clicked.
2410 */
2411 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002412 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2413
Amith Yamasania135ba82011-08-09 17:42:01 -07002414 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002415 }
2416
2417 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002418 * Event handler for the voice button
2419 *
2420 * @param v The view that was clicked.
2421 */
2422 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002423 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002424
Bjorn Bringertc459e522013-06-07 19:36:01 +01002425 startVoice();
2426 }
2427
2428 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002429 try {
2430 final SearchManager searchManager =
2431 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2432 ComponentName activityName = searchManager.getGlobalSearchActivity();
2433 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002434 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002435 if (activityName != null) {
2436 intent.setPackage(activityName.getPackageName());
2437 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002438 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002439 } catch (ActivityNotFoundException e) {
2440 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002441 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002442 startActivitySafely(null, intent, "onClickVoiceButton");
2443 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002444 }
2445
2446 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002447 * Event handler for the "grid" button that appears on the home screen, which
2448 * enters all apps mode.
2449 *
2450 * @param v The view that was clicked.
2451 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002452 protected void onClickAllAppsButton(View v) {
2453 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2454 if (isAllAppsVisible()) {
2455 showWorkspace(true);
2456 } else {
2457 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2458 }
2459 }
2460
2461 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002462 * Event handler for a paged view icon click.
2463 * @param v The view that was clicked.
2464 * @param appInfo The {link AppInfo} of the view.
2465 */
2466 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2467 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2468 startActivitySafely(v, appInfo.intent, appInfo);
2469 getStats().recordLaunch(appInfo.intent);
2470 }
2471
2472 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002473 * Event handler for an app shortcut click.
2474 *
2475 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2476 */
2477 protected void onClickAppShortcut(View v) {
2478 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2479 Object tag = v.getTag();
2480 if (!(tag instanceof ShortcutInfo)) {
2481 throw new IllegalArgumentException("Input must be a Shortcut");
2482 }
2483
2484 // Open shortcut
2485 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2486 final Intent intent = shortcut.intent;
2487
2488 // Check for special shortcuts
2489 if (intent.getComponent() != null) {
2490 final String shortcutClass = intent.getComponent().getClassName();
2491
2492 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2493 MemoryDumpActivity.startDump(this);
2494 return;
2495 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2496 toggleShowWeightWatcher();
2497 return;
2498 }
2499 }
2500
2501 // Start activities
2502 int[] pos = new int[2];
2503 v.getLocationOnScreen(pos);
2504 intent.setSourceBounds(new Rect(pos[0], pos[1],
2505 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2506
2507 boolean success = startActivitySafely(v, intent, tag);
2508
2509 mStats.recordLaunch(intent, shortcut);
2510
2511 if (success && v instanceof BubbleTextView) {
2512 mWaitingForResume = (BubbleTextView) v;
2513 mWaitingForResume.setStayPressed(true);
2514 }
2515 }
2516
2517 /**
2518 * Event handler for a folder icon click.
2519 *
2520 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2521 */
2522 protected void onClickFolderIcon(View v) {
2523 if (LOGD) Log.d(TAG, "onClickFolder");
2524 if (!(v instanceof FolderIcon)){
2525 throw new IllegalArgumentException("Input must be a FolderIcon");
2526 }
2527
2528 FolderIcon folderIcon = (FolderIcon) v;
2529 final FolderInfo info = folderIcon.getFolderInfo();
2530 Folder openFolder = mWorkspace.getFolderForTag(info);
2531
2532 // If the folder info reports that the associated folder is open, then verify that
2533 // it is actually opened. There have been a few instances where this gets out of sync.
2534 if (info.opened && openFolder == null) {
2535 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2536 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2537 info.opened = false;
2538 }
2539
2540 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2541 // Close any open folder
2542 closeFolder();
2543 // Open the requested folder
2544 openFolder(folderIcon);
2545 } else {
2546 // Find the open folder...
2547 int folderScreen;
2548 if (openFolder != null) {
2549 folderScreen = mWorkspace.getPageForView(openFolder);
2550 // .. and close it
2551 closeFolder(openFolder);
2552 if (folderScreen != mWorkspace.getCurrentPage()) {
2553 // Close any folder open on the current screen
2554 closeFolder();
2555 // Pull the folder onto this screen
2556 openFolder(folderIcon);
2557 }
2558 }
2559 }
Michael Jurka5130e402011-10-13 04:55:35 -07002560 }
2561
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002562 /**
2563 * Event handler for the (Add) Widgets button that appears after a long press
2564 * on the home screen.
2565 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002566 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002567 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002568 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2569 }
2570
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002571 /**
2572 * Event handler for the wallpaper picker button that appears after a long press
2573 * on the home screen.
2574 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002575 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002576 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2577 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2578 pickWallpaper.setComponent(getWallpaperPickerComponent());
2579 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2580 }
2581
2582 /**
2583 * Event handler for a click on the settings button that appears after a long press
2584 * on the home screen.
2585 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002586 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002587 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2588 }
2589
Michael Jurka5130e402011-10-13 04:55:35 -07002590 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002591 // Provide the same haptic feedback that the system offers for virtual keys.
2592 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002593 }
2594
Adam Cohen61f560d2013-09-30 15:58:20 -07002595 public void performHapticFeedbackOnTouchDown(View v) {
2596 // Provide the same haptic feedback that the system offers for virtual keys.
2597 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2598 }
2599
2600 public View.OnTouchListener getHapticFeedbackTouchListener() {
2601 if (mHapticFeedbackTouchListener == null) {
2602 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2603 @Override
2604 public boolean onTouch(View v, MotionEvent event) {
2605 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2606 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2607 }
2608 return false;
2609 }
2610 };
2611 }
2612 return mHapticFeedbackTouchListener;
2613 }
2614
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002615 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002616 if (!DISABLE_MARKET_BUTTON) {
2617 if (mAppMarketIntent != null) {
2618 startActivitySafely(v, mAppMarketIntent, "app market");
2619 } else {
2620 Log.e(TAG, "Invalid app market intent.");
2621 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002622 }
2623 }
2624
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002625 public void onDragStarted(View view) {}
2626
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002627 /**
2628 * Called when the user stops interacting with the launcher.
2629 * This implies that the user is now on the homescreen and is not doing housekeeping.
2630 */
2631 protected void onInteractionEnd() {}
2632
2633 /**
2634 * Called when the user starts interacting with the launcher.
2635 * The possible interactions are:
2636 * - open all apps
2637 * - reorder an app shortcut, or a widget
2638 * - open the overview mode.
2639 * This is a good time to stop doing things that only make sense
2640 * when the user is on the homescreen and not doing housekeeping.
2641 */
2642 protected void onInteractionBegin() {}
2643
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002644 void startApplicationDetailsActivity(ComponentName componentName) {
2645 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002646 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2647 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002648 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2649 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002650 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002651 }
2652
Michael Jurka1e2f4652013-07-08 18:03:46 -07002653 // returns true if the activity was started
2654 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002655 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002656 // System applications cannot be installed. For now, show a toast explaining that.
2657 // We may give them the option of disabling apps this way.
2658 int messageId = R.string.uninstall_system_app_text;
2659 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002660 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002661 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002662 String packageName = componentName.getPackageName();
2663 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002664 Intent intent = new Intent(
2665 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002666 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2667 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002668 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002669 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002670 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002671 }
2672
Michael Jurka86a720e2012-05-09 11:23:23 -07002673 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002674 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002675
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002676 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002677 // Only launch using the new animation if the shortcut has not opted out (this is a
2678 // private contract between launcher and may be ignored in the future).
2679 boolean useLaunchAnimation = (v != null) &&
2680 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2681 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002682 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2683 v.getMeasuredWidth(), v.getMeasuredHeight());
2684
2685 startActivity(intent, opts.toBundle());
2686 } else {
2687 startActivity(intent);
2688 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002689 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002690 } catch (SecurityException e) {
2691 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002692 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002693 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002694 "or use the exported attribute for this activity. "
2695 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002696 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002697 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002698 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002699
Michael Jurka86a720e2012-05-09 11:23:23 -07002700 boolean startActivitySafely(View v, Intent intent, Object tag) {
2701 boolean success = false;
2702 try {
2703 success = startActivity(v, intent, tag);
2704 } catch (ActivityNotFoundException e) {
2705 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2706 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2707 }
2708 return success;
2709 }
2710
Adam Cohen268c4752012-06-06 17:47:33 -07002711 /**
2712 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2713 * in the DragLayer in the exact absolute location of the original FolderIcon.
2714 */
2715 private void copyFolderIconToImage(FolderIcon fi) {
2716 final int width = fi.getMeasuredWidth();
2717 final int height = fi.getMeasuredHeight();
2718
2719 // Lazy load ImageView, Bitmap and Canvas
2720 if (mFolderIconImageView == null) {
2721 mFolderIconImageView = new ImageView(this);
2722 }
2723 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2724 mFolderIconBitmap.getHeight() != height) {
2725 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2726 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2727 }
2728
2729 DragLayer.LayoutParams lp;
2730 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2731 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2732 } else {
2733 lp = new DragLayer.LayoutParams(width, height);
2734 }
2735
Adam Cohen307fe232012-08-16 17:55:58 -07002736 // The layout from which the folder is being opened may be scaled, adjust the starting
2737 // view size by this scale factor.
2738 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002739 lp.customPosition = true;
2740 lp.x = mRectForFolderAnimation.left;
2741 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002742 lp.width = (int) (scale * width);
2743 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002744
2745 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2746 fi.draw(mFolderIconCanvas);
2747 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002748 if (fi.getFolder() != null) {
2749 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2750 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002751 }
Adam Cohen268c4752012-06-06 17:47:33 -07002752 // Just in case this image view is still in the drag layer from a previous animation,
2753 // we remove it and re-add it.
2754 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2755 mDragLayer.removeView(mFolderIconImageView);
2756 }
2757 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002758 if (fi.getFolder() != null) {
2759 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002760 }
Adam Cohen268c4752012-06-06 17:47:33 -07002761 }
2762
Adam Cohen2801caf2011-05-13 20:57:39 -07002763 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002764 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002765 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2766 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2767 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2768
Adam Cohenc51934b2011-07-26 21:07:43 -07002769 FolderInfo info = (FolderInfo) fi.getTag();
2770 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2771 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002772 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2773 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002774 }
2775
Adam Cohen268c4752012-06-06 17:47:33 -07002776 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2777 copyFolderIconToImage(fi);
2778 fi.setVisibility(View.INVISIBLE);
2779
Michael Jurka2ecf9952012-06-18 12:52:28 -07002780 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002781 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002782 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2783 oa.start();
2784 }
2785
Adam Cohen268c4752012-06-06 17:47:33 -07002786 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002787 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002788 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2789 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2790 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2791
Adam Cohen268c4752012-06-06 17:47:33 -07002792 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002793
Adam Cohen268c4752012-06-06 17:47:33 -07002794 // We remove and re-draw the FolderIcon in-case it has changed
2795 mDragLayer.removeView(mFolderIconImageView);
2796 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002797 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002798 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002799 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002800 oa.addListener(new AnimatorListenerAdapter() {
2801 @Override
2802 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002803 if (cl != null) {
2804 cl.clearFolderLeaveBehind();
2805 // Remove the ImageView copy of the FolderIcon and make the original visible.
2806 mDragLayer.removeView(mFolderIconImageView);
2807 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002808 }
2809 }
2810 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002811 oa.start();
2812 }
2813
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002814 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002815 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002816 * is animated relative to the specified View. If the View is null, no animation
2817 * is played.
2818 *
2819 * @param folderInfo The FolderInfo describing the folder to open.
2820 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002821 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002822 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002823 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002824
Adam Cohena9cf38f2011-05-02 15:36:58 -07002825 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002826
Adam Cohen4554ee12011-08-03 16:13:21 -07002827 // Just verify that the folder hasn't already been added to the DragLayer.
2828 // There was a one-off crash where the folder had a parent already.
2829 if (folder.getParent() == null) {
2830 mDragLayer.addView(folder);
2831 mDragController.addDropTarget((DropTarget) folder);
2832 } else {
2833 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2834 folder.getParent() + ").");
2835 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002836 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002837 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002838
2839 // Notify the accessibility manager that this folder "window" has appeared and occluded
2840 // the workspace items
2841 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2842 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002843 }
2844
2845 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002846 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002847 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002848 if (folder.isEditingName()) {
2849 folder.dismissEditingName();
2850 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002851 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002852
2853 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002854 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002855 }
2856 }
2857
2858 void closeFolder(Folder folder) {
2859 folder.getInfo().opened = false;
2860
2861 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2862 if (parent != null) {
2863 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2864 shrinkAndFadeInFolderIcon(fi);
2865 }
2866 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002867
2868 // Notify the accessibility manager that this folder "window" has disappeard and no
2869 // longer occludeds the workspace items
2870 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002871 }
2872
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002873 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002874 if (!isDraggingEnabled()) return false;
2875 if (isWorkspaceLocked()) return false;
2876 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002877
Adam Cohen1697b792013-09-17 19:08:21 -07002878 if (v instanceof Workspace) {
2879 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002880 if (mWorkspace.enterOverviewMode()) {
2881 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2882 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2883 return true;
2884 } else {
2885 return false;
2886 }
Adam Cohen1697b792013-09-17 19:08:21 -07002887 }
Adam Cohen1697b792013-09-17 19:08:21 -07002888 }
2889
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002890 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002891 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002892 }
2893
Michael Jurka0280c3b2010-09-17 15:00:07 -07002894 resetAddInfo();
2895 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002896 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002897 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002898 return true;
2899 }
2900
Winson Chung3d503fb2011-07-13 17:25:49 -07002901 // The hotseat touch handling does not go through Workspace, and we always allow long press
2902 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002903 final View itemUnderLongClick = longClickCellInfo.cell;
Dan Sandlere26d0942014-01-13 14:30:14 -05002904 final boolean inHotseat = isHotseatLayout(v);
2905 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002906 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002907 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002908 // User long pressed on empty space
2909 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2910 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2911 // Disabling reordering until we sort out some issues.
2912 if (mWorkspace.isInOverviewMode()) {
2913 mWorkspace.startReordering(v);
2914 } else {
2915 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002916 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002917 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002918 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2919 mHotseat.getOrderInHotseat(
2920 longClickCellInfo.cellX,
2921 longClickCellInfo.cellY));
2922 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002923 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002924 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002925 }
2926 }
2927 }
2928 return true;
2929 }
2930
Winson Chung3d503fb2011-07-13 17:25:49 -07002931 boolean isHotseatLayout(View layout) {
2932 return mHotseat != null && layout != null &&
2933 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2934 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002935
Winson Chung3d503fb2011-07-13 17:25:49 -07002936 /**
2937 * Returns the CellLayout of the specified container at the specified screen.
2938 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002939 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002940 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2941 if (mHotseat != null) {
2942 return mHotseat.getLayout();
2943 } else {
2944 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002945 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002946 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002947 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002948 }
2949 }
2950
Daniel Sandler843e8602010-06-07 14:59:01 -04002951 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002952 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002953 }
2954
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002955 /**
2956 * Helper method for the cameraZoomIn/cameraZoomOut animations
2957 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002958 * @param scaleFactor The scale factor used for the zoom
2959 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002960 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002961 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002962 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002963 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002964
Craig Mautner360310b2012-10-26 15:13:08 -07002965 private void setWorkspaceBackground(boolean workspace) {
2966 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002967 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002968 }
2969
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002970 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002971 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2972 int curflags = getWindow().getAttributes().flags
2973 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2974 if (wpflags != curflags) {
2975 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2976 }
Craig Mautner360310b2012-10-26 15:13:08 -07002977 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002978 }
2979
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002980 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2981 if (v instanceof LauncherTransitionable) {
2982 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2983 }
2984 }
2985
Michael Jurkabed61d22012-02-14 22:51:29 -08002986 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2987 if (v instanceof LauncherTransitionable) {
2988 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2989 }
Winson Chung70442722012-02-10 15:43:22 -08002990
2991 // Update the workspace transition step as well
2992 dispatchOnLauncherTransitionStep(v, 0f);
2993 }
2994
2995 private void dispatchOnLauncherTransitionStep(View v, float t) {
2996 if (v instanceof LauncherTransitionable) {
2997 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2998 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002999 }
3000
3001 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3002 if (v instanceof LauncherTransitionable) {
3003 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3004 }
Winson Chung70442722012-02-10 15:43:22 -08003005
3006 // Update the workspace transition step as well
3007 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003008 }
3009
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003010 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003011 * Things to test when changing the following seven functions.
3012 * - Home from workspace
3013 * - from center screen
3014 * - from other screens
3015 * - Home from all apps
3016 * - from center screen
3017 * - from other screens
3018 * - Back from all apps
3019 * - from center screen
3020 * - from other screens
3021 * - Launch app from workspace and quit
3022 * - with back
3023 * - with home
3024 * - Launch app from all apps and quit
3025 * - with back
3026 * - with home
3027 * - Go to a screen that's not the default, then all
3028 * apps, and launch and app, and go back
3029 * - with back
3030 * -with home
3031 * - On workspace, long press power and go back
3032 * - with back
3033 * - with home
3034 * - On all apps, long press power and go back
3035 * - with back
3036 * - with home
3037 * - On workspace, power off
3038 * - On all apps, power off
3039 * - Launch an app and turn off the screen while in that app
3040 * - Go back with home key
3041 * - Go back with back key TODO: make this not go to workspace
3042 * - From all apps
3043 * - From workspace
3044 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3045 * - From all apps
3046 * - From the center workspace
3047 * - From another workspace
3048 */
3049
3050 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003051 * Zoom the camera out from the workspace to reveal 'toView'.
3052 * Assumes that the view to show is anchored at either the very top or very bottom
3053 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003054 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003055 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003056 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3057 showAppsCustomizeHelper(animated, springLoaded, contentType);
3058 }
3059 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3060 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003061 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003062 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003063 mStateAnimation.cancel();
3064 mStateAnimation = null;
3065 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003066 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003067
Winson Chungf0ea4d32011-06-06 14:27:16 -07003068 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3069 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3070 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003071 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003072 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003073 final int startDelay =
3074 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003075
Michael Jurkab3e22d92011-10-31 15:58:33 -07003076 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003077
Michael Jurkad74c9842011-07-10 12:44:21 -07003078 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003079 Animator workspaceAnim =
3080 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003081 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003082 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3083 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003084 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3085 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003086
3087 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003088 toView.setScaleX(scale);
3089 toView.setScaleY(scale);
3090 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3091 scaleAnim.
3092 scaleX(1f).scaleY(1f).
3093 setDuration(duration).
3094 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003095
Winson Chungf0ea4d32011-06-06 14:27:16 -07003096 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003097 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003098 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003099 .ofFloat(toView, "alpha", 0f, 1f)
3100 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003101 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003102 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3103 @Override
3104 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003105 if (animation == null) {
3106 throw new RuntimeException("animation is null");
3107 }
Winson Chung70442722012-02-10 15:43:22 -08003108 float t = (Float) animation.getAnimatedValue();
3109 dispatchOnLauncherTransitionStep(fromView, t);
3110 dispatchOnLauncherTransitionStep(toView, t);
3111 }
3112 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003113
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003114 // toView should appear right at the end of the workspace shrink
3115 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003116 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003117 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003118 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003119
3120 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003121 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003122 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003123 // Prepare the position
3124 toView.setTranslationX(0.0f);
3125 toView.setTranslationY(0.0f);
3126 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003127 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003128 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003129 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003130 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003131 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3132 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003133
Winson Chungc7d2b602012-05-16 17:02:20 -07003134 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003135 if (mSearchDropTargetBar != null) {
3136 mSearchDropTargetBar.hideSearchBar(false);
3137 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003138 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003139 });
3140
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003141 if (workspaceAnim != null) {
3142 mStateAnimation.play(workspaceAnim);
3143 }
Michael Jurka1899a362011-11-03 13:50:45 -07003144
3145 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003146
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003147 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3148 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003149
3150 // If any of the objects being animated haven't been measured/laid out
3151 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003152 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003153 (mWorkspace.getMeasuredWidth() == 0) ||
3154 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003155 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003156 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003157
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003158 final AnimatorSet stateAnimation = mStateAnimation;
3159 final Runnable startAnimRunnable = new Runnable() {
3160 public void run() {
3161 // Check that mStateAnimation hasn't changed while
3162 // we waited for a layout/draw pass
3163 if (mStateAnimation != stateAnimation)
3164 return;
3165 setPivotsForZoom(toView, scale);
3166 dispatchOnLauncherTransitionStart(fromView, animated, false);
3167 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003168 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003169 }
3170 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003171 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003172 final ViewTreeObserver observer = toView.getViewTreeObserver();
3173 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3174 public void onGlobalLayout() {
3175 startAnimRunnable.run();
3176 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3177 }
3178 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003179 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003180 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003181 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003182 } else {
3183 toView.setTranslationX(0.0f);
3184 toView.setTranslationY(0.0f);
3185 toView.setScaleX(1.0f);
3186 toView.setScaleY(1.0f);
3187 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003188 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003189
Daniel Sandlere4f98912013-06-25 15:13:26 -04003190 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003191 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003192 if (mSearchDropTargetBar != null) {
3193 mSearchDropTargetBar.hideSearchBar(false);
3194 }
Michael Jurkaabded662011-03-04 12:06:57 -08003195 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003196 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003197 dispatchOnLauncherTransitionStart(fromView, animated, false);
3198 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003199 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003200 dispatchOnLauncherTransitionStart(toView, animated, false);
3201 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003202 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003203 }
3204
3205 /**
3206 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003207 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003208 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003209 */
Adam Cohened307df2013-10-02 09:37:31 -07003210 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003211 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003212
Michael Jurkab3e22d92011-10-31 15:58:33 -07003213 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003214 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003215 mStateAnimation.cancel();
3216 mStateAnimation = null;
3217 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003218 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003219
Winson Chungf0ea4d32011-06-06 14:27:16 -07003220 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003221 final int fadeOutDuration =
3222 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003223 final float scaleFactor = (float)
3224 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3225 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003226 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003227 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003228 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003229 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3230 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003231 toState, animated, stagger, -1);
3232 } else if (toState == Workspace.State.SPRING_LOADED ||
3233 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003234 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003235 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003236 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003237
Michael Jurkab3e22d92011-10-31 15:58:33 -07003238 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003239 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003240 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003241 final LauncherViewPropertyAnimator scaleAnim =
3242 new LauncherViewPropertyAnimator(fromView);
3243 scaleAnim.
3244 scaleX(scaleFactor).scaleY(scaleFactor).
3245 setDuration(duration).
3246 setInterpolator(new Workspace.ZoomInInterpolator());
3247
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003248 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003249 .ofFloat(fromView, "alpha", 1f, 0f)
3250 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003251 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003252 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3253 @Override
3254 public void onAnimationUpdate(ValueAnimator animation) {
3255 float t = 1f - (Float) animation.getAnimatedValue();
3256 dispatchOnLauncherTransitionStep(fromView, t);
3257 dispatchOnLauncherTransitionStep(toView, t);
3258 }
3259 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003260
Michael Jurka2ecf9952012-06-18 12:52:28 -07003261 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003262
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003263 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3264 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003265 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003266
3267 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003268 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003269 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003270 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003271 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3272 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003273 if (onCompleteRunnable != null) {
3274 onCompleteRunnable.run();
3275 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003276 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003277 }
3278 });
3279
Winson Chungf0ea4d32011-06-06 14:27:16 -07003280 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003281 if (workspaceAnim != null) {
3282 mStateAnimation.play(workspaceAnim);
3283 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003284 dispatchOnLauncherTransitionStart(fromView, animated, true);
3285 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003286 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003287 } else {
3288 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003289 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003290 dispatchOnLauncherTransitionStart(fromView, animated, true);
3291 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003292 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003293 dispatchOnLauncherTransitionStart(toView, animated, true);
3294 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003295 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003296 }
3297
Michael Jurkae326f182011-11-21 14:05:46 -08003298 @Override
3299 public void onTrimMemory(int level) {
3300 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003301 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003302 mAppsCustomizeTabHost.onTrimMemory();
3303 }
3304 }
3305
Adam Cohened307df2013-10-02 09:37:31 -07003306 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003307 showWorkspace(animated, null);
3308 }
3309
Adam Cohened307df2013-10-02 09:37:31 -07003310 protected void showWorkspace() {
3311 showWorkspace(true);
3312 }
3313
Adam Cohened66b2b2012-01-23 17:28:51 -08003314 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003315 if (mWorkspace.isInOverviewMode()) {
3316 mWorkspace.exitOverviewMode(animated);
3317 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003318 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003319 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003320 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003321 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003322
Winson Chungc7d2b602012-05-16 17:02:20 -07003323 // Show the search bar (only animate if we were showing the drop target bar in spring
3324 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003325 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003326 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003327 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003328
Michael Jurkab3e22d92011-10-31 15:58:33 -07003329 // Set focus to the AppsCustomize button
3330 if (mAllAppsButton != null) {
3331 mAllAppsButton.requestFocus();
3332 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003333 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003334
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003335 // Change the state *after* we've called all the transition code
3336 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003337
Winson Chung5fb63472011-02-02 17:03:37 -08003338 // Resume the auto-advance of widgets
3339 mUserPresent = true;
3340 updateRunning();
3341
alanv1d4fde62012-10-17 13:15:47 -07003342 // Send an accessibility event to announce the context change
3343 getWindow().getDecorView()
3344 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003345
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003346 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003347 }
3348
Adam Cohened307df2013-10-02 09:37:31 -07003349 void showOverviewMode(boolean animated) {
3350 mWorkspace.setVisibility(View.VISIBLE);
3351 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3352 mState = State.WORKSPACE;
3353 onWorkspaceShown(animated);
3354 }
3355
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003356 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003357 }
3358
Winson Chung82963d52013-10-09 11:20:57 -07003359 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3360 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003361 if (mState != State.WORKSPACE) return;
3362
Winson Chung82963d52013-10-09 11:20:57 -07003363 if (resetPageToZero) {
3364 mAppsCustomizeTabHost.reset();
3365 }
Winson Chungc58497e2013-09-03 17:48:37 -07003366 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003367 mAppsCustomizeTabHost.requestFocus();
3368
Michael Jurkab3e22d92011-10-31 15:58:33 -07003369 // Change the state *after* we've called all the transition code
3370 mState = State.APPS_CUSTOMIZE;
3371
3372 // Pause the auto-advance of widgets until we are out of AllApps
3373 mUserPresent = false;
3374 updateRunning();
3375 closeFolder();
3376
3377 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003378 getWindow().getDecorView()
3379 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003380 }
3381
Adam Cohen7777d962011-08-18 18:58:38 -07003382 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003383 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003384 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003385 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003386 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003387 }
Adam Cohen7777d962011-08-18 18:58:38 -07003388
Adam Cohenad4e15c2013-10-17 16:21:35 -07003389 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003390 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003391 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3392
Winson Chunge7a03942011-08-05 15:05:12 -07003393 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003394 @Override
3395 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003396 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003397 // Before we show workspace, hide all apps again because
3398 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3399 // clean up our state transition functions
3400 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003401 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003402 } else {
3403 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003404 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003405 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003406 }, delay);
3407
Winson Chung557d6ed2011-07-08 15:34:52 -07003408 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003409
Michael Jurkad3ef3062010-11-23 16:23:58 -08003410 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003411 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003412 final boolean animated = true;
3413 final boolean springLoaded = true;
3414 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003415 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003416 }
3417 // Otherwise, we are not in spring loaded mode, so don't do anything.
3418 }
3419
Michael Jurkab3e22d92011-10-31 15:58:33 -07003420 void lockAllApps() {
3421 // TODO
3422 }
3423
3424 void unlockAllApps() {
3425 // TODO
3426 }
3427
Winson Chungf0ea4d32011-06-06 14:27:16 -07003428 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003429 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003430 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003431 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003432 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003433 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003434 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003435 int duration = 0;
3436 if (mSearchDropTargetBar != null) {
3437 duration = mSearchDropTargetBar.getTransitionInDuration();
3438 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003439 mHotseat.animate().alpha(1f).setDuration(duration);
3440 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003441 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003442 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003443 }
3444 }
3445 }
3446
3447 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003448 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003449 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003450 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003451 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003452 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003453 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003454 int duration = 0;
3455 if (mSearchDropTargetBar != null) {
3456 duration = mSearchDropTargetBar.getTransitionOutDuration();
3457 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003458 mHotseat.animate().alpha(0f).setDuration(duration);
3459 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003460 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003461 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003462 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003463 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003464 }
3465
Patrick Dubroy5f445422011-02-18 14:35:21 -08003466 /**
3467 * Add an item from all apps or customize onto the given workspace screen.
3468 * If layout is null, add to the current screen.
3469 */
3470 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003471 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003472 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003473 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003474 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003475
Winson Chungdff8ebb2011-09-08 17:25:31 -07003476 /** Maps the current orientation to an index for referencing orientation correct global icons */
3477 private int getCurrentOrientationIndexForGlobalIcons() {
3478 // default - 0, landscape - 1
3479 switch (getResources().getConfiguration().orientation) {
3480 case Configuration.ORIENTATION_LANDSCAPE:
3481 return 1;
3482 default:
3483 return 0;
3484 }
3485 }
3486
Michael Jurkaae65ee32012-04-30 11:45:54 -07003487 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003488 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003489 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003490 // Look for the toolbar icon specified in the activity meta-data
3491 Bundle metaData = packageManager.getActivityInfo(
3492 activityName, PackageManager.GET_META_DATA).metaData;
3493 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003494 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003495 if (iconResId != 0) {
3496 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003497 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003498 }
3499 }
3500 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003501 // This can happen if the activity defines an invalid drawable
3502 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3503 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003504 } catch (Resources.NotFoundException nfe) {
3505 // This can happen if the activity defines an invalid drawable
3506 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3507 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003508 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003509 return null;
3510 }
3511
3512 // if successful in getting icon, return it; otherwise, set button to use default drawable
3513 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003514 int buttonId, ComponentName activityName, int fallbackDrawableId,
3515 String toolbarResourceName) {
3516 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003517 Resources r = getResources();
3518 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3519 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003520
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003521 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003522 // If we were unable to find the icon via the meta-data, use a generic one
3523 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003524 toolbarIcon = r.getDrawable(fallbackDrawableId);
3525 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003526 if (button != null) {
3527 button.setCompoundDrawables(toolbarIcon, null, null, null);
3528 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003529 return null;
3530 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003531 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003532 if (button != null) {
3533 button.setCompoundDrawables(toolbarIcon, null, null, null);
3534 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003535 return toolbarIcon.getConstantState();
3536 }
3537 }
3538
3539 // if successful in getting icon, return it; otherwise, set button to use default drawable
3540 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003541 int buttonId, ComponentName activityName, int fallbackDrawableId,
3542 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003543 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003544 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003545
Michael Jurka19e0fc52011-07-22 18:00:21 -07003546 if (button != null) {
3547 // If we were unable to find the icon via the meta-data, use a
3548 // generic one
3549 if (toolbarIcon == null) {
3550 button.setImageResource(fallbackDrawableId);
3551 } else {
3552 button.setImageDrawable(toolbarIcon);
3553 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003554 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003555
3556 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3557
Michael Jurka0423dcf2010-10-05 14:56:18 -07003558 }
3559
Winson Chung1b884092012-06-08 17:13:02 -07003560 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003561 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003562 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003563 }
3564
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003565 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003566 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003567 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003568 }
3569
Winson Chungbb185bd2011-11-21 12:31:42 -08003570 private void invalidatePressedFocusedStates(View container, View button) {
3571 if (container instanceof HolographicLinearLayout) {
3572 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3573 layout.invalidatePressedFocusedStates();
3574 } else if (button instanceof HolographicImageView) {
3575 HolographicImageView view = (HolographicImageView) button;
3576 view.invalidatePressedFocusedStates();
3577 }
3578 }
3579
Cristina Stancu476493b2013-08-07 17:20:14 +01003580 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003581 if (mQsb == null) {
3582 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3583 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003584 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003585 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003586 }
3587
3588 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003589 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003590 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003591 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003592 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003593
Winson Chung1cad91e2011-05-25 17:41:01 -07003594 final SearchManager searchManager =
3595 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3596 ComponentName activityName = searchManager.getGlobalSearchActivity();
3597 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003598 int coi = getCurrentOrientationIndexForGlobalIcons();
3599 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003600 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3601 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3602 if (sGlobalSearchIcon[coi] == null) {
3603 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3604 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3605 TOOLBAR_ICON_METADATA_NAME);
3606 }
3607
Winson Chungc51db6a2011-10-05 11:44:49 -07003608 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3609 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003610 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003611 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003612 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003613 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003614 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3615 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003616 if (searchButton != null) searchButton.setVisibility(View.GONE);
3617 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003618 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003619 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003620 }
3621 }
3622
Cristina Stancu476493b2013-08-07 17:20:14 +01003623 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003624 final View searchButtonContainer = findViewById(R.id.search_button_container);
3625 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003626 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003627 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003628 }
3629
Cristina Stancu476493b2013-08-07 17:20:14 +01003630 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003631 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003632 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003633
Winson Chungc51db6a2011-10-05 11:44:49 -07003634 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003635 final SearchManager searchManager =
3636 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3637 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3638
3639 ComponentName activityName = null;
3640 if (globalSearchActivity != null) {
3641 // Check if the global search activity handles voice search
3642 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3643 intent.setPackage(globalSearchActivity.getPackageName());
3644 activityName = intent.resolveActivity(getPackageManager());
3645 }
3646
3647 if (activityName == null) {
3648 // Fallback: check if an activity other than the global search activity
3649 // resolves this
3650 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3651 activityName = intent.resolveActivity(getPackageManager());
3652 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003653 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003654 int coi = getCurrentOrientationIndexForGlobalIcons();
3655 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003656 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3657 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3658 if (sVoiceSearchIcon[coi] == null) {
3659 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3660 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3661 TOOLBAR_ICON_METADATA_NAME);
3662 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003663 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003664 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003665 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003666 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003667 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003668 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003669 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003670 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003671 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003672 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003673 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003674 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003675
Cristina Stancu476493b2013-08-07 17:20:14 +01003676 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003677 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3678 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003679 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003680 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003681 }
3682
Winson Chung5841efa2013-09-30 18:06:44 -07003683 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003684 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3685 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003686 boolean visible = !forceDisableVoiceButtonProxy &&
3687 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003688 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003689 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003690 }
3691 }
Winson Chung5841efa2013-09-30 18:06:44 -07003692
3693 /**
3694 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3695 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3696 */
3697 public void disableVoiceButtonProxy(boolean disabled) {
3698 updateVoiceButtonProxyVisible(disabled);
3699 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003700 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003701 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003702 */
3703 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003704 if (!DISABLE_MARKET_BUTTON) {
3705 final View marketButton = findViewById(R.id.market_button);
3706 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3707 // Find the app market activity by resolving an intent.
3708 // (If multiple app markets are installed, it will return the ResolverActivity.)
3709 ComponentName activityName = intent.resolveActivity(getPackageManager());
3710 if (activityName != null) {
3711 int coi = getCurrentOrientationIndexForGlobalIcons();
3712 mAppMarketIntent = intent;
3713 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3714 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3715 TOOLBAR_ICON_METADATA_NAME);
3716 marketButton.setVisibility(View.VISIBLE);
3717 } else {
3718 // We should hide and disable the view so that we don't try and restore the visibility
3719 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3720 marketButton.setVisibility(View.GONE);
3721 marketButton.setEnabled(false);
3722 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003723 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003724 }
3725
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003726 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003727 if (!DISABLE_MARKET_BUTTON) {
3728 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3729 Resources r = getResources();
3730 Drawable marketIconDrawable = d.newDrawable(r);
3731 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3732 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3733 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003734
Winson Chungd64a6662013-09-30 11:06:59 -07003735 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3736 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003737 }
3738
Michael Jurkad7c28052012-04-27 15:43:36 -07003739 @Override
3740 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003741 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003742 final List<CharSequence> text = event.getText();
3743 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003744 // Populate event with a fake title based on the current state.
3745 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003746 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003747 } else {
3748 text.add(getString(R.string.all_apps_home_button_label));
3749 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003750 return result;
3751 }
3752
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003753 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003754 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003755 */
3756 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3757 @Override
3758 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003759 closeSystemDialogs();
3760 }
3761 }
3762
3763 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003764 * Receives notifications whenever the appwidgets are reset.
3765 */
3766 private class AppWidgetResetObserver extends ContentObserver {
3767 public AppWidgetResetObserver() {
3768 super(new Handler());
3769 }
3770
3771 @Override
3772 public void onChange(boolean selfChange) {
3773 onAppWidgetReset();
3774 }
3775 }
3776
3777 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003778 * If the activity is currently paused, signal that we need to run the passed Runnable
3779 * in onResume.
3780 *
3781 * This needs to be called from incoming places where resources might have been loaded
3782 * while we are paused. That is becaues the Configuration might be wrong
3783 * when we're not running, and if it comes back to what it was when we
3784 * were paused, we are not restarted.
3785 *
3786 * Implementation of the method from LauncherModel.Callbacks.
3787 *
3788 * @return true if we are currently paused. The caller might be able to
3789 * skip some work in that case since we will come back again.
3790 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003791 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003792 if (mPaused) {
3793 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003794 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003795 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003796 }
3797 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003798 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003799 return true;
3800 } else {
3801 return false;
3802 }
3803 }
3804
Michael Jurkac402cd92013-05-20 15:49:32 +02003805 private boolean waitUntilResume(Runnable run) {
3806 return waitUntilResume(run, false);
3807 }
3808
Michael Jurka1e2f4652013-07-08 18:03:46 -07003809 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003810 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003811 }
3812
Michael Jurka7607c2f2013-04-03 14:33:19 -07003813 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003814 * If the activity is currently paused, signal that we need to re-run the loader
3815 * in onResume.
3816 *
3817 * This needs to be called from incoming places where resources might have been loaded
3818 * while we are paused. That is becaues the Configuration might be wrong
3819 * when we're not running, and if it comes back to what it was when we
3820 * were paused, we are not restarted.
3821 *
3822 * Implementation of the method from LauncherModel.Callbacks.
3823 *
3824 * @return true if we are currently paused. The caller might be able to
3825 * skip some work in that case since we will come back again.
3826 */
3827 public boolean setLoadOnResume() {
3828 if (mPaused) {
3829 Log.i(TAG, "setLoadOnResume");
3830 mOnResumeNeedsLoad = true;
3831 return true;
3832 } else {
3833 return false;
3834 }
3835 }
3836
3837 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003838 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003839 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003840 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003841 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003842 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003843 } else {
3844 return SCREEN_COUNT / 2;
3845 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003846 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003847
Joe Onorato9c1289c2009-08-17 11:03:03 -04003848 /**
3849 * Refreshes the shortcuts shown on the workspace.
3850 *
3851 * Implementation of the method from LauncherModel.Callbacks.
3852 */
3853 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003854 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003855
Michael Jurka7607c2f2013-04-03 14:33:19 -07003856 // If we're starting binding all over again, clear any bind calls we'd postponed in
3857 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3858 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003859 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003860
Winson Chungd64d1762013-08-20 14:37:16 -07003861 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003862 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003863 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003864
Michael Jurka05bf6442011-11-30 20:28:53 -08003865 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003866 if (mHotseat != null) {
3867 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003868 }
3869 }
3870
Adam Cohendcd297f2013-06-18 13:13:40 -07003871 @Override
3872 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003873 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003874
Adam Cohen5084cba2013-09-03 12:01:16 -07003875 // If there are no screens, we need to have an empty screen
3876 if (orderedScreenIds.size() == 0) {
3877 mWorkspace.addExtraEmptyScreen();
3878 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003879
3880 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003881 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003882 if (hasCustomContentToLeft()) {
3883 mWorkspace.createCustomContentContainer();
3884 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003885 }
Winson Chung64359a52013-07-08 17:17:08 -07003886 }
3887
3888 @Override
3889 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003890 // Log to disk
3891 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3892 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3893 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003894 int count = orderedScreenIds.size();
3895 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003896 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003897 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003898 }
3899
Adam Cohen39a06042013-07-19 14:30:12 -07003900 private boolean shouldShowWeightWatcher() {
3901 String spKey = LauncherAppState.getSharedPreferencesKey();
3902 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003903 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003904
3905 return show;
3906 }
3907
3908 private void toggleShowWeightWatcher() {
3909 String spKey = LauncherAppState.getSharedPreferencesKey();
3910 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3911 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3912
3913 show = !show;
3914
3915 SharedPreferences.Editor editor = sp.edit();
3916 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3917 editor.commit();
3918
3919 if (mWeightWatcher != null) {
3920 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3921 }
3922 }
3923
Winson Chungd64d1762013-08-20 14:37:16 -07003924 public void bindAppsAdded(final ArrayList<Long> newScreens,
3925 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003926 final ArrayList<ItemInfo> addAnimated,
3927 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003928 Runnable r = new Runnable() {
3929 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003930 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003931 }
3932 };
3933 if (waitUntilResume(r)) {
3934 return;
3935 }
3936
Winson Chungd64d1762013-08-20 14:37:16 -07003937 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003938 if (newScreens != null) {
3939 bindAddScreens(newScreens);
3940 }
Winson Chungd64d1762013-08-20 14:37:16 -07003941
3942 // We add the items without animation on non-visible pages, and with
3943 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003944 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003945 bindItems(addNotAnimated, 0,
3946 addNotAnimated.size(), false);
3947 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003948 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003949 bindItems(addAnimated, 0,
3950 addAnimated.size(), true);
3951 }
Winson Chungc58497e2013-09-03 17:48:37 -07003952
Winson Chung87412982013-10-03 18:34:14 -07003953 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003954 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003955
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003956 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003957 addedApps != null && mAppsCustomizeContent != null) {
3958 mAppsCustomizeContent.addApps(addedApps);
3959 }
Winson Chungd64d1762013-08-20 14:37:16 -07003960 }
3961
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003962 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003963 * Bind the items start-end from the list.
3964 *
3965 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003966 */
Winson Chung64359a52013-07-08 17:17:08 -07003967 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3968 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003969 Runnable r = new Runnable() {
3970 public void run() {
3971 bindItems(shortcuts, start, end, forceAnimateIcons);
3972 }
3973 };
3974 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003975 return;
3976 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003977
Winson Chungf0c6ae02012-03-21 16:10:31 -07003978 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003979 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3980 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003981 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003982 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003983 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003984 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003985 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003986
3987 // Short circuit if we are loading dock items for a configuration which has no dock
3988 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3989 mHotseat == null) {
3990 continue;
3991 }
3992
Joe Onorato9c1289c2009-08-17 11:03:03 -04003993 switch (item.itemType) {
3994 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3995 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003996 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003997 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003998
Winson Chung64359a52013-07-08 17:17:08 -07003999 /*
4000 * TODO: FIX collision case
4001 */
Winson Chungce376632013-07-11 16:12:41 -07004002 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4003 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4004 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004005 View v = cl.getChildAt(item.cellX, item.cellY);
4006 Object tag = v.getTag();
4007 String desc = "Collision while binding workspace item: " + item
4008 + ". Collides with " + tag;
4009 if (LauncherAppState.isDogfoodBuild()) {
4010 throw (new RuntimeException(desc));
4011 } else {
4012 Log.d(TAG, desc);
4013 }
Winson Chungce376632013-07-11 16:12:41 -07004014 }
Winson Chung64359a52013-07-08 17:17:08 -07004015 }
4016
Adam Cohendcd297f2013-06-18 13:13:40 -07004017 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4018 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004019 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004020 // Animate all the applications up now
4021 shortcut.setAlpha(0f);
4022 shortcut.setScaleX(0f);
4023 shortcut.setScaleY(0f);
4024 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004025 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004026 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004027 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004028 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004029 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004030 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004031 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004032 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4033 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004034 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004035 default:
4036 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004037 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004038 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004039
Winson Chung997a9232013-07-24 15:33:46 -07004040 if (animateIcons) {
4041 // Animate to the correct page
4042 if (newShortcutsScreenId > -1) {
4043 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004044 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004045 final Runnable startBounceAnimRunnable = new Runnable() {
4046 public void run() {
4047 anim.playTogether(bounceAnims);
4048 anim.start();
4049 }
4050 };
Winson Chung997a9232013-07-24 15:33:46 -07004051 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004052 // We post the animation slightly delayed to prevent slowdowns
4053 // when we are loading right after we return to launcher.
4054 mWorkspace.postDelayed(new Runnable() {
4055 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004056 if (mWorkspace != null) {
4057 mWorkspace.snapToPage(newScreenIndex);
4058 mWorkspace.postDelayed(startBounceAnimRunnable,
4059 NEW_APPS_ANIMATION_DELAY);
4060 }
Winson Chung94d67682013-09-25 16:29:40 -07004061 }
4062 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004063 } else {
4064 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004065 }
4066 }
Winson Chung64359a52013-07-08 17:17:08 -07004067 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004068 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004069 }
4070
Joe Onorato9c1289c2009-08-17 11:03:03 -04004071 /**
4072 * Implementation of the method from LauncherModel.Callbacks.
4073 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004074 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004075 Runnable r = new Runnable() {
4076 public void run() {
4077 bindFolders(folders);
4078 }
4079 };
4080 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004081 return;
4082 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004083 sFolders.clear();
4084 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004085 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004086
4087 /**
4088 * Add the views for a widget to the workspace.
4089 *
4090 * Implementation of the method from LauncherModel.Callbacks.
4091 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004092 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004093 Runnable r = new Runnable() {
4094 public void run() {
4095 bindAppWidget(item);
4096 }
4097 };
4098 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004099 return;
4100 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004101
Daniel Sandler843e8602010-06-07 14:59:01 -04004102 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4103 if (DEBUG_WIDGETS) {
4104 Log.d(TAG, "bindAppWidget: " + item);
4105 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004106 final Workspace workspace = mWorkspace;
4107
4108 final int appWidgetId = item.appWidgetId;
4109 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004110 if (DEBUG_WIDGETS) {
4111 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4112 }
4113
Joe Onorato9c1289c2009-08-17 11:03:03 -04004114 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4115
Joe Onorato9c1289c2009-08-17 11:03:03 -04004116 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004117 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004118
Adam Cohendcd297f2013-06-18 13:13:40 -07004119 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004120 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004121 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4122
Joe Onorato9c1289c2009-08-17 11:03:03 -04004123 workspace.requestLayout();
4124
Daniel Sandler843e8602010-06-07 14:59:01 -04004125 if (DEBUG_WIDGETS) {
4126 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4127 + (SystemClock.uptimeMillis()-start) + "ms");
4128 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004129 }
4130
Adam Cohen1462de32012-07-24 22:34:36 -07004131 public void onPageBoundSynchronously(int page) {
4132 mSynchronouslyBoundPages.add(page);
4133 }
4134
Joe Onorato9c1289c2009-08-17 11:03:03 -04004135 /**
4136 * Callback saying that there aren't any more items to bind.
4137 *
4138 * Implementation of the method from LauncherModel.Callbacks.
4139 */
Adam Cohene25af792013-06-06 23:08:25 -07004140 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004141 Runnable r = new Runnable() {
4142 public void run() {
4143 finishBindingItems(upgradePath);
4144 }
4145 };
4146 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004147 return;
4148 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004149 if (mSavedState != null) {
4150 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004151 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004152 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004153 mSavedState = null;
4154 }
4155
Adam Cohen1462de32012-07-24 22:34:36 -07004156 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004157
Patrick Dubroy002cbf42011-03-03 16:36:21 -08004158 // If we received the result of any pending adds while the loader was running (e.g. the
4159 // widget configuration forced an orientation change), process them now.
4160 for (int i = 0; i < sPendingAddList.size(); i++) {
4161 completeAdd(sPendingAddList.get(i));
4162 }
4163 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004164
Winson Chungc51db6a2011-10-05 11:44:49 -07004165 // Update the market app icon as necessary (the other icons will be managed in response to
4166 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004167 if (!DISABLE_MARKET_BUTTON) {
4168 updateAppMarketIcon();
4169 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004170
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004171 setWorkspaceLoading(false);
Adam Cohene25af792013-06-06 23:08:25 -07004172 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004173 mWorkspace.getUniqueComponents(true, null);
4174 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004175 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004176 }
4177
Winson Chunga0b7e862013-09-05 16:03:15 -07004178 public boolean isAllAppsButtonRank(int rank) {
4179 if (mHotseat != null) {
4180 return mHotseat.isAllAppsButtonRank(rank);
4181 }
4182 return false;
4183 }
4184
Winson Chunga2413752012-04-03 14:22:34 -07004185 private boolean canRunNewAppsAnimation() {
4186 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4187 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4188 }
4189
Winson Chungc9168342013-06-26 14:54:55 -07004190 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4191 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4192 PropertyValuesHolder.ofFloat("alpha", 1f),
4193 PropertyValuesHolder.ofFloat("scaleX", 1f),
4194 PropertyValuesHolder.ofFloat("scaleY", 1f));
4195 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4196 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4197 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4198 return bounceAnim;
4199 }
4200
Adam Cohen27772732013-11-11 14:00:56 +00004201 public boolean useVerticalBarLayout() {
4202 return LauncherAppState.getInstance().getDynamicGrid().
4203 getDeviceProfile().isVerticalBarLayout();
4204 }
4205
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004206 protected Rect getSearchBarBounds() {
4207 return LauncherAppState.getInstance().getDynamicGrid().
4208 getDeviceProfile().getSearchBarBounds();
4209 }
4210
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004211 @Override
4212 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004213 boolean searchVisible = updateGlobalSearchIcon();
4214 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004215 if (mSearchDropTargetBar != null) {
4216 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4217 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004218 }
4219
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004220 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004221 * Add the icons for all apps.
4222 *
4223 * Implementation of the method from LauncherModel.Callbacks.
4224 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004225 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004226 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004227 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4228 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4229 getHotseat().addAllAppsFolder(mIconCache, apps,
4230 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4231 }
4232 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004233 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004234 if (mAppsCustomizeContent != null) {
4235 mAppsCustomizeContent.onPackagesUpdated(
4236 LauncherModel.getSortedWidgetsAndShortcuts(this));
4237 }
Winson Chungc58497e2013-09-03 17:48:37 -07004238 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004239 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004240 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004241 mAppsCustomizeContent.onPackagesUpdated(
4242 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004243 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004244 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004245 }
4246
4247 /**
4248 * A package was updated.
4249 *
4250 * Implementation of the method from LauncherModel.Callbacks.
4251 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004252 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004253 Runnable r = new Runnable() {
4254 public void run() {
4255 bindAppsUpdated(apps);
4256 }
4257 };
4258 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004259 return;
4260 }
4261
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004262 if (mWorkspace != null) {
4263 mWorkspace.updateShortcuts(apps);
4264 }
Winson Chungc58497e2013-09-03 17:48:37 -07004265
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004266 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004267 mAppsCustomizeContent != null) {
4268 mAppsCustomizeContent.updateApps(apps);
4269 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004270 }
4271
4272 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004273 * Update the state of a package, typically related to install state.
4274 *
4275 * Implementation of the method from LauncherModel.Callbacks.
4276 */
4277 public void updatePackageState(String pkgName, int state) {
4278 if (mWorkspace != null) {
4279 mWorkspace.updatePackageState(pkgName, state);
4280 }
4281 }
4282
4283 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004284 * A package was uninstalled. We take both the super set of packageNames
4285 * in addition to specific applications to remove, the reason being that
4286 * this can be called when a package is updated as well. In that scenario,
4287 * we only remove specific components from the workspace, where as
4288 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004289 *
4290 * Implementation of the method from LauncherModel.Callbacks.
4291 */
Winson Chung83892cc2013-05-01 16:53:33 -07004292 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Winson Chungdf95eb12013-10-16 14:57:07 -07004293 final ArrayList<AppInfo> appInfos) {
Winson Chungd64d1762013-08-20 14:37:16 -07004294 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004295 public void run() {
Winson Chungdf95eb12013-10-16 14:57:07 -07004296 bindComponentsRemoved(packageNames, appInfos);
Winson Chung83892cc2013-05-01 16:53:33 -07004297 }
Winson Chungd64d1762013-08-20 14:37:16 -07004298 };
4299 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004300 return;
4301 }
4302
Winson Chungdf95eb12013-10-16 14:57:07 -07004303 if (!packageNames.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004304 mWorkspace.removeItemsByPackageName(packageNames);
Winson Chungdf95eb12013-10-16 14:57:07 -07004305 }
4306 if (!appInfos.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004307 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004308 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004309
Winson Chunga1820962011-10-03 16:31:06 -07004310 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004311 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004312
Winson Chungdf95eb12013-10-16 14:57:07 -07004313 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004314 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004315 mAppsCustomizeContent != null) {
4316 mAppsCustomizeContent.removeApps(appInfos);
4317 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004318 }
Joe Onoratobe386092009-11-17 17:32:16 -08004319
4320 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004321 * A number of packages were updated.
4322 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004323 private ArrayList<Object> mWidgetsAndShortcuts;
4324 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004325 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004326 bindPackagesUpdated(mWidgetsAndShortcuts);
4327 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004328 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004329 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004330 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4331 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4332 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004333 return;
4334 }
4335
Winson Chung64359a52013-07-08 17:17:08 -07004336 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004337 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004338 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004339 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004340 }
4341
Winson Chung400438b2011-01-16 17:53:48 -08004342 private int mapConfigurationOriActivityInfoOri(int configOri) {
4343 final Display d = getWindowManager().getDefaultDisplay();
4344 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4345 switch (d.getRotation()) {
4346 case Surface.ROTATION_0:
4347 case Surface.ROTATION_180:
4348 // We are currently in the same basic orientation as the natural orientation
4349 naturalOri = configOri;
4350 break;
4351 case Surface.ROTATION_90:
4352 case Surface.ROTATION_270:
4353 // We are currently in the other basic orientation to the natural orientation
4354 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4355 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4356 break;
4357 }
4358
4359 int[] oriMap = {
4360 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4361 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4362 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4363 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4364 };
4365 // Since the map starts at portrait, we need to offset if this device's natural orientation
4366 // is landscape.
4367 int indexOffset = 0;
4368 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4369 indexOffset = 1;
4370 }
4371 return oriMap[(d.getRotation() + indexOffset) % 4];
4372 }
Adam Cohen446e9402011-09-15 18:21:21 -07004373
Winson Chung4b919f82012-05-01 10:44:08 -07004374 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004375 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004376 getResources().getBoolean(R.bool.allow_rotation);
4377 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004378 }
Winson Chung4b919f82012-05-01 10:44:08 -07004379 public void lockScreenOrientation() {
4380 if (isRotationEnabled()) {
4381 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4382 .getConfiguration().orientation));
4383 }
4384 }
4385 public void unlockScreenOrientation(boolean immediate) {
4386 if (isRotationEnabled()) {
4387 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004388 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004389 } else {
4390 mHandler.postDelayed(new Runnable() {
4391 public void run() {
4392 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4393 }
4394 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004395 }
Winson Chung4b919f82012-05-01 10:44:08 -07004396 }
Winson Chung400438b2011-01-16 17:53:48 -08004397 }
4398
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004399 /**
4400 * Called when the SearchBar hint should be changed.
4401 *
4402 * @param hint the hint to be displayed in the search bar.
4403 */
4404 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004405 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004406 }
4407
Winson Chunge43a1e72014-01-15 10:33:02 -08004408 protected boolean isLauncherPreinstalled() {
4409 PackageManager pm = getPackageManager();
4410 try {
4411 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4412 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4413 return true;
4414 } else {
4415 return false;
4416 }
4417 } catch (NameNotFoundException e) {
4418 e.printStackTrace();
4419 return false;
4420 }
4421 }
4422
Winson Chunge6eabff2013-09-24 11:01:23 -07004423 protected String getFirstRunClingSearchBarHint() {
4424 return "";
4425 }
4426 protected String getFirstRunCustomContentHint() {
4427 return "";
4428 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004429 protected int getFirstRunFocusedHotseatAppDrawableId() {
4430 return -1;
4431 }
4432 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4433 return null;
4434 }
4435 protected int getFirstRunFocusedHotseatAppRank() {
4436 return -1;
4437 }
4438 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4439 return "";
4440 }
4441 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4442 return "";
4443 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004444
Winson Chungaf40f202013-09-18 18:26:31 -07004445 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004446 mLauncherClings.dismissFirstRunCling(v);
4447 }
4448 public void dismissMigrationClingCopyApps(View v) {
4449 mLauncherClings.dismissMigrationClingCopyApps(v);
4450 }
4451 public void dismissMigrationClingUseDefault(View v) {
4452 mLauncherClings.dismissMigrationClingUseDefault(v);
4453 }
4454 public void dismissMigrationWorkspaceCling(View v) {
4455 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004456 }
Winson Chung82f55532011-08-09 14:14:23 -07004457 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004458 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004459 }
4460 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004461 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004462 }
4463
Adam Cohen432609a2014-03-13 17:03:22 -07004464
4465 /**
4466 * To be overridden by subclasses to indicate that there is an activity to launch
4467 * before showing the standard launcher experience.
4468 */
4469 protected boolean hasFirstRunActivity() {
4470 return false;
4471 }
4472
4473 /**
4474 * To be overridden by subclasses to launch any first run activity
4475 */
4476 protected Intent getFirstRunActivity() {
4477 return null;
4478 }
4479
Winson Chunga6945242014-01-08 14:04:34 -08004480 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004481 return !ActivityManager.isRunningInTestHarness() &&
4482 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004483 }
4484
Adam Cohen4a9423d2014-03-28 14:22:31 -07004485 protected boolean hasRunFirstRunActivity() {
4486 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4487 }
4488
Adam Cohen432609a2014-03-13 17:03:22 -07004489 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004490 if (shouldRunFirstRunActivity() &&
4491 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004492 Intent firstRunIntent = getFirstRunActivity();
4493 if (firstRunIntent != null) {
4494 startActivity(firstRunIntent);
4495 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004496 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004497 }
4498 }
Adam Cohen432609a2014-03-13 17:03:22 -07004499 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004500 }
4501
4502 private void markFirstRunActivityShown() {
4503 SharedPreferences.Editor editor = mSharedPrefs.edit();
4504 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4505 editor.apply();
4506 }
4507
Adam Cohen432609a2014-03-13 17:03:22 -07004508 /**
4509 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4510 * screen that must be displayed and dismissed.
4511 */
4512 protected boolean hasDismissableIntroScreen() {
4513 return false;
4514 }
4515
4516 /**
4517 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4518 */
4519 protected View getIntroScreen() {
4520 return null;
4521 }
4522
4523 /**
4524 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4525 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4526 */
4527 private boolean shouldShowIntroScreen() {
4528 return hasDismissableIntroScreen() &&
4529 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4530 }
4531
4532 protected void showIntroScreen() {
4533 View introScreen = getIntroScreen();
4534 changeWallpaperVisiblity(false);
4535 if (introScreen != null) {
4536 mDragLayer.showOverlayView(introScreen);
4537 }
4538 }
4539
4540 public void dismissIntroScreen() {
4541 markIntroScreenDismissed();
4542 if (showFirstRunActivity()) {
4543 // We delay hiding the intro view until the first run activity is showing. This
4544 // avoids a blip.
4545 mWorkspace.postDelayed(new Runnable() {
4546 @Override
4547 public void run() {
4548 mDragLayer.dismissOverlayView();
4549 }
4550 }, ACTIVITY_START_DELAY);
4551 } else {
4552 mDragLayer.dismissOverlayView();
4553 }
4554 changeWallpaperVisiblity(true);
4555 }
4556
4557 private void markIntroScreenDismissed() {
4558 SharedPreferences.Editor editor = mSharedPrefs.edit();
4559 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4560 editor.apply();
4561 }
4562
Winson Chunga6945242014-01-08 14:04:34 -08004563 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004564 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4565 if (mHotseat != null) mHotseat.setAlpha(1f);
4566 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4567 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004568 }
4569
4570 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004571 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4572 if (mHotseat != null) mHotseat.setAlpha(0f);
4573 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4574 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004575 }
4576
Mathew Inwood72fbec12013-11-19 15:45:07 +00004577 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
4578 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
4579 if (ri == null) {
4580 return null;
4581 }
4582 return new AppInfo(getPackageManager(), ri, mIconCache, null);
4583 }
4584
4585 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4586 Bitmap icon) {
4587 return new ShortcutInfo(shortcutIntent, caption, icon);
4588 }
4589
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004590 protected void moveWorkspaceToDefaultScreen() {
4591 mWorkspace.moveToDefaultScreen(false);
4592 }
4593
Mathew Inwood72fbec12013-11-19 15:45:07 +00004594 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4595 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004596 mWorkspace.onExternalDragStartedWithItem(dragView);
4597 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004598 }
4599
Anjali Koppalf5d29132014-02-28 13:33:27 -08004600 @Override
4601 public void onPageSwitch(View newPage, int newPageIndex) {
4602 }
4603
Winson Chung80baf5a2010-08-09 16:03:15 -07004604 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004605 * Prints out out state for debugging.
4606 */
4607 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004608 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004609 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004610 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4611 Log.d(TAG, "mRestoring=" + mRestoring);
4612 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4613 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004614 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004615 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004616
Winson Chung785d2eb2011-04-14 16:08:02 -07004617 if (mAppsCustomizeContent != null) {
4618 mAppsCustomizeContent.dumpState();
4619 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004620 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004621 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004622
4623 @Override
4624 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4625 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004626 synchronized (sDumpLogs) {
4627 writer.println(" ");
4628 writer.println("Debug logs: ");
4629 for (int i = 0; i < sDumpLogs.size(); i++) {
4630 writer.println(" " + sDumpLogs.get(i));
4631 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004632 }
4633 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004634
4635 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004636 if (DEBUG_DUMP_LOG) {
4637 synchronized (sDumpLogs) {
4638 Log.d(TAG, "");
4639 Log.d(TAG, "*********************");
4640 Log.d(TAG, "Launcher debug logs: ");
4641 for (int i = 0; i < sDumpLogs.size(); i++) {
4642 Log.d(TAG, " " + sDumpLogs.get(i));
4643 }
4644 Log.d(TAG, "*********************");
4645 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004646 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004647 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004648 }
4649
4650 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004651 addDumpLog(tag, log, null, debugLog);
4652 }
4653
4654 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004655 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004656 if (e != null) {
4657 Log.d(tag, log, e);
4658 } else {
4659 Log.d(tag, log);
4660 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004661 }
Winson Chungede41292013-09-19 16:27:36 -07004662 if (DEBUG_DUMP_LOG) {
4663 sDateStamp.setTime(System.currentTimeMillis());
4664 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004665 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4666 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004667 }
Winson Chungede41292013-09-19 16:27:36 -07004668 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004669 }
4670
Winson Chungede41292013-09-19 16:27:36 -07004671 public void dumpLogsToLocalData() {
4672 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004673 new AsyncTask<Void, Void, Void>() {
4674 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004675 boolean success = false;
4676 sDateStamp.setTime(sRunStart);
4677 String FILENAME = sDateStamp.getMonth() + "-"
4678 + sDateStamp.getDay() + "_"
4679 + sDateStamp.getHours() + "-"
4680 + sDateStamp.getMinutes() + "_"
4681 + sDateStamp.getSeconds() + ".txt";
4682
4683 FileOutputStream fos = null;
4684 File outFile = null;
4685 try {
4686 outFile = new File(getFilesDir(), FILENAME);
4687 outFile.createNewFile();
4688 fos = new FileOutputStream(outFile);
4689 } catch (Exception e) {
4690 e.printStackTrace();
4691 }
4692 if (fos != null) {
4693 PrintWriter writer = new PrintWriter(fos);
4694
4695 writer.println(" ");
4696 writer.println("Debug logs: ");
4697 synchronized (sDumpLogs) {
4698 for (int i = 0; i < sDumpLogs.size(); i++) {
4699 writer.println(" " + sDumpLogs.get(i));
4700 }
4701 }
4702 writer.close();
4703 }
4704 try {
4705 if (fos != null) {
4706 fos.close();
4707 success = true;
4708 }
4709 } catch (IOException e) {
4710 e.printStackTrace();
4711 }
Michael Jurka43467462013-11-14 12:03:58 +01004712 return null;
Winson Chungede41292013-09-19 16:27:36 -07004713 }
Michael Jurka43467462013-11-14 12:03:58 +01004714 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004715 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004716 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004717}
Michael Jurka2763be32011-02-24 11:19:57 -08004718
Michael Jurkaabded662011-03-04 12:06:57 -08004719interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004720 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004721 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004722 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004723 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004724 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004725}
Dan Sandlerd5024042014-01-09 15:01:33 -05004726
4727interface DebugIntents {
4728 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4729 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004730}