blob: 734c7285ea144a34f37cf1149aa0d6a19f89dc43 [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;
Adam Cohen2854d252014-08-27 16:04:07 -070025import android.animation.TimeInterpolator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070026import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000027import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070029import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070030import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040031import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040042import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070045import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070046import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070047import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080048import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070050import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070052import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
Adam Cohen3f9c9712014-10-31 11:48:25 -070054import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.Bitmap;
56import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070057import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070058import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070060import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040061import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070062import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020063import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020065import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080066import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070067import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070068import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040069import android.os.SystemClock;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
76import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
79import android.view.LayoutInflater;
80import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070081import android.view.MotionEvent;
82import android.view.Surface;
83import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen2854d252014-08-27 16:04:07 -070086import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070088import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.ViewTreeObserver;
Sunny Goyal651077b2014-06-30 14:15:31 -070090import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080092import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070093import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080094import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070096import android.widget.Advanceable;
97import android.widget.FrameLayout;
98import android.widget.ImageView;
Adam Cohen96d30a12013-07-16 18:13:21 -070099import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700100
Sunny Goyal651077b2014-06-30 14:15:31 -0700101import com.android.launcher3.DropTarget.DragObject;
102import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700103import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100104import com.android.launcher3.compat.LauncherActivityInfoCompat;
105import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700106import com.android.launcher3.compat.PackageInstallerCompat;
107import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100108import com.android.launcher3.compat.UserHandleCompat;
109import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700110
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.DataInputStream;
112import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700114import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700118import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000119import java.lang.reflect.Field;
120import java.lang.reflect.InvocationTargetException;
121import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700122import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700124import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700127import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700128import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000129import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131/**
132 * Default launcher application.
133 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100134public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700135 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700136 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800137 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700138 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Daniel Sandlerf061f822013-06-27 13:59:36 -0400140 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400141 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700142 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400143 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700144 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700145
Dan Sandlerd5024042014-01-09 15:01:33 -0500146 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
147
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700149 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700152 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Michael Jurka8b805b12012-04-18 14:23:14 -0700154 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700155 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700156
Mathew Inwood876a8462013-06-14 14:12:41 +0100157 /**
158 * IntentStarter uses request codes starting with this. This must be greater than all activity
159 * request codes used internally.
160 */
161 protected static final int REQUEST_LAST = 100;
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
164
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800165 static final int SCREEN_COUNT = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Michael Jurka0a457bf2012-11-19 14:05:05 -0800167 // To turn on these properties, type
168 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800169 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800170 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171
Winson Chung2672ff92012-05-04 16:22:30 -0700172 // The Intent extra that defines whether to ignore the launch animation
173 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400174 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700175
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: int
177 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700178 // Type: int
179 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700181 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
182 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
184 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700185 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 // Type: boolean
189 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
190 // Type: long
191 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700192 // Type: int
193 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
196 // Type: parcelable
197 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000198 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: int[]
201 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
Adam Cohen432609a2014-03-13 17:03:22 -0700203 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800204 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
205
Adam Cohen3ed316a2014-07-23 18:21:20 -0700206 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
207 static final String ACTION_FIRST_LOAD_COMPLETE =
208 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
209
Adam Cohen39a06042013-07-19 14:30:12 -0700210 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700211 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700212
Sunny Goyal594d76d2014-11-06 10:12:54 -0800213 private static final String QSB_WIDGET_ID = "qsb_widget_id";
214 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
215
Winson Chunga6945242014-01-08 14:04:34 -0800216 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
217
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700218 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700219 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700220 private State mState = State.WORKSPACE;
221 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700222
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700223 private boolean mIsSafeModeEnabled;
224
Adam Cohenc2d6e892014-10-16 09:49:24 -0700225 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
226 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700227 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700228
Joe Onorato9c1289c2009-08-17 11:03:03 -0400229 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700230 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
231 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700232 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private static final Object sLock = new Object();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000236 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
237 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
238
Winson Chunga2413752012-04-03 14:22:34 -0700239 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700240 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
241 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700242 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700243 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700244
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800245 private final BroadcastReceiver mCloseSystemDialogsReceiver
246 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800247 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private LayoutInflater mInflater;
250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700252 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800253 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800254 private DragLayer mDragLayer;
255 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700256 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700257
Sunny Goyalffe83f12014-08-14 17:39:34 -0700258 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
Michael Jurkac9d95c52011-08-29 14:03:34 -0700261 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800262 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800263 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264
Michael Jurka0280c3b2010-09-17 15:00:07 -0700265 private int[] mTmpAddItemCellCoordinates = new int[2];
266
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 private FolderInfo mFolderInfo;
268
Winson Chung3d503fb2011-07-13 17:25:49 -0700269 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800270 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700271
Michael Jurka838a4ca2011-02-07 13:33:06 -0800272 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700273
Winson Chungc51db6a2011-10-05 11:44:49 -0700274 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700275 private AppsCustomizeTabHost mAppsCustomizeTabHost;
276 private AppsCustomizePagedView mAppsCustomizeContent;
277 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800278 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700281 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
282 // scroll issues (because the workspace may not have been measured yet) and extra work.
283 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
284 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285
286 private SpannableStringBuilder mDefaultKeySsb = null;
287
Joe Onorato9c1289c2009-08-17 11:03:03 -0400288 private boolean mWorkspaceLoading = true;
289
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800290 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 private boolean mRestoring;
292 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700293 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294
Michael Jurka1e2f4652013-07-08 18:03:46 -0700295 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700296 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
297
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298 private Bundle mSavedInstanceState;
299
Joe Onorato9c1289c2009-08-17 11:03:03 -0400300 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800301 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800302 private boolean mUserPresent = true;
303 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700304 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400306
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700307 private static LocaleConfiguration sLocaleConfiguration = null;
308
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700309 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700310
Adam Cohen61f560d2013-09-30 15:58:20 -0700311 private View.OnTouchListener mHapticFeedbackTouchListener;
312
Adam Cohen80e6beb2015-02-13 16:14:33 -0800313 public static final int BUILD_LAYER = 0;
314 public static final int BUILD_AND_SET_LAYER = 1;
315
Adam Cohended9f8d2010-11-03 13:25:16 -0700316 // Related to the auto-advancing of widgets
317 private final int ADVANCE_MSG = 1;
318 private final int mAdvanceInterval = 20000;
319 private final int mAdvanceStagger = 250;
320 private long mAutoAdvanceSentTime;
321 private long mAutoAdvanceTimeLeft = -1;
322 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
323 new HashMap<View, AppWidgetProviderInfo>();
324
Winson Chung400438b2011-01-16 17:53:48 -0800325 // Determines how long to wait after a rotation before restoring the screen orientation to
326 // match the sensor state.
327 private final int mRestoreScreenOrientationDelay = 500;
328
Craig Mautner360310b2012-10-26 15:13:08 -0700329 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700330
Adam Cohen1462de32012-07-24 22:34:36 -0700331 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700332 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700333
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700334 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700335 static Date sDateStamp = new Date();
336 static DateFormat sDateFormat =
337 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
338 static long sRunStart = System.currentTimeMillis();
339 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700340
Winson Chung46353de2012-02-16 14:05:10 -0800341 // We only want to get the SharedPreferences once since it does an FS stat each time we get
342 // it from the context.
343 private SharedPreferences mSharedPrefs;
344
Adam Cohene25af792013-06-06 23:08:25 -0700345 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
346
Winson Chungf0c6ae02012-03-21 16:10:31 -0700347 // Holds the page that we need to animate to, and the icon views that we need to animate up
348 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700349 private ImageView mFolderIconImageView;
350 private Bitmap mFolderIconBitmap;
351 private Canvas mFolderIconCanvas;
352 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700353
Michael Jurkaddd62e92011-02-16 17:49:14 -0800354 private BubbleTextView mWaitingForResume;
355
Adam Cohen59400422014-03-05 18:07:04 -0800356 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
357 new HashMap<String, CustomAppWidget>();
358
359 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
360 static {
361 if (ENABLE_CUSTOM_WIDGET_TEST) {
362 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
363 }
364 }
365
Michael Jurkac1f5d262011-09-30 19:32:27 -0700366 private Runnable mBuildLayersRunnable = new Runnable() {
367 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700368 if (mWorkspace != null) {
369 mWorkspace.buildPageHardwareLayers();
370 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700371 }
372 };
373
Adam Cohendb364c32014-05-20 14:23:40 -0700374 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375
376 private static class PendingAddArguments {
377 int requestCode;
378 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700379 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700380 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800381 int cellX;
382 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700383 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800384 }
385
Daniel Sandlerff02d492013-08-05 02:12:05 -0400386 private Stats mStats;
387
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700388 FocusIndicatorView mFocusHandler;
389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 @Override
391 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700392 if (DEBUG_STRICT_MODE) {
393 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
394 .detectDiskReads()
395 .detectDiskWrites()
396 .detectNetwork() // or .detectAll() for all detectable problems
397 .penaltyLog()
398 .build());
399 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
400 .detectLeakedSqlLiteObjects()
401 .detectLeakedClosableObjects()
402 .penaltyLog()
403 .penaltyDeath()
404 .build());
405 }
406
Adam Cohen9211d422014-10-07 18:14:53 -0700407 if (mLauncherCallbacks != null) {
408 mLauncherCallbacks.preOnCreate();
409 }
410
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800411 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400412
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400413 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400414 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700415 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700416
Winson Chung5f8afe62013-08-12 16:19:28 -0700417 // Lazy-initialize the dynamic grid
Sunny Goyal33d44382014-10-16 09:24:19 -0700418 DeviceProfile grid = app.initDynamicGrid(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700419
420 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400421 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700422 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700423 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800424 mModel = app.setLauncher(this);
425 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700426 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400427 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Daniel Sandlerff02d492013-08-05 02:12:05 -0400430 mStats = new Stats(this);
431
Sunny Goyalffe83f12014-08-14 17:39:34 -0700432 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700433
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700434 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
435 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700436
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700437 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
438 // this also ensures that any synchronous binding below doesn't re-trigger another
439 // LauncherModel load.
440 mPaused = false;
441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200443 android.os.Debug.startMethodTracing(
444 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 }
446
447 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100451 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800453 registerContentObservers();
454
Joe Onorato7c312c12009-08-13 21:36:53 -0700455 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 mSavedState = savedInstanceState;
458 restoreState(mSavedState);
459
460 if (PROFILE_STARTUP) {
461 android.os.Debug.stopMethodTracing();
462 }
463
464 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700465 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 // If the user leaves launcher, then we should just load items asynchronously when
467 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500468 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 } else {
470 // We only load the page synchronously if the user rotates (or triggers a
471 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800472 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 }
475
476 // For handling default keys
477 mDefaultKeySsb = new SpannableStringBuilder();
478 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800479
480 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
481 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800482
Adam Cohenf9426d52012-06-04 17:26:21 -0700483 // 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 Cohen9211d422014-10-07 18:14:53 -0700486 if (mLauncherCallbacks != null) {
487 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700488 if (mLauncherCallbacks.hasLauncherOverlay()) {
489 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700490 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
491 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
492 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700493 mWorkspace.setLauncherOverlay(mLauncherOverlay);
494 }
Adam Cohen9211d422014-10-07 18:14:53 -0700495 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700496
497 if (shouldShowIntroScreen()) {
498 showIntroScreen();
499 } else {
500 showFirstRunActivity();
501 showFirstRunClings();
502 }
Adam Cohen9211d422014-10-07 18:14:53 -0700503 }
504
505 private LauncherCallbacks mLauncherCallbacks;
506
507 public void onPostCreate(Bundle savedInstanceState) {
508 super.onPostCreate(savedInstanceState);
509 if (mLauncherCallbacks != null) {
510 mLauncherCallbacks.onPostCreate(savedInstanceState);
511 }
512 }
513
514 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
515 mLauncherCallbacks = callbacks;
516 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700517 }
518
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700519 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700520 public void onLauncherProviderChange() {
521 if (mLauncherCallbacks != null) {
522 mLauncherCallbacks.onLauncherProviderChange();
523 }
524 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700525
Adam Cohen9211d422014-10-07 18:14:53 -0700526 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700527 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700528 if (mLauncherCallbacks != null) {
529 return mLauncherCallbacks.hasCustomContentToLeft();
530 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700531 return false;
532 }
533
Dave Hawkeya8881582013-09-17 15:55:33 -0600534 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500535 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 * {@link #addToCustomContentPage}. This will only be invoked if
537 * {@link #hasCustomContentToLeft()} is {@code true}.
538 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500539 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700540 if (mLauncherCallbacks != null) {
541 mLauncherCallbacks.populateCustomContentContainer();
542 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600543 }
544
545 /**
546 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
547 * ensure the custom content page is added or removed if necessary.
548 */
549 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600550 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600551 // Not bound yet, wait for bindScreens to be called.
552 return;
553 }
554
555 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
556 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500557 mWorkspace.createCustomContentContainer();
558 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600559 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
560 mWorkspace.removeCustomContentPage();
561 }
562 }
563
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 if (sLocaleConfiguration == null) {
566 new AsyncTask<Void, Void, LocaleConfiguration>() {
567 @Override
568 protected LocaleConfiguration doInBackground(Void... unused) {
569 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
570 readConfiguration(Launcher.this, localeConfiguration);
571 return localeConfiguration;
572 }
573
574 @Override
575 protected void onPostExecute(LocaleConfiguration result) {
576 sLocaleConfiguration = result;
577 checkForLocaleChange(); // recursive, but now with a locale configuration
578 }
579 }.execute();
580 return;
581 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700582
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 final Configuration configuration = getResources().getConfiguration();
584
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 final String locale = configuration.locale.toString();
587
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 final int mcc = configuration.mcc;
590
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700591 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 final int mnc = configuration.mnc;
593
Romain Guy84f296c2009-11-04 15:00:44 -0800594 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800595
Romain Guy84f296c2009-11-04 15:00:44 -0800596 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700597 sLocaleConfiguration.locale = locale;
598 sLocaleConfiguration.mcc = mcc;
599 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700600
Joe Onorato0589f0f2010-02-08 13:44:00 -0800601 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602
603 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100604 new AsyncTask<Void, Void, Void>() {
605 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100607 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 }
Michael Jurka43467462013-11-14 12:03:58 +0100609 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700610 }
611 }
612
613 private static class LocaleConfiguration {
614 public String locale;
615 public int mcc = -1;
616 public int mnc = -1;
617 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700618
Romain Guy98d01652009-06-30 16:21:04 -0700619 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
620 DataInputStream in = null;
621 try {
Helena Josol28db2802014-10-09 17:04:09 +0100622 in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
Romain Guy98d01652009-06-30 16:21:04 -0700623 configuration.locale = in.readUTF();
624 configuration.mcc = in.readInt();
625 configuration.mnc = in.readInt();
626 } catch (FileNotFoundException e) {
627 // Ignore
628 } catch (IOException e) {
629 // Ignore
630 } finally {
631 if (in != null) {
632 try {
633 in.close();
634 } catch (IOException e) {
635 // Ignore
636 }
637 }
638 }
639 }
640
641 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
642 DataOutputStream out = null;
643 try {
Helena Josol4fbbb3e2014-10-06 16:06:46 +0100644 out = new DataOutputStream(context.openFileOutput(
Helena Josol28db2802014-10-09 17:04:09 +0100645 LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
Romain Guy98d01652009-06-30 16:21:04 -0700646 out.writeUTF(configuration.locale);
647 out.writeInt(configuration.mcc);
648 out.writeInt(configuration.mnc);
649 out.flush();
650 } catch (FileNotFoundException e) {
651 // Ignore
652 } catch (IOException e) {
653 //noinspection ResultOfMethodCallIgnored
Helena Josol28db2802014-10-09 17:04:09 +0100654 context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
Romain Guy98d01652009-06-30 16:21:04 -0700655 } finally {
656 if (out != null) {
657 try {
658 out.close();
659 } catch (IOException e) {
660 // Ignore
661 }
662 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 }
664 }
665
Anton Hanssona2f665f2013-09-26 12:18:32 +0100666 public Stats getStats() {
667 return mStats;
668 }
669
Bjorn Bringertc459e522013-06-07 19:36:01 +0100670 public LayoutInflater getInflater() {
671 return mInflater;
672 }
673
Winson Chung36a62fe2012-05-06 18:04:42 -0700674 boolean isDraggingEnabled() {
675 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
676 // that is subsequently removed from the workspace in startBinding().
677 return !mModel.isLoadingWorkspace();
678 }
679
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800680 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000681 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100682 if (Build.VERSION.SDK_INT >= 17) {
683 return View.generateViewId();
684 } else {
685 // View.generateViewId() is not available. The following fallback logic is a copy
686 // of its implementation.
687 for (;;) {
688 final int result = sNextGeneratedId.get();
689 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
690 int newValue = result + 1;
691 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
692 if (sNextGeneratedId.compareAndSet(result, newValue)) {
693 return result;
694 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000695 }
696 }
697 }
698
699 public int getViewIdForItem(ItemInfo info) {
700 // This cast is safe given the > 2B range for int.
701 int itemId = (int) info.id;
702 if (mItemIdToViewId.containsKey(itemId)) {
703 return mItemIdToViewId.get(itemId);
704 }
705 int viewId = generateViewId();
706 mItemIdToViewId.put(itemId, viewId);
707 return viewId;
708 }
709
710 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700711 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
712 * a configuration step, this allows the proper animations to run after other transitions.
713 */
Adam Cohendb364c32014-05-20 14:23:40 -0700714 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700715 long screenId = args.screenId;
716 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
717 // When the screen id represents an actual screen (as opposed to a rank) we make sure
718 // that the drop page actually exists.
719 screenId = ensurePendingDropLayoutExists(args.screenId);
720 }
Adam Cohendb364c32014-05-20 14:23:40 -0700721
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800722 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800723 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700724 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700725 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700726 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800727 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700728 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700729 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700730 case REQUEST_RECONFIGURE_APPWIDGET:
731 completeRestoreAppWidget(args.appWidgetId);
732 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800733 }
Michael Jurka27614d22012-04-02 06:40:22 -0700734 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
735 // if you turned the screen off and then back while in All Apps, Launcher would not
736 // return to the workspace. Clearing mAddInfo.container here fixes this issue
737 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700738 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 }
740
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800741 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700742 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700743 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700744 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700745 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800746 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700747
Adam Cohenad4e15c2013-10-17 16:21:35 -0700748 Runnable exitSpringLoaded = new Runnable() {
749 @Override
750 public void run() {
751 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
752 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
753 }
754 };
755
Michael Jurka8b805b12012-04-18 14:23:14 -0700756 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700757 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700758 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
759 if (resultCode == RESULT_CANCELED) {
760 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700761 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700762 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700763 } else if (resultCode == RESULT_OK) {
Sunny Goyal8f9a7872015-01-16 16:14:29 -0800764 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700765 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 }
767 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200768 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
769 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
770 mWorkspace.exitOverviewMode(false);
771 }
772 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700773 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200774
Adam Cohened66b2b2012-01-23 17:28:51 -0800775 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
776 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700777
Adam Cohendb364c32014-05-20 14:23:40 -0700778 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 // We have special handling for widgets
780 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800781 final int appWidgetId;
782 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
783 : -1;
784 if (widgetId < 0) {
785 appWidgetId = pendingAddWidgetId;
786 } else {
787 appWidgetId = widgetId;
788 }
789
Adam Cohenad4e15c2013-10-17 16:21:35 -0700790 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800791 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700792 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
793 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700794 result = RESULT_CANCELED;
795 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700796 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700797 @Override
798 public void run() {
799 exitSpringLoadedDragModeDelayed(false, 0, null);
800 }
801 };
Adam Cohendb364c32014-05-20 14:23:40 -0700802 if (workspaceLocked) {
803 // No need to remove the empty screen if we're mid-binding, as the
804 // the bind will not add the empty screen.
805 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
806 } else {
807 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
808 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
809 }
Winson Chung5aaab772012-04-27 15:24:02 -0700810 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700811 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700812 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
813 // When the screen id represents an actual screen (as opposed to a rank)
814 // we make sure that the drop page actually exists.
815 mPendingAddInfo.screenId =
816 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
817 }
Adam Cohendb364c32014-05-20 14:23:40 -0700818 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
819
820 dropLayout.setDropPending(true);
821 final Runnable onComplete = new Runnable() {
822 @Override
823 public void run() {
824 completeTwoStageWidgetDrop(resultCode, appWidgetId);
825 dropLayout.setDropPending(false);
826 }
827 };
828 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
829 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
830 } else {
831 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
832 mPendingAddInfo);
833 sPendingAddItem = args;
834 }
Winson Chung5aaab772012-04-27 15:24:02 -0700835 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800836 return;
837 }
838
Sunny Goyalff572272014-07-23 13:58:07 -0700839 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
840 if (resultCode == RESULT_OK) {
841 // Update the widget view.
842 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
843 pendingAddWidgetId, mPendingAddInfo);
844 if (workspaceLocked) {
845 sPendingAddItem = args;
846 } else {
847 completeAdd(args);
848 }
849 }
850 // Leave the widget in the pending state if the user canceled the configure.
851 return;
852 }
853
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 // The pattern used here is that a user PICKs a specific application,
855 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700856
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
858 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700859 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700860 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
861 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800862 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700863 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800864 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700865 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700866 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
867 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 }
Adam Cohen00074722013-10-11 17:46:09 -0700869 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700870 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700871 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800874
875 }
876
877 @Override
878 protected void onActivityResult(
879 final int requestCode, final int resultCode, final Intent data) {
880 handleActivityResult(requestCode, resultCode, data);
881 if (mLauncherCallbacks != null) {
882 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
883 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 }
885
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600886 /** @Override for MNC */
887 protected void onRequestPermissionsResult(int requestCode, String[] permissions,
888 int[] grantResults) {
889 if (mLauncherCallbacks != null) {
890 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
891 grantResults);
892 }
893 }
894
Adam Cohendb364c32014-05-20 14:23:40 -0700895 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
896 appWidgetId, ItemInfo info) {
897 PendingAddArguments args = new PendingAddArguments();
898 args.requestCode = requestCode;
899 args.intent = data;
900 args.container = info.container;
901 args.screenId = info.screenId;
902 args.cellX = info.cellX;
903 args.cellY = info.cellY;
904 args.appWidgetId = appWidgetId;
905 return args;
906 }
907
908 /**
909 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
910 *
911 * @param screenId the screen id to check
912 * @return the new screen, or screenId if it exists
913 */
914 private long ensurePendingDropLayoutExists(long screenId) {
915 CellLayout dropLayout =
916 (CellLayout) mWorkspace.getScreenWithId(screenId);
917 if (dropLayout == null) {
918 // it's possible that the add screen was removed because it was
919 // empty and a re-bind occurred
920 mWorkspace.addExtraEmptyScreen();
921 return mWorkspace.commitExtraEmptyScreen();
922 } else {
923 return screenId;
924 }
925 }
926
Adam Cohened66b2b2012-01-23 17:28:51 -0800927 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700928 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700929 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 Runnable onCompleteRunnable = null;
931 int animationType = 0;
932
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700933 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800934 if (resultCode == RESULT_OK) {
935 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
936 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700937 mPendingAddWidgetInfo);
938 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800939 onCompleteRunnable = new Runnable() {
940 @Override
941 public void run() {
942 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700943 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700944 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
945 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800946 }
947 };
948 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800949 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800950 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800951 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700952 if (mDragLayer.getAnimatedView() != null) {
953 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
954 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
955 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700956 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700957 // The animated view may be null in the case of a rotation during widget configuration
958 onCompleteRunnable.run();
959 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 }
961
962 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700963 protected void onStop() {
964 super.onStop();
965 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700966
967 if (mLauncherCallbacks != null) {
968 mLauncherCallbacks.onStop();
969 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700970 }
971
972 @Override
973 protected void onStart() {
974 super.onStart();
975 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700976
977 if (mLauncherCallbacks != null) {
978 mLauncherCallbacks.onStart();
979 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700980 }
981
982 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800983 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200984 long startTime = 0;
985 if (DEBUG_RESUME_TIME) {
986 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400987 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200988 }
Adam Cohen9211d422014-10-07 18:14:53 -0700989
990 if (mLauncherCallbacks != null) {
991 mLauncherCallbacks.preOnResume();
992 }
993
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800994 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700995
Winson Chung4a2afa32012-07-19 14:53:05 -0700996 // Restore the previous launcher state
997 if (mOnResumeState == State.WORKSPACE) {
998 showWorkspace(false);
999 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -08001000 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001001 }
1002 mOnResumeState = State.NONE;
1003
Craig Mautner360310b2012-10-26 15:13:08 -07001004 // Background was set to gradient in onPause(), restore to black if in all apps.
1005 setWorkspaceBackground(mState == State.WORKSPACE);
1006
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001007 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001008 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001009 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -05001010 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001011 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001012 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001013 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001014 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001015 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1016 // execute them here
1017 long startTimeCallbacks = 0;
1018 if (DEBUG_RESUME_TIME) {
1019 startTimeCallbacks = System.currentTimeMillis();
1020 }
1021
1022 if (mAppsCustomizeContent != null) {
1023 mAppsCustomizeContent.setBulkBind(true);
1024 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001025 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1026 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001027 }
1028 if (mAppsCustomizeContent != null) {
1029 mAppsCustomizeContent.setBulkBind(false);
1030 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001031 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001032 if (DEBUG_RESUME_TIME) {
1033 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1034 (System.currentTimeMillis() - startTimeCallbacks));
1035 }
Michael Jurka447bf842013-05-15 14:52:15 +02001036 }
Michael Jurka54554252013-08-01 12:52:23 +02001037 if (mOnResumeCallbacks.size() > 0) {
1038 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1039 mOnResumeCallbacks.get(i).run();
1040 }
1041 mOnResumeCallbacks.clear();
1042 }
Winson Chunge4e50662012-01-23 14:45:13 -08001043
1044 // Reset the pressed state of icons that were locked in the press state while activities
1045 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001046 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001047 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001048 mWaitingForResume.setStayPressed(false);
1049 }
Winson Chung82963d52013-10-09 11:20:57 -07001050
Adam Cohen06dff352012-06-01 17:17:08 -07001051 // It is possible that widgets can receive updates while launcher is not in the foreground.
1052 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1053 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1054 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001055 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001056
Winson Chung780fe592013-09-26 14:48:44 -07001057 // Process any items that were added while Launcher was away.
1058 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1059
Michael Jurka447bf842013-05-15 14:52:15 +02001060 if (DEBUG_RESUME_TIME) {
1061 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1062 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001063
1064 if (mWorkspace.getCustomContentCallbacks() != null) {
1065 // If we are resuming and the custom content is the current page, we call onShow().
1066 // It is also poassible that onShow will instead be called slightly after first layout
1067 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1068 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001069 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001070 }
1071 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001072 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001073 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001074
1075 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen9211d422014-10-07 18:14:53 -07001076
1077 if (mLauncherCallbacks != null) {
1078 mLauncherCallbacks.onResume();
1079 }
Adam Cohen06dff352012-06-01 17:17:08 -07001080 }
1081
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001083 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001084 // Ensure that items added to Launcher are queued until Launcher returns
1085 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001086 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001087
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001088 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001089 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001090 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001091 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001092
1093 // We call onHide() aggressively. The custom content callbacks should be able to
1094 // debounce excess onHide calls.
1095 if (mWorkspace.getCustomContentCallbacks() != null) {
1096 mWorkspace.getCustomContentCallbacks().onHide();
1097 }
Romain Guycbb89e42009-06-08 15:52:54 -07001098
Adam Cohen9211d422014-10-07 18:14:53 -07001099 if (mLauncherCallbacks != null) {
1100 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001101 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001102 }
1103
1104 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001105 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1106 // by a onResume or by scrolling otherwise.
1107 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001108
1109 // Custom content is completely hidden
1110 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001111
1112 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1113 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001114
1115 // Indicates whether the user is allowed to scroll away from the custom content.
1116 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001117 }
1118
Adam Cohenc2d6e892014-10-16 09:49:24 -07001119 public interface LauncherOverlay {
1120
1121 /**
1122 * Touch interaction leading to overscroll has begun
1123 */
1124 public void onScrollInteractionBegin();
1125
1126 /**
1127 * Touch interaction related to overscroll has ended
1128 */
1129 public void onScrollInteractionEnd();
1130
1131 /**
1132 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1133 * screen (or in the case of RTL, the rightmost screen).
1134 */
1135 public void onScrollChange(int progress, boolean rtl);
1136
1137 /**
1138 * Screen has stopped scrolling
1139 */
1140 public void onScrollSettled();
1141
1142 /**
1143 * This method can be called by the Launcher in order to force the LauncherOverlay
1144 * to exit fully immersive mode.
1145 */
1146 public void forceExitFullImmersion();
1147 }
1148
1149 public interface LauncherOverlayCallbacks {
1150 /**
1151 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1152 * however it doesn't modify any state within the launcher.
1153 */
1154 public boolean canEnterFullImmersion();
1155
1156 /**
1157 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1158 * eg. by occupying the full screen and handling all touch events.
1159 *
1160 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1161 * case, Launcher will modify any necessary state and assumes the overlay is
1162 * handling all interaction. If false, the LauncherOverlay should cancel any
1163 *
1164 */
1165 public boolean enterFullImmersion();
1166
1167 /**
1168 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1169 * full control over UI and state.
1170 */
1171 public void exitFullImmersion();
1172 }
1173
1174 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1175
1176 @Override
1177 public boolean canEnterFullImmersion() {
1178 return mState == State.WORKSPACE;
1179 }
1180
1181 @Override
1182 public boolean enterFullImmersion() {
1183 if (mState == State.WORKSPACE) {
1184 // When fully immersed, disregard any touches which fall through.
1185 mDragLayer.setBlockTouch(true);
1186 return true;
1187 }
1188 return false;
1189 }
1190
1191 @Override
1192 public void exitFullImmersion() {
1193 mDragLayer.setBlockTouch(false);
1194 }
1195 }
1196
Jorim Jaggid017f882014-01-14 17:08:48 -08001197 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001198 if (mLauncherCallbacks != null) {
1199 return mLauncherCallbacks.hasSettings();
1200 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001201 return false;
1202 }
1203
Adam Cohenbffe7452013-07-22 18:21:45 -07001204
Adam Cohen9211d422014-10-07 18:14:53 -07001205 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001206 CustomContentCallbacks callbacks, String description) {
1207 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001208 }
1209
Adam Cohenedb40762013-07-18 16:45:45 -07001210 // The custom content needs to offset its content to account for the QSB
1211 public int getTopOffsetForCustomContent() {
1212 return mWorkspace.getPaddingTop();
1213 }
1214
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001215 @Override
1216 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001217 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001218 if (mModel.isCurrentCallbacks(this)) {
1219 mModel.stopLoader();
1220 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001221 if (mAppsCustomizeContent != null) {
1222 mAppsCustomizeContent.surrender();
1223 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001224 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001225 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001226
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001227 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001228 @Override
1229 public void onWindowFocusChanged(boolean hasFocus) {
1230 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001231 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001232
1233 if (mLauncherCallbacks != null) {
1234 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1235 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001236 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001237
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 private boolean acceptFilter() {
1239 final InputMethodManager inputManager = (InputMethodManager)
1240 getSystemService(Context.INPUT_METHOD_SERVICE);
1241 return !inputManager.isFullscreenMode();
1242 }
1243
1244 @Override
1245 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001246 final int uniChar = event.getUnicodeChar();
1247 final boolean handled = super.onKeyDown(keyCode, event);
1248 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1249 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1251 keyCode, event);
1252 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001253 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001254 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001255 // showSearchDialog()
1256 // If there are multiple keystrokes before the search dialog takes focus,
1257 // onSearchRequested() will be called for every keystroke,
1258 // but it is idempotent, so it's fine.
1259 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 }
1261 }
1262
Joe Onorato8a9625e2010-01-28 15:55:35 -08001263 // Eat the long press event so the keyboard doesn't come up.
1264 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1265 return true;
1266 }
1267
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 return handled;
1269 }
1270
Karl Rosaen138a0412009-04-23 19:00:21 -07001271 private String getTypedText() {
1272 return mDefaultKeySsb.toString();
1273 }
1274
1275 private void clearTypedText() {
1276 mDefaultKeySsb.clear();
1277 mDefaultKeySsb.clearSpans();
1278 Selection.setSelection(mDefaultKeySsb, 0);
1279 }
1280
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001282 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1283 * State
1284 */
1285 private static State intToState(int stateOrdinal) {
1286 State state = State.WORKSPACE;
1287 final State[] stateValues = State.values();
1288 for (int i = 0; i < stateValues.length; i++) {
1289 if (stateValues[i].ordinal() == stateOrdinal) {
1290 state = stateValues[i];
1291 break;
1292 }
1293 }
1294 return state;
1295 }
1296
1297 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 * Restores the previous state, if it exists.
1299 *
1300 * @param savedState The previous state.
1301 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001302 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 private void restoreState(Bundle savedState) {
1304 if (savedState == null) {
1305 return;
1306 }
1307
Michael Jurka883f55b2010-10-21 15:47:14 -07001308 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001309 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001310 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001311 }
1312
Adam Cohen21cd0022013-10-09 18:57:02 -07001313 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1314 PagedView.INVALID_RESTORE_PAGE);
1315 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001316 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 }
1318
Winson Chung3d503fb2011-07-13 17:25:49 -07001319 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001320 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001321
Winson Chung3d503fb2011-07-13 17:25:49 -07001322 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1323 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001324 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001325 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1326 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001327 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1328 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001329 AppWidgetProviderInfo info = savedState.getParcelable(
1330 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyala6095962015-05-12 13:30:07 -07001331 mPendingAddWidgetInfo = info == null ?
1332 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1333
Adam Cohen4637b5a2013-11-04 18:21:24 -08001334 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001335 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336 mRestoring = true;
1337 }
1338
1339 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1340 if (renameFolder) {
1341 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001342 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 mRestoring = true;
1344 }
Winson Chunga12a2502010-12-20 14:41:35 -08001345
Winson Chung785d2eb2011-04-14 16:08:02 -07001346 // Restore the AppsCustomize tab
1347 if (mAppsCustomizeTabHost != null) {
1348 String curTab = savedState.getString("apps_customize_currentTab");
1349 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001350 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001351 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001352 mAppsCustomizeContent.loadAssociatedPages(
1353 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001354 }
1355
Winson Chung5afbf7b2011-07-25 11:53:08 -07001356 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1357 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001358 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001359 mItemIdToViewId = (HashMap<Integer, Integer>)
1360 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 }
1362
1363 /**
1364 * Finds all the views we need and configure them properly.
1365 */
1366 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001367 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001368
Craig Mautner360310b2012-10-26 15:13:08 -07001369 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001370 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001371 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1372 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001373 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001374 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001375
John Spurlock77e1f472013-09-11 10:09:51 -04001376 mLauncherView.setSystemUiVisibility(
1377 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001378 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379
Winson Chung4c98d922011-05-31 16:50:48 -07001380 // Setup the drag layer
1381 mDragLayer.setup(this, dragController);
1382
Winson Chung3d503fb2011-07-13 17:25:49 -07001383 // Setup the hotseat
1384 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1385 if (mHotseat != null) {
1386 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001387 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001388 }
1389
Jorim Jaggid017f882014-01-14 17:08:48 -08001390 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001391 View widgetButton = findViewById(R.id.widget_button);
1392 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001393 @Override
1394 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001395 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001396 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001397 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001398 }
1399 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001400 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1401
1402 View wallpaperButton = findViewById(R.id.wallpaper_button);
1403 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001404 @Override
1405 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001406 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001407 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001408 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001409 }
1410 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001411 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1412
1413 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001414 if (hasSettings()) {
1415 settingsButton.setOnClickListener(new OnClickListener() {
1416 @Override
1417 public void onClick(View arg0) {
1418 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001419 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001420 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001421 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001422 });
1423 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1424 } else {
1425 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001426 }
1427
Adam Cohendbdff6b2013-09-18 19:09:15 -07001428 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001429
Winson Chung4c98d922011-05-31 16:50:48 -07001430 // Setup the workspace
1431 mWorkspace.setHapticFeedbackEnabled(false);
1432 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001433 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001434 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001435
Winson Chungf0ea4d32011-06-06 14:27:16 -07001436 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001437 mSearchDropTargetBar = (SearchDropTargetBar)
1438 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001439
Winson Chungf0ea4d32011-06-06 14:27:16 -07001440 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001441 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001442 mAppsCustomizeContent = (AppsCustomizePagedView)
1443 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1444 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001445
Winson Chung3d503fb2011-07-13 17:25:49 -07001446 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001447 dragController.setDragScoller(mWorkspace);
1448 dragController.setScrollView(mDragLayer);
1449 dragController.setMoveTarget(mWorkspace);
1450 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001451 if (mSearchDropTargetBar != null) {
1452 mSearchDropTargetBar.setup(this, dragController);
Sunny Goyal594d76d2014-11-06 10:12:54 -08001453 mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001454 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001455
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001456 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001457 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001458 mWeightWatcher = new WeightWatcher(this);
1459 mWeightWatcher.setAlpha(0.5f);
1460 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001461 new FrameLayout.LayoutParams(
1462 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001463 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001464 Gravity.BOTTOM)
1465 );
Adam Cohen39a06042013-07-19 14:30:12 -07001466
1467 boolean show = shouldShowWeightWatcher();
1468 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001469 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 }
1471
1472 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001473 * Sets the all apps button. This method is called from {@link Hotseat}.
1474 */
1475 public void setAllAppsButton(View allAppsButton) {
1476 mAllAppsButton = allAppsButton;
1477 }
1478
1479 public View getAllAppsButton() {
1480 return mAllAppsButton;
1481 }
1482
1483 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 * Creates a view representing a shortcut.
1485 *
1486 * @param info The data structure describing the shortcut.
1487 *
1488 * @return A View inflated from R.layout.application.
1489 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001490 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001492 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 }
1494
1495 /**
1496 * Creates a view representing a shortcut inflated from the specified resource.
1497 *
1498 * @param layoutResId The id of the XML layout used to create the shortcut.
1499 * @param parent The group the shortcut belongs to.
1500 * @param info The data structure describing the shortcut.
1501 *
1502 * @return A View inflated from layoutResId.
1503 */
Adam Cohen59400422014-03-05 18:07:04 -08001504 public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001505 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001506 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001508 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 return favorite;
1510 }
1511
1512 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 * Add a shortcut to the workspace.
1514 *
1515 * @param data The intent describing the shortcut.
1516 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001518 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001519 int cellY) {
1520 int[] cellXY = mTmpAddItemCellCoordinates;
1521 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001522 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001523
Michael Jurkad3ef3062010-11-23 16:23:58 -08001524 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001525
Sunny Goyal2350bc92014-10-14 16:42:54 -07001526 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001527 if (info == null) {
1528 return;
1529 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001530 final View view = createShortcut(info);
1531
Adam Cohenfbba09b2011-07-18 21:43:05 -07001532 // First we check if we already know the exact location where we want to add this item.
1533 if (cellX >= 0 && cellY >= 0) {
1534 cellXY[0] = cellX;
1535 cellXY[1] = cellY;
1536 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001537
1538 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001539 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001540 true, null,null)) {
1541 return;
1542 }
1543 DragObject dragObject = new DragObject();
1544 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001545 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1546 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001547 return;
1548 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001549 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001550 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001551 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001552 foundCellSpan = (result != null);
1553 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001554 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001555 }
1556
1557 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001558 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001559 return;
1560 }
1561
Adam Cohendcd297f2013-06-18 13:13:40 -07001562 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563
1564 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001565 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001566 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 }
1568 }
1569
Adam Cohen2f093b62012-04-30 18:59:53 -07001570 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1571 int minHeight) {
1572 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001573 // We want to account for the extra amount of padding that we are adding to the widget
1574 // to ensure that it gets the full amount of space that it has requested
1575 int requiredWidth = minWidth + padding.left + padding.right;
1576 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001577 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001578 }
1579
Adam Cohen2f093b62012-04-30 18:59:53 -07001580 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1581 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001582 }
1583
Adam Cohen2f093b62012-04-30 18:59:53 -07001584 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1585 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001586 }
1587
Adam Cohen2f093b62012-04-30 18:59:53 -07001588 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1589 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001590 }
1591
Adam Cohen2f093b62012-04-30 18:59:53 -07001592 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1593 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001594 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001595 }
1596
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001598 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001600 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 */
Adam Cohen59400422014-03-05 18:07:04 -08001602 private void completeAddAppWidget(int appWidgetId, long container, long screenId,
1603 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1604
1605 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001606 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001607 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1608 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001609 }
Romain Guycbb89e42009-06-08 15:52:54 -07001610
Adam Cohen59400422014-03-05 18:07:04 -08001611 if (appWidgetInfo.isCustomWidget) {
1612 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001613 }
1614
Adam Cohen59400422014-03-05 18:07:04 -08001615 LauncherAppWidgetInfo launcherInfo;
1616 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1617 launcherInfo.spanX = info.spanX;
1618 launcherInfo.spanY = info.spanY;
1619 launcherInfo.minSpanX = info.minSpanX;
1620 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001621 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001622
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001623 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001624 container, screenId, info.cellX, info.cellY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625
1626 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001627 if (hostView == null) {
1628 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001629 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1630 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001631 } else {
1632 // The AppWidgetHostView has already been inflated and instantiated
1633 launcherInfo.hostView = hostView;
1634 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001636 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001637 launcherInfo.notifyWidgetSizeChanged(this);
1638
Adam Cohen59400422014-03-05 18:07:04 -08001639 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1640 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001641
1642 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001643 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001644 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 }
Romain Guycbb89e42009-06-08 15:52:54 -07001646
Adam Cohended9f8d2010-11-03 13:25:16 -07001647 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1648 @Override
1649 public void onReceive(Context context, Intent intent) {
1650 final String action = intent.getAction();
1651 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1652 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001653 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001654 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001655
Winson Chungc100e8e2011-08-09 16:02:43 -07001656 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001657 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001658 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001659 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001660 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001661 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1662 mUserPresent = true;
1663 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001664 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1665 mModel.resetLoadedState(false, true);
1666 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1667 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1668 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1669 mModel.resetLoadedState(false, true);
1670 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1671 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1672 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001673 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1674 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1675 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001676 }
1677 }
1678 };
1679
1680 @Override
1681 public void onAttachedToWindow() {
1682 super.onAttachedToWindow();
1683
1684 // Listen for broadcasts related to user-presence
1685 final IntentFilter filter = new IntentFilter();
1686 filter.addAction(Intent.ACTION_SCREEN_OFF);
1687 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001688 // For handling managed profiles
1689 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1690 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001691 if (ENABLE_DEBUG_INTENTS) {
1692 filter.addAction(DebugIntents.DELETE_DATABASE);
1693 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1694 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001695 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001696 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001697 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001698 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001699 mVisible = true;
1700 }
1701
Adam Cohen0b395352014-06-09 22:54:36 +00001702 /**
1703 * Sets up transparent navigation and status bars in LMP.
1704 * This method is a no-op for other platform versions.
1705 */
1706 @TargetApi(19)
1707 private void setupTransparentSystemBarsForLmp() {
1708 // TODO(sansid): use the APIs directly when compiling against L sdk.
1709 // Currently we use reflection to access the flags and the API to set the transparency
1710 // on the System bars.
Kenny Guyd794a3f2014-09-16 15:17:58 +01001711 if (Utilities.isLmpOrAbove()) {
Adam Cohen0b395352014-06-09 22:54:36 +00001712 try {
1713 getWindow().getAttributes().systemUiVisibility |=
1714 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1715 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1716 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1717 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1718 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1719 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1720 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1721 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1722
1723 Method setStatusBarColorMethod =
1724 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1725 Method setNavigationBarColorMethod =
1726 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1727 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1728 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1729 } catch (NoSuchFieldException e) {
1730 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1731 } catch (NoSuchMethodException ex) {
1732 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1733 } catch (IllegalAccessException e) {
1734 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1735 } catch (IllegalArgumentException e) {
1736 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1737 } catch (InvocationTargetException e) {
1738 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1739 } finally {}
1740 }
1741 }
1742
Adam Cohended9f8d2010-11-03 13:25:16 -07001743 @Override
1744 public void onDetachedFromWindow() {
1745 super.onDetachedFromWindow();
1746 mVisible = false;
1747
Adam Cohend113e0c2010-11-11 10:48:05 -08001748 if (mAttached) {
1749 unregisterReceiver(mReceiver);
1750 mAttached = false;
1751 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001752 updateRunning();
1753 }
1754
1755 public void onWindowVisibilityChanged(int visibility) {
1756 mVisible = visibility == View.VISIBLE;
1757 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001758 // The following code used to be in onResume, but it turns out onResume is called when
1759 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1760 // is a more appropriate event to handle
1761 if (mVisible) {
1762 mAppsCustomizeTabHost.onWindowVisible();
1763 if (!mWorkspaceLoading) {
1764 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001765 // We want to let Launcher draw itself at least once before we force it to build
1766 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001767 // apps is nice and speedy.
1768 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001769 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001770 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001771 if (mStarted) return;
1772 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001773 // We delay the layer building a bit in order to give
1774 // other message processing a time to run. In particular
1775 // this avoids a delay in hiding the IME if it was
1776 // currently shown, because doing that may involve
1777 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001778 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001779 final ViewTreeObserver.OnDrawListener listener = this;
1780 mWorkspace.post(new Runnable() {
1781 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001782 if (mWorkspace != null &&
1783 mWorkspace.getViewTreeObserver() != null) {
1784 mWorkspace.getViewTreeObserver().
1785 removeOnDrawListener(listener);
1786 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001787 }
1788 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001789 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001790 }
1791 });
1792 }
1793 clearTypedText();
1794 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001795 }
1796
1797 private void sendAdvanceMessage(long delay) {
1798 mHandler.removeMessages(ADVANCE_MSG);
1799 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1800 mHandler.sendMessageDelayed(msg, delay);
1801 mAutoAdvanceSentTime = System.currentTimeMillis();
1802 }
1803
1804 private void updateRunning() {
1805 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1806 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1807 mAutoAdvanceRunning = autoAdvanceRunning;
1808 if (autoAdvanceRunning) {
1809 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1810 sendAdvanceMessage(delay);
1811 } else {
1812 if (!mWidgetsToAdvance.isEmpty()) {
1813 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1814 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1815 }
1816 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001817 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 }
1819 }
1820 }
1821
1822 private final Handler mHandler = new Handler() {
1823 @Override
1824 public void handleMessage(Message msg) {
1825 if (msg.what == ADVANCE_MSG) {
1826 int i = 0;
1827 for (View key: mWidgetsToAdvance.keySet()) {
1828 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1829 final int delay = mAdvanceStagger * i;
1830 if (v instanceof Advanceable) {
1831 postDelayed(new Runnable() {
1832 public void run() {
1833 ((Advanceable) v).advance();
1834 }
1835 }, delay);
1836 }
1837 i++;
1838 }
1839 sendAdvanceMessage(mAdvanceInterval);
1840 }
1841 }
1842 };
1843
1844 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001845 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001846 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1847 if (v instanceof Advanceable) {
1848 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001849 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001850 updateRunning();
1851 }
1852 }
1853
1854 void removeWidgetToAutoAdvance(View hostView) {
1855 if (mWidgetsToAdvance.containsKey(hostView)) {
1856 mWidgetsToAdvance.remove(hostView);
1857 updateRunning();
1858 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001859 }
1860
Joe Onorato9c1289c2009-08-17 11:03:03 -04001861 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001862 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001863 launcherInfo.hostView = null;
1864 }
1865
Winson Chung93eef082012-03-23 15:59:27 -07001866 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1867 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1868 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001869 }
1870
Adam Cohen59400422014-03-05 18:07:04 -08001871 public ArrayList<AppInfo> getAllAppsList() {
1872 return mAppsCustomizeContent.getApps();
1873 }
1874
Winson Chunga6945242014-01-08 14:04:34 -08001875 public DragLayer getDragLayer() {
1876 return mDragLayer;
1877 }
1878
1879 public Workspace getWorkspace() {
1880 return mWorkspace;
1881 }
1882
1883 public Hotseat getHotseat() {
1884 return mHotseat;
1885 }
1886
Jorim Jaggid017f882014-01-14 17:08:48 -08001887 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001888 return mOverviewPanel;
1889 }
1890
1891 public SearchDropTargetBar getSearchBar() {
1892 return mSearchDropTargetBar;
1893 }
1894
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001895 public LauncherAppWidgetHost getAppWidgetHost() {
1896 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 }
Romain Guycbb89e42009-06-08 15:52:54 -07001898
Winson Chunga9abd0e2010-10-27 17:18:37 -07001899 public LauncherModel getModel() {
1900 return mModel;
1901 }
1902
Winson Chunga6945242014-01-08 14:04:34 -08001903 protected SharedPreferences getSharedPrefs() {
1904 return mSharedPrefs;
1905 }
1906
Bjorn Bringertc459e522013-06-07 19:36:01 +01001907 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001908 getWindow().closeAllPanels();
1909
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001910 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001911 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001912 }
1913
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 @Override
1915 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001916 long startTime = 0;
1917 if (DEBUG_RESUME_TIME) {
1918 startTime = System.currentTimeMillis();
1919 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 super.onNewIntent(intent);
1921
1922 // Close the menu
1923 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001924 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001925 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001926
Adam Cohened307df2013-10-02 09:37:31 -07001927 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1928 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1929 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001930
Adam Cohen6fecd412013-10-02 17:41:50 -07001931 if (mWorkspace == null) {
1932 // Can be cases where mWorkspace is null, this prevents a NPE
1933 return;
1934 }
1935 Folder openFolder = mWorkspace.getOpenFolder();
1936 // In all these cases, only animate if we're already on home
1937 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001938
1939 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1940 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Adam Cohen6fecd412013-10-02 17:41:50 -07001941 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Cohen9211d422014-10-07 18:14:53 -07001942 openFolder == null && moveToDefaultScreen) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001943 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001944 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001945
Adam Cohen6fecd412013-10-02 17:41:50 -07001946 closeFolder();
1947 exitSpringLoadedDragMode();
1948
1949 // If we are already on home, then just animate back to the workspace,
1950 // otherwise, just wait until onResume to set the state back to Workspace
1951 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001952 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001953 } else {
1954 mOnResumeState = State.WORKSPACE;
1955 }
1956
1957 final View v = getWindow().peekDecorView();
1958 if (v != null && v.getWindowToken() != null) {
1959 InputMethodManager imm = (InputMethodManager)getSystemService(
1960 INPUT_METHOD_SERVICE);
1961 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1962 }
1963
1964 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001965 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001966 mAppsCustomizeTabHost.reset();
1967 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001968
Adam Cohen9211d422014-10-07 18:14:53 -07001969 if (mLauncherCallbacks != null) {
1970 mLauncherCallbacks.onHomeIntent();
1971 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 }
Adam Cohened307df2013-10-02 09:37:31 -07001973
Michael Jurka447bf842013-05-15 14:52:15 +02001974 if (DEBUG_RESUME_TIME) {
1975 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1976 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977
Adam Cohen9211d422014-10-07 18:14:53 -07001978 if (mLauncherCallbacks != null) {
1979 mLauncherCallbacks.onNewIntent(intent);
1980 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001981 }
1982
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001984 public void onRestoreInstanceState(Bundle state) {
1985 super.onRestoreInstanceState(state);
1986 for (int page: mSynchronouslyBoundPages) {
1987 mWorkspace.restoreInstanceStateForChild(page);
1988 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 }
1990
1991 @Override
1992 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001993 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001994 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1995 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001996 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001997 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001998
Michael Jurka883f55b2010-10-21 15:47:14 -07001999 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07002000 // We close any open folder since it will not be re-opened, and we need to make sure
2001 // this state is reflected.
2002 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003
Adam Cohendcd297f2013-06-18 13:13:40 -07002004 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07002005 mWaitingForResult) {
2006 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07002007 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07002008 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2009 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002010 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2011 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2012 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002013 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 }
2015
2016 if (mFolderInfo != null && mWaitingForResult) {
2017 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2018 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2019 }
Michael Jurka946ad472010-07-09 18:05:18 -07002020
Winson Chung785d2eb2011-04-14 16:08:02 -07002021 // Save the current AppsCustomize tab
2022 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08002023 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2024 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07002025 if (currentTabTag != null) {
2026 outState.putString("apps_customize_currentTab", currentTabTag);
2027 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002028 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2029 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002030 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002031 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
Adam Cohen9211d422014-10-07 18:14:53 -07002032
2033 if (mLauncherCallbacks != null) {
2034 mLauncherCallbacks.onSaveInstanceState(outState);
2035 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036 }
2037
2038 @Override
2039 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002041
Winson Chunge7a03942011-08-05 15:05:12 -07002042 // Remove all pending runnables
2043 mHandler.removeMessages(ADVANCE_MSG);
2044 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002045 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002046
Winson Chungcd2b0142011-06-08 16:02:26 -07002047 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002048 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002049
2050 // It's possible to receive onDestroy after a new Launcher activity has
2051 // been created. In this case, don't interfere with the new Launcher.
2052 if (mModel.isCurrentCallbacks(this)) {
2053 mModel.stopLoader();
2054 app.setLauncher(null);
2055 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002056
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002058 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002060 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002062 mAppWidgetHost = null;
2063
2064 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065
2066 TextKeyListener.getInstance().release();
2067
Winson Chung81b52252012-08-27 15:34:29 -07002068 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2069 // to prevent leaking Launcher activities on orientation change.
2070 if (mModel != null) {
2071 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2072 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002073
2074 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002075 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002076
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002077 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002078 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002079 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002080 mWorkspace = null;
2081 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002082
Michael Jurka2ecf9952012-06-18 12:52:28 -07002083 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002084
2085 if (mLauncherCallbacks != null) {
2086 mLauncherCallbacks.onDestroy();
2087 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 }
2089
Adam Cohena9cf38f2011-05-02 15:36:58 -07002090 public DragController getDragController() {
2091 return mDragController;
2092 }
2093
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002094 @Override
2095 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002096 onStartForResult(requestCode);
2097 super.startActivityForResult(intent, requestCode);
2098 }
2099
2100 @Override
2101 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2102 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2103 onStartForResult(requestCode);
2104 try {
2105 super.startIntentSenderForResult(intent, requestCode,
2106 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2107 } catch (IntentSender.SendIntentException e) {
2108 throw new ActivityNotFoundException();
2109 }
2110 }
2111
2112 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002113 if (requestCode >= 0) {
2114 setWaitingForResult(true);
2115 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 }
2117
Winson Chung70d72102011-08-12 11:24:35 -07002118 /**
2119 * Indicates that we want global search for this activity by setting the globalSearch
2120 * argument for {@link #startSearch} to true.
2121 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002122 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002123 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002125
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002126 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002127
Karl Rosaen138a0412009-04-23 19:00:21 -07002128 if (initialQuery == null) {
2129 // Use any text typed in the launcher as the initial query
2130 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002131 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002132 if (appSearchData == null) {
2133 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002134 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 }
Winson Chungadf0c182012-08-23 14:59:07 -07002136 Rect sourceBounds = new Rect();
2137 if (mSearchDropTargetBar != null) {
2138 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2139 }
Romain Guycbb89e42009-06-08 15:52:54 -07002140
Ian Parkinson047036e2014-09-01 15:40:53 +01002141 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002142 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002143 if (clearTextImmediately) {
2144 clearTypedText();
2145 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01002146 }
2147
Ian Parkinson047036e2014-09-01 15:40:53 +01002148 /**
2149 * Start a text search.
2150 *
2151 * @return {@code true} if the search will start immediately, so any further keypresses
2152 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2153 * to buffer keypresses.
2154 */
2155 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002156 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002157 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2158 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2159 sourceBounds);
2160 }
2161
Michael Jurkaa33411c2012-06-14 16:18:21 -07002162 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002163 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002164 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002165 }
2166
2167 /**
2168 * Starts the global search activity. This code is a copied from SearchManager
2169 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002170 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002171 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002172 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002173 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2174 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2175 if (globalSearchActivity == null) {
2176 Log.w(TAG, "No global search activity found.");
2177 return;
2178 }
2179 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2181 intent.setComponent(globalSearchActivity);
2182 // Make sure that we have a Bundle to put source in
2183 if (appSearchData == null) {
2184 appSearchData = new Bundle();
2185 } else {
2186 appSearchData = new Bundle(appSearchData);
2187 }
Adam Cohen9211d422014-10-07 18:14:53 -07002188 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002189 if (!appSearchData.containsKey("source")) {
2190 appSearchData.putString("source", getPackageName());
2191 }
2192 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2193 if (!TextUtils.isEmpty(initialQuery)) {
2194 intent.putExtra(SearchManager.QUERY, initialQuery);
2195 }
2196 if (selectInitialQuery) {
2197 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2198 }
2199 intent.setSourceBounds(sourceBounds);
2200 try {
2201 startActivity(intent);
2202 } catch (ActivityNotFoundException ex) {
2203 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2204 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002205 }
2206
Yura4f93ec62014-02-04 14:15:21 +00002207 public boolean isOnCustomContent() {
2208 return mWorkspace.isOnOrMovingToCustomContent();
2209 }
2210
Winson Chung70d72102011-08-12 11:24:35 -07002211 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002212 public boolean onPrepareOptionsMenu(Menu menu) {
2213 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002214 if (!isOnCustomContent()) {
2215 // Close any open folders
2216 closeFolder();
2217 // Stop resizing any widgets
2218 mWorkspace.exitWidgetResizeMode();
2219 if (!mWorkspace.isInOverviewMode()) {
2220 // Show the overview mode
2221 showOverviewMode(true);
2222 } else {
2223 showWorkspace(true);
2224 }
Winson Chunge0298742014-01-17 12:03:00 -08002225 }
Adam Cohen9211d422014-10-07 18:14:53 -07002226 if (mLauncherCallbacks != null) {
2227 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2228 }
2229
Michael Jurkab94f3f82013-09-11 18:08:54 +02002230 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002231 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002232
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002233 @Override
2234 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002235 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002236 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002237 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002238 }
2239
Joe Onorato9c1289c2009-08-17 11:03:03 -04002240 public boolean isWorkspaceLocked() {
2241 return mWorkspaceLoading || mWaitingForResult;
2242 }
2243
Adam Cohen517a7f52014-03-01 12:12:59 -08002244 public boolean isWorkspaceLoading() {
2245 return mWorkspaceLoading;
2246 }
2247
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002248 private void setWorkspaceLoading(boolean value) {
2249 boolean isLocked = isWorkspaceLocked();
2250 mWorkspaceLoading = value;
2251 if (isLocked != isWorkspaceLocked()) {
2252 onWorkspaceLockedChanged();
2253 }
2254 }
2255
2256 private void setWaitingForResult(boolean value) {
2257 boolean isLocked = isWorkspaceLocked();
2258 mWaitingForResult = value;
2259 if (isLocked != isWorkspaceLocked()) {
2260 onWorkspaceLockedChanged();
2261 }
2262 }
2263
Adam Cohen9211d422014-10-07 18:14:53 -07002264 protected void onWorkspaceLockedChanged() {
2265 if (mLauncherCallbacks != null) {
2266 mLauncherCallbacks.onWorkspaceLockedChanged();
2267 }
2268 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002269
Michael Jurka0280c3b2010-09-17 15:00:07 -07002270 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002271 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002272 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002273 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2274 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002275 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002276 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002277 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002278
Sunny Goyal8f9a7872015-01-16 16:14:29 -08002279 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002280 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Adam Cohenad4e15c2013-10-17 16:21:35 -07002281 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2282 }
2283
Sunny Goyal8f9a7872015-01-16 16:14:29 -08002284 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002285 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2286 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002287 if (appWidgetInfo.configure != null) {
2288 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002289 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002290
Bjorn Bringert7984c942009-12-09 15:38:25 +00002291 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002292 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2293 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2294
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002295 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002296 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002297 Runnable onComplete = new Runnable() {
2298 @Override
2299 public void run() {
2300 // Exit spring loaded mode if necessary after adding the widget
2301 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2302 null);
2303 }
2304 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002305 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002306 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002307 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002308 }
2309 }
Romain Guycbb89e42009-06-08 15:52:54 -07002310
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002311 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002312 // Close any folders that may be open.
2313 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002314 mWorkspace.moveToCustomContentScreen(animate);
2315 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002316
2317 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2318 int[] cell, int spanX, int spanY) {
2319 switch (info.itemType) {
2320 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2321 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2322 int span[] = new int[2];
2323 span[0] = spanX;
2324 span[1] = spanY;
2325 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2326 container, screenId, cell, span);
2327 break;
2328 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2329 processShortcutFromDrop(info.componentName, container, screenId, cell);
2330 break;
2331 default:
2332 throw new IllegalStateException("Unknown item type: " + info.itemType);
2333 }
2334 }
2335
Adam Cohenfbba09b2011-07-18 21:43:05 -07002336 /**
2337 * Process a shortcut drop.
2338 *
2339 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002340 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002341 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002342 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002343 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2344 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002345 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002346 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002347 mPendingAddInfo.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002348 mPendingAddInfo.dropPos = null;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002349
2350 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002351 mPendingAddInfo.cellX = cell[0];
2352 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002353 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002354
2355 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2356 createShortcutIntent.setComponent(componentName);
2357 processShortcut(createShortcutIntent);
2358 }
2359
Adam Cohenfbba09b2011-07-18 21:43:05 -07002360 /**
2361 * Process a widget drop.
2362 *
2363 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002364 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002365 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002366 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002367 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2368 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002369 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002370 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002371 mPendingAddInfo.screenId = info.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002372 mPendingAddInfo.dropPos = null;
Adam Cohend41fbf52012-02-16 23:53:59 -08002373 mPendingAddInfo.minSpanX = info.minSpanX;
2374 mPendingAddInfo.minSpanY = info.minSpanY;
2375
Adam Cohenfbba09b2011-07-18 21:43:05 -07002376 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002377 mPendingAddInfo.cellX = cell[0];
2378 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002379 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002380 if (span != null) {
2381 mPendingAddInfo.spanX = span[0];
2382 mPendingAddInfo.spanY = span[1];
2383 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002384
Adam Cohened66b2b2012-01-23 17:28:51 -08002385 AppWidgetHostView hostView = info.boundWidget;
2386 int appWidgetId;
2387 if (hostView != null) {
2388 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002389 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002390 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002391 // In this case, we either need to start an activity to get permission to bind
2392 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002393 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002394 Bundle options = info.bindOptions;
2395
Sunny Goyalffe83f12014-08-14 17:39:34 -07002396 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2397 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002398 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002399 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002400 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002401 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002402 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2403 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2404 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002405 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2406 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002407 // TODO: we need to make sure that this accounts for the options bundle.
2408 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002409 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2410 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002411 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002412 }
2413
Joe Onoratodeb98af2010-02-19 14:59:39 -08002414 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002415 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002416 }
2417
Winson Chung24ab2f12010-09-16 14:10:47 -07002418 void processWallpaper(Intent intent) {
2419 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2420 }
2421
Adam Cohendcd297f2013-06-18 13:13:40 -07002422 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002423 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002424 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 folderInfo.title = getText(R.string.folder_name);
2426
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002427 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002428 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002429 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002430 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002431
2432 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002433 FolderIcon newFolder =
2434 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002435 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002436 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002437 // Force measure the new folder icon
2438 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2439 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002440 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002441 }
Romain Guycbb89e42009-06-08 15:52:54 -07002442
Joe Onorato9c1289c2009-08-17 11:03:03 -04002443 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002444 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002445 }
2446
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002447 protected ComponentName getWallpaperPickerComponent() {
Adam Cohen9211d422014-10-07 18:14:53 -07002448 if (mLauncherCallbacks != null) {
2449 return mLauncherCallbacks.getWallpaperPickerComponent();
2450 }
Michael Jurka7ad868b2013-12-12 15:04:25 +01002451 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002452 }
2453
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002454 /**
2455 * Registers various content observers. The current implementation registers
2456 * only a favorites observer to keep track of the favorites applications.
2457 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002458 private void registerContentObservers() {
2459 ContentResolver resolver = getContentResolver();
2460 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2461 true, mWidgetObserver);
2462 }
2463
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002464 @Override
2465 public boolean dispatchKeyEvent(KeyEvent event) {
2466 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2467 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002468 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002469 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002470 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002471 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002472 dumpState();
2473 return true;
2474 }
2475 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002476 }
2477 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2478 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002479 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002480 return true;
2481 }
2482 }
2483
2484 return super.dispatchKeyEvent(event);
2485 }
2486
Joe Onorato88ec0992009-11-19 13:16:06 -08002487 @Override
2488 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002489 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2490 return;
2491 }
2492
Winson Chungc93e5ae2012-07-23 20:48:26 -07002493 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002494 if (mAppsCustomizeContent.getContentType() ==
2495 AppsCustomizePagedView.ContentType.Applications) {
2496 showWorkspace(true);
2497 } else {
2498 showOverviewMode(true);
2499 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002500 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002501 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002502 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002503 Folder openFolder = mWorkspace.getOpenFolder();
2504 if (openFolder.isEditingName()) {
2505 openFolder.dismissEditingName();
2506 } else {
2507 closeFolder();
2508 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002509 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002510 mWorkspace.exitWidgetResizeMode();
2511
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002512 // Back button is a no-op here, but give at least some feedback for the button press
2513 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002514 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002515 }
2516
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002517 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002518 * Re-listen when widgets are reset.
2519 */
2520 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002521 if (mAppWidgetHost != null) {
2522 mAppWidgetHost.startListening();
2523 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002524 }
2525
2526 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002527 * Launches the intent referred by the clicked shortcut.
2528 *
2529 * @param v The view representing the clicked shortcut.
2530 */
2531 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002532 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2533 // view has detached (it's possible for this to happen if the view is removed mid touch).
2534 if (v.getWindowToken() == null) {
2535 return;
2536 }
2537
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002538 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002539 return;
2540 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002541
Adam Cohen1697b792013-09-17 19:08:21 -07002542 if (v instanceof Workspace) {
2543 if (mWorkspace.isInOverviewMode()) {
2544 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002545 }
2546 return;
2547 }
2548
2549 if (v instanceof CellLayout) {
2550 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002551 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002552 }
2553 }
2554
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002556 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002557 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002558 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002559 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002560 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002561 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002562 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002563 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002564 } else if (tag instanceof AppInfo) {
2565 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002566 } else if (tag instanceof LauncherAppWidgetInfo) {
2567 if (v instanceof PendingAppWidgetHostView) {
2568 onClickPendingWidget((PendingAppWidgetHostView) v);
2569 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002570 }
2571 }
2572
Sunny Goyal508da152014-08-14 10:53:27 -07002573 public void onClickPagedViewIcon(View v) {
2574 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002575 if (mLauncherCallbacks != null) {
2576 mLauncherCallbacks.onClickPagedViewIcon(v);
2577 }
Sunny Goyal508da152014-08-14 10:53:27 -07002578 }
2579
Michael Jurka0e260592010-06-30 17:07:39 -07002580 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002581 return false;
2582 }
2583
Michael Jurkaaf442092010-06-10 17:01:57 -07002584 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002585 * Event handler for the app widget view which has not fully restored.
2586 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002587 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002588 if (mIsSafeModeEnabled) {
2589 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2590 return;
2591 }
2592
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002593 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002594 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002595 int widgetId = info.appWidgetId;
2596 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2597 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002598 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2599 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002600 mPendingAddInfo.copyFrom(info);
2601 mPendingAddWidgetId = widgetId;
2602
Sunny Goyalffe83f12014-08-14 17:39:34 -07002603 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2604 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002605 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002606 } else if (info.installProgress < 0) {
2607 // The install has not been queued
2608 final String packageName = info.providerName.getPackageName();
2609 showBrokenAppInstallDialog(packageName,
2610 new DialogInterface.OnClickListener() {
2611 public void onClick(DialogInterface dialog, int id) {
2612 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2613 }
2614 });
2615 } else {
2616 // Download has started.
2617 final String packageName = info.providerName.getPackageName();
2618 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002619 }
2620 }
2621
2622 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002623 * Event handler for the "grid" button that appears on the home screen, which
2624 * enters all apps mode.
2625 *
2626 * @param v The view that was clicked.
2627 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002628 protected void onClickAllAppsButton(View v) {
2629 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2630 if (isAllAppsVisible()) {
2631 showWorkspace(true);
2632 } else {
2633 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2634 }
Adam Cohen9211d422014-10-07 18:14:53 -07002635 if (mLauncherCallbacks != null) {
2636 mLauncherCallbacks.onClickAllAppsButton(v);
2637 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002638 }
2639
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002640 private void showBrokenAppInstallDialog(final String packageName,
2641 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002642 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002643 .setTitle(R.string.abandoned_promises_title)
2644 .setMessage(R.string.abandoned_promise_explanation)
2645 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2646 .setNeutralButton(R.string.abandoned_clean_this,
2647 new DialogInterface.OnClickListener() {
2648 public void onClick(DialogInterface dialog, int id) {
2649 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2650 mWorkspace.removeAbandonedPromise(packageName, user);
2651 }
2652 })
2653 .create().show();
2654 return;
2655 }
2656
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002657 /**
2658 * Event handler for an app shortcut click.
2659 *
2660 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2661 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002662 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002663 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2664 Object tag = v.getTag();
2665 if (!(tag instanceof ShortcutInfo)) {
2666 throw new IllegalArgumentException("Input must be a Shortcut");
2667 }
2668
2669 // Open shortcut
2670 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002671
2672 if (shortcut.isDisabled != 0) {
2673 int error = R.string.activity_not_available;
2674 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2675 error = R.string.safemode_shortcut_error;
2676 }
2677 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2678 return;
2679 }
2680
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002681 final Intent intent = shortcut.intent;
2682
2683 // Check for special shortcuts
2684 if (intent.getComponent() != null) {
2685 final String shortcutClass = intent.getComponent().getClassName();
2686
2687 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2688 MemoryDumpActivity.startDump(this);
2689 return;
2690 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2691 toggleShowWeightWatcher();
2692 return;
2693 }
2694 }
2695
Chris Wren40c5ed32014-06-24 18:24:23 -04002696 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002697 if ((v instanceof BubbleTextView)
2698 && shortcut.isPromise()
2699 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002700 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002701 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002702 new DialogInterface.OnClickListener() {
2703 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002704 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002705 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002706 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002707 return;
2708 }
2709
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002710 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002711 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002712
2713 if (mLauncherCallbacks != null) {
2714 mLauncherCallbacks.onClickAppShortcut(v);
2715 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002716 }
2717
Sunny Goyal508da152014-08-14 10:53:27 -07002718 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002719 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002720 final ShortcutInfo shortcut;
2721 final Intent intent;
2722 if (tag instanceof ShortcutInfo) {
2723 shortcut = (ShortcutInfo) tag;
2724 intent = shortcut.intent;
2725 int[] pos = new int[2];
2726 v.getLocationOnScreen(pos);
2727 intent.setSourceBounds(new Rect(pos[0], pos[1],
2728 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002729
Sunny Goyal508da152014-08-14 10:53:27 -07002730 } else if (tag instanceof AppInfo) {
2731 shortcut = null;
2732 intent = ((AppInfo) tag).intent;
2733 } else {
2734 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2735 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002736
2737 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002738 mStats.recordLaunch(intent, shortcut);
2739
2740 if (success && v instanceof BubbleTextView) {
2741 mWaitingForResume = (BubbleTextView) v;
2742 mWaitingForResume.setStayPressed(true);
2743 }
2744 }
2745
2746 /**
2747 * Event handler for a folder icon click.
2748 *
2749 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2750 */
2751 protected void onClickFolderIcon(View v) {
2752 if (LOGD) Log.d(TAG, "onClickFolder");
2753 if (!(v instanceof FolderIcon)){
2754 throw new IllegalArgumentException("Input must be a FolderIcon");
2755 }
2756
2757 FolderIcon folderIcon = (FolderIcon) v;
2758 final FolderInfo info = folderIcon.getFolderInfo();
2759 Folder openFolder = mWorkspace.getFolderForTag(info);
2760
2761 // If the folder info reports that the associated folder is open, then verify that
2762 // it is actually opened. There have been a few instances where this gets out of sync.
2763 if (info.opened && openFolder == null) {
2764 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2765 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2766 info.opened = false;
2767 }
2768
2769 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2770 // Close any open folder
2771 closeFolder();
2772 // Open the requested folder
2773 openFolder(folderIcon);
2774 } else {
2775 // Find the open folder...
2776 int folderScreen;
2777 if (openFolder != null) {
2778 folderScreen = mWorkspace.getPageForView(openFolder);
2779 // .. and close it
2780 closeFolder(openFolder);
2781 if (folderScreen != mWorkspace.getCurrentPage()) {
2782 // Close any folder open on the current screen
2783 closeFolder();
2784 // Pull the folder onto this screen
2785 openFolder(folderIcon);
2786 }
2787 }
2788 }
Adam Cohen9211d422014-10-07 18:14:53 -07002789
2790 if (mLauncherCallbacks != null) {
2791 mLauncherCallbacks.onClickFolderIcon(v);
2792 }
Michael Jurka5130e402011-10-13 04:55:35 -07002793 }
2794
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002795 /**
2796 * Event handler for the (Add) Widgets button that appears after a long press
2797 * on the home screen.
2798 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002799 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002800 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002801 if (mIsSafeModeEnabled) {
2802 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2803 } else {
2804 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2805 if (mLauncherCallbacks != null) {
2806 mLauncherCallbacks.onClickAddWidgetButton(view);
2807 }
Adam Cohen9211d422014-10-07 18:14:53 -07002808 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002809 }
2810
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002811 /**
2812 * Event handler for the wallpaper picker button that appears after a long press
2813 * on the home screen.
2814 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002815 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002816 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2817 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2818 pickWallpaper.setComponent(getWallpaperPickerComponent());
2819 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002820
2821 if (mLauncherCallbacks != null) {
2822 mLauncherCallbacks.onClickWallpaperPicker(v);
2823 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002824 }
2825
2826 /**
2827 * Event handler for a click on the settings button that appears after a long press
2828 * on the home screen.
2829 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002830 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002831 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002832 if (mLauncherCallbacks != null) {
2833 mLauncherCallbacks.onClickSettingsButton(v);
2834 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002835 }
2836
Michael Jurka5130e402011-10-13 04:55:35 -07002837 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002838 // Provide the same haptic feedback that the system offers for virtual keys.
2839 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002840 }
2841
Adam Cohen61f560d2013-09-30 15:58:20 -07002842 public void performHapticFeedbackOnTouchDown(View v) {
2843 // Provide the same haptic feedback that the system offers for virtual keys.
2844 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2845 }
2846
2847 public View.OnTouchListener getHapticFeedbackTouchListener() {
2848 if (mHapticFeedbackTouchListener == null) {
2849 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2850 @Override
2851 public boolean onTouch(View v, MotionEvent event) {
2852 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2853 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2854 }
2855 return false;
2856 }
2857 };
2858 }
2859 return mHapticFeedbackTouchListener;
2860 }
2861
Adam Cohen9211d422014-10-07 18:14:53 -07002862 public void onDragStarted(View view) {
2863 if (isOnCustomContent()) {
2864 // Custom content screen doesn't participate in drag and drop. If on custom
2865 // content screen, move to default.
2866 moveWorkspaceToDefaultScreen();
2867 }
2868
2869 if (mLauncherCallbacks != null) {
2870 mLauncherCallbacks.onDragStarted(view);
2871 }
2872 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002873
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002874 /**
2875 * Called when the user stops interacting with the launcher.
2876 * This implies that the user is now on the homescreen and is not doing housekeeping.
2877 */
Adam Cohen9211d422014-10-07 18:14:53 -07002878 protected void onInteractionEnd() {
2879 if (mLauncherCallbacks != null) {
2880 mLauncherCallbacks.onInteractionEnd();
2881 }
2882 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002883
2884 /**
2885 * Called when the user starts interacting with the launcher.
2886 * The possible interactions are:
2887 * - open all apps
2888 * - reorder an app shortcut, or a widget
2889 * - open the overview mode.
2890 * This is a good time to stop doing things that only make sense
2891 * when the user is on the homescreen and not doing housekeeping.
2892 */
Adam Cohen9211d422014-10-07 18:14:53 -07002893 protected void onInteractionBegin() {
2894 if (mLauncherCallbacks != null) {
2895 mLauncherCallbacks.onInteractionBegin();
2896 }
2897 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002898
Kenny Guyf07af7b2014-07-31 11:39:16 +01002899 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002900 try {
2901 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002902 launcherApps.showAppDetailsForProfile(componentName, user);
2903 } catch (SecurityException e) {
2904 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2905 Log.e(TAG, "Launcher does not have permission to launch settings");
2906 } catch (ActivityNotFoundException e) {
2907 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2908 Log.e(TAG, "Unable to launch settings");
2909 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002910 }
2911
Michael Jurka1e2f4652013-07-08 18:03:46 -07002912 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002913 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2914 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002915 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002916 // System applications cannot be installed. For now, show a toast explaining that.
2917 // We may give them the option of disabling apps this way.
2918 int messageId = R.string.uninstall_system_app_text;
2919 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002920 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002921 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002922 String packageName = componentName.getPackageName();
2923 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002924 Intent intent = new Intent(
2925 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002926 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2927 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002928 if (user != null) {
2929 user.addToIntent(intent, Intent.EXTRA_USER);
2930 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002931 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002932 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002933 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002934 }
2935
Michael Jurka86a720e2012-05-09 11:23:23 -07002936 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002937 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002938 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002939 // Only launch using the new animation if the shortcut has not opted out (this is a
2940 // private contract between launcher and may be ignored in the future).
2941 boolean useLaunchAnimation = (v != null) &&
2942 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002943 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2944 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002945
Kenny Guy1317e2d2014-05-08 18:52:50 +01002946 UserHandleCompat user = null;
2947 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2948 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2949 user = userManager.getUserForSerialNumber(serialNumber);
2950 }
2951
2952 Bundle optsBundle = null;
Adam Cohen68fdeaa2015-04-02 11:53:23 -07002953 if (useLaunchAnimation && !Utilities.isLmpOrAbove()) {
2954 // On pre-L devices, we use the scale up transition.
Adam Cohen68fdeaa2015-04-02 11:53:23 -07002955 ActivityOptions opts =
Adam Cohen4da294d2014-07-28 10:56:19 -07002956 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002957 optsBundle = opts.toBundle();
Adam Cohenc3d45532015-05-22 14:36:14 -07002958 } else if (useLaunchAnimation && Utilities.isLmpMr1()) {
2959 // On L-MR1 devices, we use custom slide up animation without a delay
2960 // On L devices, we use the system default slide up.
2961 ActivityOptions opts = ActivityOptions.makeCustomAnimation(this,
2962 R.anim.task_open_enter, R.anim.no_anim);
2963 optsBundle = opts.toBundle();
Adam Cohen6ea3b112014-06-11 11:38:49 -07002964 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002965
2966 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2967 // Could be launching some bookkeeping activity
2968 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002969 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002970 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002971 launcherApps.startActivityForProfile(intent.getComponent(), user,
2972 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002973 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002974 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002975 } catch (SecurityException e) {
2976 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002977 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002978 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002979 "or use the exported attribute for this activity. "
2980 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002981 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002982 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002983 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002984
Michael Jurka86a720e2012-05-09 11:23:23 -07002985 boolean startActivitySafely(View v, Intent intent, Object tag) {
2986 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002987 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2988 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2989 return false;
2990 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002991 try {
2992 success = startActivity(v, intent, tag);
2993 } catch (ActivityNotFoundException e) {
2994 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2995 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2996 }
2997 return success;
2998 }
2999
Adam Cohen268c4752012-06-06 17:47:33 -07003000 /**
3001 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
3002 * in the DragLayer in the exact absolute location of the original FolderIcon.
3003 */
3004 private void copyFolderIconToImage(FolderIcon fi) {
3005 final int width = fi.getMeasuredWidth();
3006 final int height = fi.getMeasuredHeight();
3007
3008 // Lazy load ImageView, Bitmap and Canvas
3009 if (mFolderIconImageView == null) {
3010 mFolderIconImageView = new ImageView(this);
3011 }
3012 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3013 mFolderIconBitmap.getHeight() != height) {
3014 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3015 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3016 }
3017
3018 DragLayer.LayoutParams lp;
3019 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3020 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3021 } else {
3022 lp = new DragLayer.LayoutParams(width, height);
3023 }
3024
Adam Cohen307fe232012-08-16 17:55:58 -07003025 // The layout from which the folder is being opened may be scaled, adjust the starting
3026 // view size by this scale factor.
3027 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003028 lp.customPosition = true;
3029 lp.x = mRectForFolderAnimation.left;
3030 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003031 lp.width = (int) (scale * width);
3032 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003033
3034 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3035 fi.draw(mFolderIconCanvas);
3036 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003037 if (fi.getFolder() != null) {
3038 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3039 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003040 }
Adam Cohen268c4752012-06-06 17:47:33 -07003041 // Just in case this image view is still in the drag layer from a previous animation,
3042 // we remove it and re-add it.
3043 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3044 mDragLayer.removeView(mFolderIconImageView);
3045 }
3046 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003047 if (fi.getFolder() != null) {
3048 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003049 }
Adam Cohen268c4752012-06-06 17:47:33 -07003050 }
3051
Adam Cohen2801caf2011-05-13 20:57:39 -07003052 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003053 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003054 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3055 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3056 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3057
Adam Cohenc51934b2011-07-26 21:07:43 -07003058 FolderInfo info = (FolderInfo) fi.getTag();
3059 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3060 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003061 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3062 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003063 }
3064
Adam Cohen268c4752012-06-06 17:47:33 -07003065 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3066 copyFolderIconToImage(fi);
3067 fi.setVisibility(View.INVISIBLE);
3068
Michael Jurka2ecf9952012-06-18 12:52:28 -07003069 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003070 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003071 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003072 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3073 }
3074 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003075 oa.start();
3076 }
3077
Adam Cohen268c4752012-06-06 17:47:33 -07003078 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003079 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003080 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3081 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3082 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3083
Adam Cohen268c4752012-06-06 17:47:33 -07003084 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003085
Adam Cohen268c4752012-06-06 17:47:33 -07003086 // We remove and re-draw the FolderIcon in-case it has changed
3087 mDragLayer.removeView(mFolderIconImageView);
3088 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003089 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003090 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003091 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003092 oa.addListener(new AnimatorListenerAdapter() {
3093 @Override
3094 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003095 if (cl != null) {
3096 cl.clearFolderLeaveBehind();
3097 // Remove the ImageView copy of the FolderIcon and make the original visible.
3098 mDragLayer.removeView(mFolderIconImageView);
3099 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003100 }
3101 }
3102 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003103 oa.start();
3104 }
3105
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003106 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003107 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003108 * is animated relative to the specified View. If the View is null, no animation
3109 * is played.
3110 *
3111 * @param folderInfo The FolderInfo describing the folder to open.
3112 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003113 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003114 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07003115 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003116
Adam Cohena9cf38f2011-05-02 15:36:58 -07003117 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003118
Adam Cohen4554ee12011-08-03 16:13:21 -07003119 // Just verify that the folder hasn't already been added to the DragLayer.
3120 // There was a one-off crash where the folder had a parent already.
3121 if (folder.getParent() == null) {
3122 mDragLayer.addView(folder);
3123 mDragController.addDropTarget((DropTarget) folder);
3124 } else {
3125 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3126 folder.getParent() + ").");
3127 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003128 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003129 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003130
3131 // Notify the accessibility manager that this folder "window" has appeared and occluded
3132 // the workspace items
3133 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3134 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003135 }
3136
3137 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003138 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003139 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003140 if (folder.isEditingName()) {
3141 folder.dismissEditingName();
3142 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003143 closeFolder(folder);
3144 }
3145 }
3146
3147 void closeFolder(Folder folder) {
3148 folder.getInfo().opened = false;
3149
3150 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3151 if (parent != null) {
3152 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3153 shrinkAndFadeInFolderIcon(fi);
3154 }
3155 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003156
3157 // Notify the accessibility manager that this folder "window" has disappeard and no
3158 // longer occludeds the workspace items
3159 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003160 }
3161
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003162 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003163 if (!isDraggingEnabled()) return false;
3164 if (isWorkspaceLocked()) return false;
3165 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003166
Adam Cohen1697b792013-09-17 19:08:21 -07003167 if (v instanceof Workspace) {
3168 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003169 if (mWorkspace.enterOverviewMode()) {
3170 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3171 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3172 return true;
3173 } else {
3174 return false;
3175 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003176 } else {
3177 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003178 }
Adam Cohen1697b792013-09-17 19:08:21 -07003179 }
3180
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003181 CellLayout.CellInfo longClickCellInfo = null;
3182 View itemUnderLongClick = null;
3183 if (v.getTag() instanceof ItemInfo) {
3184 ItemInfo info = (ItemInfo) v.getTag();
3185 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3186 itemUnderLongClick = longClickCellInfo.cell;
3187 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003188 }
3189
Winson Chung3d503fb2011-07-13 17:25:49 -07003190 // The hotseat touch handling does not go through Workspace, and we always allow long press
3191 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003192 final boolean inHotseat = isHotseatLayout(v);
3193 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003194 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003195 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003196 // User long pressed on empty space
3197 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3198 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003199 if (mWorkspace.isInOverviewMode()) {
3200 mWorkspace.startReordering(v);
3201 } else {
3202 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003203 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003204 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003205 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3206 mHotseat.getOrderInHotseat(
3207 longClickCellInfo.cellX,
3208 longClickCellInfo.cellY));
3209 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003210 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003211 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003212 }
3213 }
3214 }
3215 return true;
3216 }
3217
Winson Chung3d503fb2011-07-13 17:25:49 -07003218 boolean isHotseatLayout(View layout) {
3219 return mHotseat != null && layout != null &&
3220 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3221 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003222
Winson Chung3d503fb2011-07-13 17:25:49 -07003223 /**
3224 * Returns the CellLayout of the specified container at the specified screen.
3225 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003226 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003227 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3228 if (mHotseat != null) {
3229 return mHotseat.getLayout();
3230 } else {
3231 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003232 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003233 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003234 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003235 }
3236 }
3237
Daniel Sandler843e8602010-06-07 14:59:01 -04003238 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003239 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003240 }
3241
Craig Mautner360310b2012-10-26 15:13:08 -07003242 private void setWorkspaceBackground(boolean workspace) {
3243 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003244 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003245 }
3246
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003247 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003248 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3249 int curflags = getWindow().getAttributes().flags
3250 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3251 if (wpflags != curflags) {
3252 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3253 }
Craig Mautner360310b2012-10-26 15:13:08 -07003254 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003255 }
3256
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003257 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3258 if (v instanceof LauncherTransitionable) {
3259 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3260 }
3261 }
3262
Michael Jurkabed61d22012-02-14 22:51:29 -08003263 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3264 if (v instanceof LauncherTransitionable) {
3265 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3266 }
Winson Chung70442722012-02-10 15:43:22 -08003267
3268 // Update the workspace transition step as well
3269 dispatchOnLauncherTransitionStep(v, 0f);
3270 }
3271
3272 private void dispatchOnLauncherTransitionStep(View v, float t) {
3273 if (v instanceof LauncherTransitionable) {
3274 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3275 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003276 }
3277
3278 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3279 if (v instanceof LauncherTransitionable) {
3280 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3281 }
Winson Chung70442722012-02-10 15:43:22 -08003282
3283 // Update the workspace transition step as well
3284 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003285 }
3286
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003287 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003288 * Things to test when changing the following seven functions.
3289 * - Home from workspace
3290 * - from center screen
3291 * - from other screens
3292 * - Home from all apps
3293 * - from center screen
3294 * - from other screens
3295 * - Back from all apps
3296 * - from center screen
3297 * - from other screens
3298 * - Launch app from workspace and quit
3299 * - with back
3300 * - with home
3301 * - Launch app from all apps and quit
3302 * - with back
3303 * - with home
3304 * - Go to a screen that's not the default, then all
3305 * apps, and launch and app, and go back
3306 * - with back
3307 * -with home
3308 * - On workspace, long press power and go back
3309 * - with back
3310 * - with home
3311 * - On all apps, long press power and go back
3312 * - with back
3313 * - with home
3314 * - On workspace, power off
3315 * - On all apps, power off
3316 * - Launch an app and turn off the screen while in that app
3317 * - Go back with home key
3318 * - Go back with back key TODO: make this not go to workspace
3319 * - From all apps
3320 * - From workspace
3321 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3322 * - From all apps
3323 * - From the center workspace
3324 * - From another workspace
3325 */
3326
3327 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003328 * Zoom the camera out from the workspace to reveal 'toView'.
3329 * Assumes that the view to show is anchored at either the very top or very bottom
3330 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003331 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003332 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003333 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3334 showAppsCustomizeHelper(animated, springLoaded, contentType);
3335 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003336
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08003337 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Winson Chungc58497e2013-09-03 17:48:37 -07003338 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3339 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003340 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003341 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003342 mStateAnimation.cancel();
3343 mStateAnimation = null;
3344 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003345
Kenny Guyd794a3f2014-09-16 15:17:58 +01003346 boolean material = Utilities.isLmpOrAbove();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003347
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003348 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003349
Adam Cohen6c5891a2014-07-09 23:53:15 -07003350 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003351 final int itemsAlphaStagger =
3352 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003353
Michael Jurkabed61d22012-02-14 22:51:29 -08003354 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003355 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003356
Adam Cohen80e6beb2015-02-13 16:14:33 -08003357 final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
Adam Cohen2854d252014-08-27 16:04:07 -07003358
Adam Cohen6c5891a2014-07-09 23:53:15 -07003359 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3360 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003361 Animator workspaceAnim =
Adam Cohen2854d252014-08-27 16:04:07 -07003362 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003363 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003364 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3365 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003366 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3367 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003368
Adam Cohena38dc902014-09-07 17:48:55 +02003369 // If for some reason our views aren't initialized, don't animate
3370 boolean initialized = getAllAppsButton() != null;
3371
3372 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003373 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003374 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3375 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003376
Adam Cohen9bfdb762014-07-21 17:44:06 -07003377 final View page = content.getPageAt(content.getCurrentPage());
3378 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003379
Adam Cohen63f1ec02014-08-12 09:23:13 -07003380 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3381 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003382 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3383 } else {
3384 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3385 }
3386
Adam Cohen9bfdb762014-07-21 17:44:06 -07003387 // Hide the real page background, and swap in the fake one
Adam Cohen9bfdb762014-07-21 17:44:06 -07003388 content.setPageBackgroundsVisible(false);
Adam Cohen2854d252014-08-27 16:04:07 -07003389 revealView.setVisibility(View.VISIBLE);
3390 // We need to hide this view as the animation start will be posted.
3391 revealView.setAlpha(0);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003392
Adam Cohen9bfdb762014-07-21 17:44:06 -07003393 int width = revealView.getMeasuredWidth();
3394 int height = revealView.getMeasuredHeight();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003395 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen2854d252014-08-27 16:04:07 -07003396
Adam Cohen63f1ec02014-08-12 09:23:13 -07003397 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003398 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003399
Adam Cohen63f1ec02014-08-12 09:23:13 -07003400 // Get the y delta between the center of the page and the center of the all apps button
3401 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3402 getAllAppsButton(), null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003403
Adam Cohen2854d252014-08-27 16:04:07 -07003404 float alpha = 0;
3405 float xDrift = 0;
3406 float yDrift = 0;
3407 if (material) {
3408 alpha = isWidgetTray ? 0.3f : 1f;
3409 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3410 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3411 } else {
3412 yDrift = 2 * height / 3;
3413 xDrift = 0;
3414 }
3415 final float initAlpha = alpha;
3416
Adam Cohen80e6beb2015-02-13 16:14:33 -08003417 layerViews.put(revealView, BUILD_AND_SET_LAYER);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003418 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003419 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003420 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003421 PropertyValuesHolder panelDriftX =
3422 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003423
Adam Cohen2854d252014-08-27 16:04:07 -07003424 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3425 panelAlpha, panelDriftY, panelDriftX);
3426
Adam Cohen9bfdb762014-07-21 17:44:06 -07003427 panelAlphaAndDrift.setDuration(revealDuration);
3428 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003429
Adam Cohen9bfdb762014-07-21 17:44:06 -07003430 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003431
Adam Cohen4e243a22014-08-10 18:30:55 -07003432 if (page != null) {
3433 page.setVisibility(View.VISIBLE);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003434 layerViews.put(page, BUILD_AND_SET_LAYER);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003435
Adam Cohen2854d252014-08-27 16:04:07 -07003436 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3437 page.setTranslationY(yDrift);
Adam Cohen4e243a22014-08-10 18:30:55 -07003438 pageDrift.setDuration(revealDuration);
3439 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003440 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003441 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003442
Adam Cohen63f1ec02014-08-12 09:23:13 -07003443 page.setAlpha(0f);
Adam Cohen2854d252014-08-27 16:04:07 -07003444 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003445 itemsAlpha.setDuration(revealDuration);
3446 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3447 itemsAlpha.setStartDelay(itemsAlphaStagger);
3448 mStateAnimation.play(itemsAlpha);
3449 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003450
Adam Cohen4e243a22014-08-10 18:30:55 -07003451 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3452 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003453 ObjectAnimator indicatorsAlpha =
Adam Cohen2854d252014-08-27 16:04:07 -07003454 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003455 indicatorsAlpha.setDuration(revealDuration);
3456 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003457
Adam Cohen9bfdb762014-07-21 17:44:06 -07003458 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003459 final View allApps = getAllAppsButton();
3460 int allAppsButtonSize = LauncherAppState.getInstance().
3461 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3462 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen2854d252014-08-27 16:04:07 -07003463 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003464 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003465 reveal.setDuration(revealDuration);
3466 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003467
3468 reveal.addListener(new AnimatorListenerAdapter() {
3469 public void onAnimationStart(Animator animation) {
3470 if (!isWidgetTray) {
3471 allApps.setVisibility(View.INVISIBLE);
3472 }
3473 }
3474 public void onAnimationEnd(Animator animation) {
3475 if (!isWidgetTray) {
3476 allApps.setVisibility(View.VISIBLE);
3477 }
3478 }
3479 });
Adam Cohen6c5891a2014-07-09 23:53:15 -07003480 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003481 }
Michael Jurka1899a362011-11-03 13:50:45 -07003482
Adam Cohen9bfdb762014-07-21 17:44:06 -07003483 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3484 @Override
3485 public void onAnimationEnd(Animator animation) {
3486 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3487 dispatchOnLauncherTransitionEnd(toView, animated, false);
3488
3489 revealView.setVisibility(View.INVISIBLE);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003490
3491 for (View v : layerViews.keySet()) {
3492 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3493 v.setLayerType(View.LAYER_TYPE_NONE, null);
3494 }
Adam Cohen4e243a22014-08-10 18:30:55 -07003495 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003496 content.setPageBackgroundsVisible(true);
3497
3498 // Hide the search bar
3499 if (mSearchDropTargetBar != null) {
3500 mSearchDropTargetBar.hideSearchBar(false);
3501 }
Adam Cohen3f9c9712014-10-31 11:48:25 -07003502
3503 // This can hold unnecessary references to views.
3504 mStateAnimation = null;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003505 }
3506
Adam Cohen9bfdb762014-07-21 17:44:06 -07003507 });
3508
Adam Cohen6c5891a2014-07-09 23:53:15 -07003509 if (workspaceAnim != null) {
3510 mStateAnimation.play(workspaceAnim);
3511 }
Adam Cohen2854d252014-08-27 16:04:07 -07003512
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003513 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3514 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003515 final AnimatorSet stateAnimation = mStateAnimation;
3516 final Runnable startAnimRunnable = new Runnable() {
3517 public void run() {
3518 // Check that mStateAnimation hasn't changed while
3519 // we waited for a layout/draw pass
3520 if (mStateAnimation != stateAnimation)
3521 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003522 dispatchOnLauncherTransitionStart(fromView, animated, false);
3523 dispatchOnLauncherTransitionStart(toView, animated, false);
Adam Cohen2854d252014-08-27 16:04:07 -07003524
3525 revealView.setAlpha(initAlpha);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003526
3527 for (View v : layerViews.keySet()) {
3528 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3529 v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3530 }
3531 }
3532
Kenny Guyd794a3f2014-09-16 15:17:58 +01003533 if (Utilities.isLmpOrAbove()) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003534 for (View v : layerViews.keySet()) {
3535 if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003536 }
3537 }
3538 mStateAnimation.start();
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003539 }
3540 };
Adam Cohen2854d252014-08-27 16:04:07 -07003541 toView.bringToFront();
3542 toView.setVisibility(View.VISIBLE);
3543 toView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003544 } else {
3545 toView.setTranslationX(0.0f);
3546 toView.setTranslationY(0.0f);
3547 toView.setScaleX(1.0f);
3548 toView.setScaleY(1.0f);
3549 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003550 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003551
Daniel Sandlere4f98912013-06-25 15:13:26 -04003552 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003553 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003554 if (mSearchDropTargetBar != null) {
3555 mSearchDropTargetBar.hideSearchBar(false);
3556 }
Michael Jurkaabded662011-03-04 12:06:57 -08003557 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003558 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003559 dispatchOnLauncherTransitionStart(fromView, animated, false);
3560 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003561 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003562 dispatchOnLauncherTransitionStart(toView, animated, false);
3563 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003564 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003565 }
3566
3567 /**
3568 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003569 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003570 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003571 */
Adam Cohened307df2013-10-02 09:37:31 -07003572 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003573 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003574
Michael Jurkab3e22d92011-10-31 15:58:33 -07003575 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003576 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003577 mStateAnimation.cancel();
3578 mStateAnimation = null;
3579 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003580
Kenny Guyd794a3f2014-09-16 15:17:58 +01003581 boolean material = Utilities.isLmpOrAbove();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003582 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003583
Adam Cohen63f1ec02014-08-12 09:23:13 -07003584 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003585 final int itemsAlphaStagger =
3586 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003587
Winson Chungf0ea4d32011-06-06 14:27:16 -07003588 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003589 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003590 Animator workspaceAnim = null;
Adam Cohen80e6beb2015-02-13 16:14:33 -08003591 final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
Adam Cohen2854d252014-08-27 16:04:07 -07003592
Adam Cohened307df2013-10-02 09:37:31 -07003593 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003594 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003595 toState, animated, layerViews);
Adam Cohened307df2013-10-02 09:37:31 -07003596 } else if (toState == Workspace.State.SPRING_LOADED ||
3597 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003598 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003599 toState, animated, layerViews);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003600 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003601
Adam Cohena38dc902014-09-07 17:48:55 +02003602 // If for some reason our views aren't initialized, don't animate
3603 boolean initialized = getAllAppsButton() != null;
3604
3605 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003606 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen2854d252014-08-27 16:04:07 -07003607 if (workspaceAnim != null) {
3608 mStateAnimation.play(workspaceAnim);
3609 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003610
Adam Cohen9bfdb762014-07-21 17:44:06 -07003611 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3612 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003613
Adam Cohen9bfdb762014-07-21 17:44:06 -07003614 final View page = content.getPageAt(content.getNextPage());
Adam Cohen8e894fa2014-09-08 19:45:43 +02003615
3616 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3617 int count = content.getChildCount();
3618 for (int i = 0; i < count; i++) {
3619 View child = content.getChildAt(i);
3620 if (child != page) {
3621 child.setVisibility(View.INVISIBLE);
3622 }
3623 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003624 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003625
Adam Cohen2854d252014-08-27 16:04:07 -07003626 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3627 // don't perform all these no-op animations. In particularly, this was causing
3628 // the all-apps button to pop in and out.
3629 if (fromView.getVisibility() == View.VISIBLE) {
3630 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3631 final boolean isWidgetTray =
3632 contentType == AppsCustomizePagedView.ContentType.Widgets;
Adam Cohen63f1ec02014-08-12 09:23:13 -07003633
Adam Cohen2854d252014-08-27 16:04:07 -07003634 if (isWidgetTray) {
3635 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3636 } else {
3637 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003638 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003639
Adam Cohen2854d252014-08-27 16:04:07 -07003640 int width = revealView.getMeasuredWidth();
3641 int height = revealView.getMeasuredHeight();
3642 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3643
3644 // Hide the real page background, and swap in the fake one
3645 revealView.setVisibility(View.VISIBLE);
3646 content.setPageBackgroundsVisible(false);
3647
3648 final View allAppsButton = getAllAppsButton();
3649 revealView.setTranslationY(0);
3650 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3651 allAppsButton, null);
3652
3653 float xDrift = 0;
3654 float yDrift = 0;
3655 if (material) {
3656 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3657 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3658 } else {
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003659 yDrift = 2 * height / 3;
Adam Cohen2854d252014-08-27 16:04:07 -07003660 xDrift = 0;
3661 }
3662
Adam Cohen80e6beb2015-02-13 16:14:33 -08003663 layerViews.put(revealView, BUILD_AND_SET_LAYER);
Adam Cohen2854d252014-08-27 16:04:07 -07003664 TimeInterpolator decelerateInterpolator = material ?
3665 new LogDecelerateInterpolator(100, 0) :
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003666 new DecelerateInterpolator(1f);
Adam Cohen2854d252014-08-27 16:04:07 -07003667
3668 // The vertical motion of the apps panel should be delayed by one frame
3669 // from the conceal animation in order to give the right feel. We correpsondingly
3670 // shorten the duration so that the slide and conceal end at the same time.
3671 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3672 0, yDrift);
3673 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3674 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3675 panelDriftY.setInterpolator(decelerateInterpolator);
3676 mStateAnimation.play(panelDriftY);
3677
3678 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3679 0, xDrift);
3680 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3681 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3682 panelDriftX.setInterpolator(decelerateInterpolator);
3683 mStateAnimation.play(panelDriftX);
3684
3685 if (isWidgetTray || !material) {
3686 float finalAlpha = material ? 0.4f : 0f;
3687 revealView.setAlpha(1f);
3688 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3689 1f, finalAlpha);
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003690 panelAlpha.setDuration(material ? revealDuration : 150);
3691 panelAlpha.setInterpolator(decelerateInterpolator);
3692 panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen2854d252014-08-27 16:04:07 -07003693 mStateAnimation.play(panelAlpha);
3694 }
3695
3696 if (page != null) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003697 layerViews.put(page, BUILD_AND_SET_LAYER);
Adam Cohen2854d252014-08-27 16:04:07 -07003698
3699 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3700 0, yDrift);
3701 page.setTranslationY(0);
3702 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3703 pageDrift.setInterpolator(decelerateInterpolator);
3704 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3705 mStateAnimation.play(pageDrift);
3706
3707 page.setAlpha(1f);
3708 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3709 itemsAlpha.setDuration(100);
3710 itemsAlpha.setInterpolator(decelerateInterpolator);
3711 mStateAnimation.play(itemsAlpha);
3712 }
3713
3714 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3715 pageIndicators.setAlpha(1f);
3716 ObjectAnimator indicatorsAlpha =
3717 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3718 indicatorsAlpha.setDuration(revealDuration);
3719 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3720 mStateAnimation.play(indicatorsAlpha);
3721
3722 width = revealView.getMeasuredWidth();
3723
3724 if (material) {
3725 if (!isWidgetTray) {
3726 allAppsButton.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003727 }
Adam Cohen2854d252014-08-27 16:04:07 -07003728 int allAppsButtonSize = LauncherAppState.getInstance().
3729 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3730 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3731 Animator reveal =
3732 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3733 height / 2, revealRadius, finalRadius);
3734 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3735 reveal.setDuration(revealDuration);
3736 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003737
Adam Cohen2854d252014-08-27 16:04:07 -07003738 reveal.addListener(new AnimatorListenerAdapter() {
3739 public void onAnimationEnd(Animator animation) {
3740 revealView.setVisibility(View.INVISIBLE);
3741 if (!isWidgetTray) {
3742 allAppsButton.setVisibility(View.VISIBLE);
3743 }
3744 }
3745 });
Adam Cohen9bfdb762014-07-21 17:44:06 -07003746
Adam Cohen2854d252014-08-27 16:04:07 -07003747 mStateAnimation.play(reveal);
3748 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003749
Adam Cohen2854d252014-08-27 16:04:07 -07003750 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3751 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3752 mAppsCustomizeContent.stopScrolling();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003753 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003754
3755 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003756 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003757 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003758 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003759 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3760 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003761 if (onCompleteRunnable != null) {
3762 onCompleteRunnable.run();
3763 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003764
Adam Cohen80e6beb2015-02-13 16:14:33 -08003765 for (View v : layerViews.keySet()) {
3766 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3767 v.setLayerType(View.LAYER_TYPE_NONE, null);
3768 }
Adam Cohen4e243a22014-08-10 18:30:55 -07003769 }
Adam Cohen80e6beb2015-02-13 16:14:33 -08003770
Adam Cohen9bfdb762014-07-21 17:44:06 -07003771 content.setPageBackgroundsVisible(true);
Adam Cohen8e894fa2014-09-08 19:45:43 +02003772 // Unhide side pages
3773 int count = content.getChildCount();
3774 for (int i = 0; i < count; i++) {
3775 View child = content.getChildAt(i);
3776 child.setVisibility(View.VISIBLE);
3777 }
3778
3779 // Reset page transforms
Adam Cohen493f6bc2014-09-18 08:11:05 -07003780 if (page != null) {
3781 page.setTranslationX(0);
3782 page.setTranslationY(0);
3783 page.setAlpha(1);
3784 }
Adam Cohen8e894fa2014-09-08 19:45:43 +02003785 content.setCurrentPage(content.getNextPage());
3786
Chet Haasebc2f0822012-10-26 17:59:53 -07003787 mAppsCustomizeContent.updateCurrentPageScroll();
Adam Cohen3f9c9712014-10-31 11:48:25 -07003788
3789 // This can hold unnecessary references to views.
3790 mStateAnimation = null;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003791 }
3792 });
3793
Adam Cohen2854d252014-08-27 16:04:07 -07003794 final AnimatorSet stateAnimation = mStateAnimation;
3795 final Runnable startAnimRunnable = new Runnable() {
3796 public void run() {
3797 // Check that mStateAnimation hasn't changed while
3798 // we waited for a layout/draw pass
3799 if (mStateAnimation != stateAnimation)
3800 return;
3801 dispatchOnLauncherTransitionStart(fromView, animated, false);
3802 dispatchOnLauncherTransitionStart(toView, animated, false);
3803
Adam Cohen80e6beb2015-02-13 16:14:33 -08003804 for (View v : layerViews.keySet()) {
3805 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3806 v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3807 }
3808 }
3809
Kenny Guyd794a3f2014-09-16 15:17:58 +01003810 if (Utilities.isLmpOrAbove()) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003811 for (View v : layerViews.keySet()) {
3812 if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003813 }
3814 }
3815 mStateAnimation.start();
3816 }
3817 };
3818 fromView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003819 } else {
3820 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003821 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003822 dispatchOnLauncherTransitionStart(fromView, animated, true);
3823 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003824 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003825 dispatchOnLauncherTransitionStart(toView, animated, true);
3826 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003827 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003828 }
3829
Michael Jurkae326f182011-11-21 14:05:46 -08003830 @Override
3831 public void onTrimMemory(int level) {
3832 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003833 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3834 // The widget preview db can result in holding onto over
3835 // 3MB of memory for caching which isn't necessary.
3836 SQLiteDatabase.releaseMemory();
3837
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003838 // This clears all widget bitmaps from the widget tray
Adam Cohen3f9c9712014-10-31 11:48:25 -07003839 if (mAppsCustomizeTabHost != null) {
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003840 mAppsCustomizeTabHost.trimMemory();
Adam Cohen3f9c9712014-10-31 11:48:25 -07003841 }
Michael Jurkae326f182011-11-21 14:05:46 -08003842 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003843 if (mLauncherCallbacks != null) {
3844 mLauncherCallbacks.onTrimMemory(level);
3845 }
Michael Jurkae326f182011-11-21 14:05:46 -08003846 }
3847
Adam Cohened307df2013-10-02 09:37:31 -07003848 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003849 showWorkspace(animated, null);
3850 }
3851
Adam Cohened307df2013-10-02 09:37:31 -07003852 protected void showWorkspace() {
3853 showWorkspace(true);
3854 }
3855
Adam Cohened66b2b2012-01-23 17:28:51 -08003856 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003857 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003858 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003859 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003860 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003861
Winson Chungc7d2b602012-05-16 17:02:20 -07003862 // Show the search bar (only animate if we were showing the drop target bar in spring
3863 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003864 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003865 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003866 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003867
Michael Jurkab3e22d92011-10-31 15:58:33 -07003868 // Set focus to the AppsCustomize button
3869 if (mAllAppsButton != null) {
3870 mAllAppsButton.requestFocus();
3871 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003872 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003873
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003874 // Change the state *after* we've called all the transition code
3875 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003876
Winson Chung5fb63472011-02-02 17:03:37 -08003877 // Resume the auto-advance of widgets
3878 mUserPresent = true;
3879 updateRunning();
3880
alanv1d4fde62012-10-17 13:15:47 -07003881 // Send an accessibility event to announce the context change
3882 getWindow().getDecorView()
3883 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003884
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003885 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003886 }
3887
Adam Cohened307df2013-10-02 09:37:31 -07003888 void showOverviewMode(boolean animated) {
3889 mWorkspace.setVisibility(View.VISIBLE);
3890 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3891 mState = State.WORKSPACE;
3892 onWorkspaceShown(animated);
3893 }
3894
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003895 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003896 }
3897
Winson Chung82963d52013-10-09 11:20:57 -07003898 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3899 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003900 if (mState != State.WORKSPACE) return;
3901
Winson Chung82963d52013-10-09 11:20:57 -07003902 if (resetPageToZero) {
3903 mAppsCustomizeTabHost.reset();
3904 }
Winson Chungc58497e2013-09-03 17:48:37 -07003905 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003906 mAppsCustomizeTabHost.post(new Runnable() {
3907 @Override
3908 public void run() {
3909 // We post this in-case the all apps view isn't yet constructed.
3910 mAppsCustomizeTabHost.requestFocus();
3911 }
3912 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003913
Michael Jurkab3e22d92011-10-31 15:58:33 -07003914 // Change the state *after* we've called all the transition code
3915 mState = State.APPS_CUSTOMIZE;
3916
3917 // Pause the auto-advance of widgets until we are out of AllApps
3918 mUserPresent = false;
3919 updateRunning();
3920 closeFolder();
3921
3922 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003923 getWindow().getDecorView()
3924 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003925 }
3926
Adam Cohen7777d962011-08-18 18:58:38 -07003927 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003928 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003929 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003930 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003931 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003932 }
Adam Cohen7777d962011-08-18 18:58:38 -07003933
Adam Cohenad4e15c2013-10-17 16:21:35 -07003934 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003935 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003936 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3937
Winson Chunge7a03942011-08-05 15:05:12 -07003938 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003939 @Override
3940 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003941 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003942 // Before we show workspace, hide all apps again because
3943 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3944 // clean up our state transition functions
3945 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003946 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003947 } else {
3948 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003949 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003950 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003951 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003952 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003953
Michael Jurkad3ef3062010-11-23 16:23:58 -08003954 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003955 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003956 final boolean animated = true;
3957 final boolean springLoaded = true;
3958 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003959 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003960 }
3961 // Otherwise, we are not in spring loaded mode, so don't do anything.
3962 }
3963
Michael Jurkab3e22d92011-10-31 15:58:33 -07003964 void lockAllApps() {
3965 // TODO
3966 }
3967
3968 void unlockAllApps() {
3969 // TODO
3970 }
3971
Sunny Goyal594d76d2014-11-06 10:12:54 -08003972 protected void disableVoiceButtonProxy(boolean disable) {
3973 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003974 }
3975
Cristina Stancu476493b2013-08-07 17:20:14 +01003976 public View getQsbBar() {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003977 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
3978 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003979 }
3980
Adam Cohen24ce0b32014-01-14 16:18:14 -08003981 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003982 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3983 if (searchProvider == null) {
3984 return null;
3985 }
3986
3987 Bundle opts = new Bundle();
3988 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
3989 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
3990
3991 SharedPreferences sp = getSharedPreferences(
3992 LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
3993 int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003994 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003995 if (!searchProvider.provider.flattenToString().equals(
3996 sp.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003997 || (widgetInfo == null)
3998 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003999 // A valid widget is not already bound.
4000 if (widgetId > -1) {
4001 mAppWidgetHost.deleteAppWidgetId(widgetId);
4002 widgetId = -1;
4003 }
4004
4005 // Try to bind a new widget
4006 widgetId = mAppWidgetHost.allocateAppWidgetId();
4007
4008 if (!AppWidgetManagerCompat.getInstance(this)
4009 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
4010 mAppWidgetHost.deleteAppWidgetId(widgetId);
4011 widgetId = -1;
4012 }
4013
4014 sp.edit()
4015 .putInt(QSB_WIDGET_ID, widgetId)
4016 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
4017 .commit();
4018 }
4019
4020 if (widgetId != -1) {
4021 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
4022 mQsb.updateAppWidgetOptions(opts);
4023 mQsb.setPadding(0, 0, 0, 0);
4024 mSearchDropTargetBar.addView(mQsb);
4025 }
Cristina Stancu476493b2013-08-07 17:20:14 +01004026 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08004027 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01004028 }
4029
Michael Jurkad7c28052012-04-27 15:43:36 -07004030 @Override
4031 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004032 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004033 final List<CharSequence> text = event.getText();
4034 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004035 // Populate event with a fake title based on the current state.
4036 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004037 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004038 } else {
4039 text.add(getString(R.string.all_apps_home_button_label));
4040 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004041 return result;
4042 }
4043
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004044 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004045 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004046 */
4047 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4048 @Override
4049 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004050 closeSystemDialogs();
4051 }
4052 }
4053
4054 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004055 * Receives notifications whenever the appwidgets are reset.
4056 */
4057 private class AppWidgetResetObserver extends ContentObserver {
4058 public AppWidgetResetObserver() {
4059 super(new Handler());
4060 }
4061
4062 @Override
4063 public void onChange(boolean selfChange) {
4064 onAppWidgetReset();
4065 }
4066 }
4067
4068 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004069 * If the activity is currently paused, signal that we need to run the passed Runnable
4070 * in onResume.
4071 *
4072 * This needs to be called from incoming places where resources might have been loaded
4073 * while we are paused. That is becaues the Configuration might be wrong
4074 * when we're not running, and if it comes back to what it was when we
4075 * were paused, we are not restarted.
4076 *
4077 * Implementation of the method from LauncherModel.Callbacks.
4078 *
4079 * @return true if we are currently paused. The caller might be able to
4080 * skip some work in that case since we will come back again.
4081 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004082 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004083 if (mPaused) {
4084 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004085 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004086 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004087 }
4088 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004089 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004090 return true;
4091 } else {
4092 return false;
4093 }
4094 }
4095
Michael Jurkac402cd92013-05-20 15:49:32 +02004096 private boolean waitUntilResume(Runnable run) {
4097 return waitUntilResume(run, false);
4098 }
4099
Michael Jurka1e2f4652013-07-08 18:03:46 -07004100 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004101 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004102 }
4103
Michael Jurka7607c2f2013-04-03 14:33:19 -07004104 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004105 * If the activity is currently paused, signal that we need to re-run the loader
4106 * in onResume.
4107 *
4108 * This needs to be called from incoming places where resources might have been loaded
4109 * while we are paused. That is becaues the Configuration might be wrong
4110 * when we're not running, and if it comes back to what it was when we
4111 * were paused, we are not restarted.
4112 *
4113 * Implementation of the method from LauncherModel.Callbacks.
4114 *
4115 * @return true if we are currently paused. The caller might be able to
4116 * skip some work in that case since we will come back again.
4117 */
4118 public boolean setLoadOnResume() {
4119 if (mPaused) {
4120 Log.i(TAG, "setLoadOnResume");
4121 mOnResumeNeedsLoad = true;
4122 return true;
4123 } else {
4124 return false;
4125 }
4126 }
4127
4128 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004129 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004130 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004131 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004132 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004133 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004134 } else {
4135 return SCREEN_COUNT / 2;
4136 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004137 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004138
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 /**
4140 * Refreshes the shortcuts shown on the workspace.
4141 *
4142 * Implementation of the method from LauncherModel.Callbacks.
4143 */
4144 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004145 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004146
Michael Jurka7607c2f2013-04-03 14:33:19 -07004147 // If we're starting binding all over again, clear any bind calls we'd postponed in
4148 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4149 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004150 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004151
Winson Chungd64d1762013-08-20 14:37:16 -07004152 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004153 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004154 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004155
Michael Jurka05bf6442011-11-30 20:28:53 -08004156 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004157 if (mHotseat != null) {
4158 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004159 }
4160 }
4161
Adam Cohendcd297f2013-06-18 13:13:40 -07004162 @Override
4163 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004164 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004165
Adam Cohen5084cba2013-09-03 12:01:16 -07004166 // If there are no screens, we need to have an empty screen
4167 if (orderedScreenIds.size() == 0) {
4168 mWorkspace.addExtraEmptyScreen();
4169 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004170
4171 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004172 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004173 if (hasCustomContentToLeft()) {
4174 mWorkspace.createCustomContentContainer();
4175 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004176 }
Winson Chung64359a52013-07-08 17:17:08 -07004177 }
4178
4179 @Override
4180 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004181 // Log to disk
4182 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4183 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4184 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004185 int count = orderedScreenIds.size();
4186 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004187 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004188 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004189 }
4190
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08004191 @Override
4192 public void bindAddPendingItem(final PendingAddItemInfo info, final long container,
4193 final long screenId, final int[] cell, final int spanX, final int spanY) {
4194 showWorkspace(true, new Runnable() {
4195
4196 @Override
4197 public void run() {
4198 mWorkspace.snapToPage(mWorkspace.getPageIndexForScreenId(screenId));
4199 addPendingItem(info, container, screenId, cell, spanX, spanY);
4200 }
4201 });
4202 }
4203
Adam Cohen39a06042013-07-19 14:30:12 -07004204 private boolean shouldShowWeightWatcher() {
4205 String spKey = LauncherAppState.getSharedPreferencesKey();
4206 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004207 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004208
4209 return show;
4210 }
4211
4212 private void toggleShowWeightWatcher() {
4213 String spKey = LauncherAppState.getSharedPreferencesKey();
4214 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4215 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4216
4217 show = !show;
4218
4219 SharedPreferences.Editor editor = sp.edit();
4220 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4221 editor.commit();
4222
4223 if (mWeightWatcher != null) {
4224 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4225 }
4226 }
4227
Winson Chungd64d1762013-08-20 14:37:16 -07004228 public void bindAppsAdded(final ArrayList<Long> newScreens,
4229 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004230 final ArrayList<ItemInfo> addAnimated,
4231 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004232 Runnable r = new Runnable() {
4233 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004234 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004235 }
4236 };
4237 if (waitUntilResume(r)) {
4238 return;
4239 }
4240
Winson Chungd64d1762013-08-20 14:37:16 -07004241 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004242 if (newScreens != null) {
4243 bindAddScreens(newScreens);
4244 }
Winson Chungd64d1762013-08-20 14:37:16 -07004245
4246 // We add the items without animation on non-visible pages, and with
4247 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004248 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004249 bindItems(addNotAnimated, 0,
4250 addNotAnimated.size(), false);
4251 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004252 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004253 bindItems(addAnimated, 0,
4254 addAnimated.size(), true);
4255 }
Winson Chungc58497e2013-09-03 17:48:37 -07004256
Winson Chung87412982013-10-03 18:34:14 -07004257 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004258 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004259
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004260 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004261 addedApps != null && mAppsCustomizeContent != null) {
4262 mAppsCustomizeContent.addApps(addedApps);
4263 }
Winson Chungd64d1762013-08-20 14:37:16 -07004264 }
4265
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004266 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004267 * Bind the items start-end from the list.
4268 *
4269 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004270 */
Winson Chung64359a52013-07-08 17:17:08 -07004271 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4272 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004273 Runnable r = new Runnable() {
4274 public void run() {
4275 bindItems(shortcuts, start, end, forceAnimateIcons);
4276 }
4277 };
4278 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004279 return;
4280 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004281
Winson Chungf0c6ae02012-03-21 16:10:31 -07004282 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004283 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4284 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004285 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004286 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004287 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004288 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004289 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004290
4291 // Short circuit if we are loading dock items for a configuration which has no dock
4292 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4293 mHotseat == null) {
4294 continue;
4295 }
4296
Joe Onorato9c1289c2009-08-17 11:03:03 -04004297 switch (item.itemType) {
4298 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4299 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004300 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004301 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004302
Winson Chung64359a52013-07-08 17:17:08 -07004303 /*
4304 * TODO: FIX collision case
4305 */
Winson Chungce376632013-07-11 16:12:41 -07004306 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4307 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4308 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004309 View v = cl.getChildAt(item.cellX, item.cellY);
4310 Object tag = v.getTag();
4311 String desc = "Collision while binding workspace item: " + item
4312 + ". Collides with " + tag;
4313 if (LauncherAppState.isDogfoodBuild()) {
4314 throw (new RuntimeException(desc));
4315 } else {
4316 Log.d(TAG, desc);
4317 }
Winson Chungce376632013-07-11 16:12:41 -07004318 }
Winson Chung64359a52013-07-08 17:17:08 -07004319 }
4320
Adam Cohendcd297f2013-06-18 13:13:40 -07004321 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4322 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004323 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004324 // Animate all the applications up now
4325 shortcut.setAlpha(0f);
4326 shortcut.setScaleX(0f);
4327 shortcut.setScaleY(0f);
4328 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004329 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004330 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004331 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004332 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004333 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004334 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004335 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004336 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4337 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004338 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004339 default:
4340 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004341 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004342 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004343
Winson Chung997a9232013-07-24 15:33:46 -07004344 if (animateIcons) {
4345 // Animate to the correct page
4346 if (newShortcutsScreenId > -1) {
4347 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004348 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004349 final Runnable startBounceAnimRunnable = new Runnable() {
4350 public void run() {
4351 anim.playTogether(bounceAnims);
4352 anim.start();
4353 }
4354 };
Winson Chung997a9232013-07-24 15:33:46 -07004355 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004356 // We post the animation slightly delayed to prevent slowdowns
4357 // when we are loading right after we return to launcher.
4358 mWorkspace.postDelayed(new Runnable() {
4359 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004360 if (mWorkspace != null) {
4361 mWorkspace.snapToPage(newScreenIndex);
4362 mWorkspace.postDelayed(startBounceAnimRunnable,
4363 NEW_APPS_ANIMATION_DELAY);
4364 }
Winson Chung94d67682013-09-25 16:29:40 -07004365 }
4366 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004367 } else {
4368 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004369 }
4370 }
Winson Chung64359a52013-07-08 17:17:08 -07004371 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004372 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004373 }
4374
Joe Onorato9c1289c2009-08-17 11:03:03 -04004375 /**
4376 * Implementation of the method from LauncherModel.Callbacks.
4377 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004378 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004379 Runnable r = new Runnable() {
4380 public void run() {
4381 bindFolders(folders);
4382 }
4383 };
4384 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004385 return;
4386 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004387 sFolders.clear();
4388 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004389 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004390
4391 /**
4392 * Add the views for a widget to the workspace.
4393 *
4394 * Implementation of the method from LauncherModel.Callbacks.
4395 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004396 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004397 Runnable r = new Runnable() {
4398 public void run() {
4399 bindAppWidget(item);
4400 }
4401 };
4402 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004403 return;
4404 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004405
Daniel Sandler843e8602010-06-07 14:59:01 -04004406 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4407 if (DEBUG_WIDGETS) {
4408 Log.d(TAG, "bindAppWidget: " + item);
4409 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004410 final Workspace workspace = mWorkspace;
4411
Adam Cohen59400422014-03-05 18:07:04 -08004412 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee2dd9f012015-03-16 19:41:43 +00004413 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08004414
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004415 if (!mIsSafeModeEnabled
4416 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
4417 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
Sunny Goyalff572272014-07-23 13:58:07 -07004418 if (appWidgetInfo == null) {
4419 if (DEBUG_WIDGETS) {
4420 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4421 + " belongs to component " + item.providerName
4422 + ", as the povider is null");
4423 }
4424 LauncherModel.deleteItemFromDatabase(this, item);
4425 return;
4426 }
4427 // Note: This assumes that the id remap broadcast is received before this step.
4428 // If that is not the case, the id remap will be ignored and user may see the
4429 // click to setup view.
Adam Cohen59400422014-03-05 18:07:04 -08004430 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null);
Sunny Goyalff572272014-07-23 13:58:07 -07004431 pendingInfo.spanX = item.spanX;
4432 pendingInfo.spanY = item.spanY;
4433 pendingInfo.minSpanX = item.minSpanX;
4434 pendingInfo.minSpanY = item.minSpanY;
4435 Bundle options =
4436 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4437
Sunny Goyalff572272014-07-23 13:58:07 -07004438 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004439 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4440 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004441
4442 // TODO consider showing a permission dialog when the widget is clicked.
4443 if (!success) {
4444 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4445 if (DEBUG_WIDGETS) {
4446 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4447 + " belongs to component " + item.providerName
4448 + ", as the launcher is unable to bing a new widget id");
4449 }
4450 LauncherModel.deleteItemFromDatabase(this, item);
4451 return;
4452 }
4453
4454 item.appWidgetId = newWidgetId;
4455
4456 // If the widget has a configure activity, it is still needs to set it up, otherwise
4457 // the widget is ready to go.
4458 item.restoreStatus = (appWidgetInfo.configure == null)
4459 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4460 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4461
4462 LauncherModel.updateItemInDatabase(this, item);
4463 }
4464
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004465 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004466 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004467 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004468 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4469 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004470 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004471
Sunny Goyal651077b2014-06-30 14:15:31 -07004472 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4473 } else {
4474 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004475 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4476 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004477 view.updateIcon(mIconCache);
4478 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004479 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004480 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004481 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004482
Joe Onorato9c1289c2009-08-17 11:03:03 -04004483 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004484 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004485
Adam Cohendcd297f2013-06-18 13:13:40 -07004486 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004487 item.cellY, item.spanX, item.spanY, false);
Adam Cohen59400422014-03-05 18:07:04 -08004488 if (!item.isCustomWidget()) {
4489 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4490 }
Adam Cohended9f8d2010-11-03 13:25:16 -07004491
Joe Onorato9c1289c2009-08-17 11:03:03 -04004492 workspace.requestLayout();
4493
Daniel Sandler843e8602010-06-07 14:59:01 -04004494 if (DEBUG_WIDGETS) {
4495 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4496 + (SystemClock.uptimeMillis()-start) + "ms");
4497 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004498 }
4499
Sunny Goyalff572272014-07-23 13:58:07 -07004500 /**
4501 * Restores a pending widget.
4502 *
4503 * @param appWidgetId The app widget id
4504 * @param cellInfo The position on screen where to create the widget.
4505 */
4506 private void completeRestoreAppWidget(final int appWidgetId) {
4507 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4508 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4509 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4510 return;
4511 }
4512
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004513 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004514 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4515
4516 mWorkspace.reinflateWidgetsIfNecessary();
4517 LauncherModel.updateItemInDatabase(this, info);
4518 }
4519
Adam Cohen1462de32012-07-24 22:34:36 -07004520 public void onPageBoundSynchronously(int page) {
4521 mSynchronouslyBoundPages.add(page);
4522 }
4523
Joe Onorato9c1289c2009-08-17 11:03:03 -04004524 /**
4525 * Callback saying that there aren't any more items to bind.
4526 *
4527 * Implementation of the method from LauncherModel.Callbacks.
4528 */
Adam Cohene25af792013-06-06 23:08:25 -07004529 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004530 Runnable r = new Runnable() {
4531 public void run() {
4532 finishBindingItems(upgradePath);
4533 }
4534 };
4535 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004536 return;
4537 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004538 if (mSavedState != null) {
4539 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004540 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004541 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004542 mSavedState = null;
4543 }
4544
Adam Cohen1462de32012-07-24 22:34:36 -07004545 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004546
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004547 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004548 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004549
4550 // If we received the result of any pending adds while the loader was running (e.g. the
4551 // widget configuration forced an orientation change), process them now.
4552 if (sPendingAddItem != null) {
4553 final long screenId = completeAdd(sPendingAddItem);
4554
4555 // TODO: this moves the user to the page where the pending item was added. Ideally,
4556 // the screen would be guaranteed to exist after bind, and the page would be set through
4557 // the workspace restore process.
4558 mWorkspace.post(new Runnable() {
4559 @Override
4560 public void run() {
4561 mWorkspace.snapToScreenId(screenId);
4562 }
4563 });
4564 sPendingAddItem = null;
4565 }
4566
Adam Cohene25af792013-06-06 23:08:25 -07004567 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004568 mWorkspace.getUniqueComponents(true, null);
4569 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004570 }
Sunny Goyale755d462014-07-22 13:48:29 -07004571 PackageInstallerCompat.getInstance(this).onFinishBind();
Adam Cohen9211d422014-10-07 18:14:53 -07004572
4573 if (mLauncherCallbacks != null) {
4574 mLauncherCallbacks.finishBindingItems(upgradePath);
4575 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004576 }
4577
Adam Cohen3ed316a2014-07-23 18:21:20 -07004578 private void sendLoadingCompleteBroadcastIfNecessary() {
4579 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4580 String permission =
4581 getResources().getString(R.string.receive_first_load_broadcast_permission);
4582 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4583 sendBroadcast(intent, permission);
4584 SharedPreferences.Editor editor = mSharedPrefs.edit();
4585 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4586 editor.apply();
4587 }
4588 }
4589
Winson Chunga0b7e862013-09-05 16:03:15 -07004590 public boolean isAllAppsButtonRank(int rank) {
4591 if (mHotseat != null) {
4592 return mHotseat.isAllAppsButtonRank(rank);
4593 }
4594 return false;
4595 }
4596
Winson Chunga2413752012-04-03 14:22:34 -07004597 private boolean canRunNewAppsAnimation() {
4598 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4599 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4600 }
4601
Winson Chungc9168342013-06-26 14:54:55 -07004602 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4603 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4604 PropertyValuesHolder.ofFloat("alpha", 1f),
4605 PropertyValuesHolder.ofFloat("scaleX", 1f),
4606 PropertyValuesHolder.ofFloat("scaleY", 1f));
4607 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4608 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4609 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4610 return bounceAnim;
4611 }
4612
Adam Cohen27772732013-11-11 14:00:56 +00004613 public boolean useVerticalBarLayout() {
4614 return LauncherAppState.getInstance().getDynamicGrid().
4615 getDeviceProfile().isVerticalBarLayout();
4616 }
4617
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004618 protected Rect getSearchBarBounds() {
4619 return LauncherAppState.getInstance().getDynamicGrid().
4620 getDeviceProfile().getSearchBarBounds();
4621 }
4622
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004623 public void bindSearchablesChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004624 if (mSearchDropTargetBar == null) {
4625 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004626 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004627 if (mQsb != null) {
4628 mSearchDropTargetBar.removeView(mQsb);
4629 mQsb = null;
4630 }
4631 mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004632 }
4633
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004634 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004635 * Add the icons for all apps.
4636 *
4637 * Implementation of the method from LauncherModel.Callbacks.
4638 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004639 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004640 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004641 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4642 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4643 getHotseat().addAllAppsFolder(mIconCache, apps,
4644 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4645 }
4646 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004647 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004648 if (mAppsCustomizeContent != null) {
4649 mAppsCustomizeContent.onPackagesUpdated(
Hyunyoung Songfe1dcbf2015-03-11 16:36:52 -07004650 LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */));
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004651 }
Winson Chungc58497e2013-09-03 17:48:37 -07004652 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004653 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004654 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004655 mAppsCustomizeContent.onPackagesUpdated(
Hyunyoung Songfe1dcbf2015-03-11 16:36:52 -07004656 LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */));
Winson Chungc58497e2013-09-03 17:48:37 -07004657 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004658 }
Adam Cohen9211d422014-10-07 18:14:53 -07004659 if (mLauncherCallbacks != null) {
4660 mLauncherCallbacks.bindAllApplications(apps);
4661 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004662 }
4663
4664 /**
4665 * A package was updated.
4666 *
4667 * Implementation of the method from LauncherModel.Callbacks.
4668 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004669 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004670 Runnable r = new Runnable() {
4671 public void run() {
4672 bindAppsUpdated(apps);
4673 }
4674 };
4675 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004676 return;
4677 }
4678
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004679 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004680 mAppsCustomizeContent != null) {
4681 mAppsCustomizeContent.updateApps(apps);
4682 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004683 }
4684
Sunny Goyal4390ace2014-10-13 11:33:11 -07004685 @Override
4686 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4687 Runnable r = new Runnable() {
4688 public void run() {
4689 bindWidgetsRestored(widgets);
4690 }
4691 };
4692 if (waitUntilResume(r)) {
4693 return;
4694 }
4695 mWorkspace.widgetsRestored(widgets);
4696 }
4697
Joe Onorato9c1289c2009-08-17 11:03:03 -04004698 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004699 * Some shortcuts were updated in the background.
4700 *
4701 * Implementation of the method from LauncherModel.Callbacks.
4702 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004703 @Override
4704 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4705 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004706 Runnable r = new Runnable() {
4707 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004708 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004709 }
4710 };
4711 if (waitUntilResume(r)) {
4712 return;
4713 }
4714
Sunny Goyal4390ace2014-10-13 11:33:11 -07004715 if (!updated.isEmpty()) {
4716 mWorkspace.updateShortcuts(updated);
4717 }
4718
4719 if (!removed.isEmpty()) {
4720 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4721 for (ShortcutInfo si : removed) {
4722 removedComponents.add(si.getTargetComponent());
4723 }
4724 mWorkspace.removeItemsByComponentName(removedComponents, user);
4725 // Notify the drag controller
4726 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004727 }
4728 }
4729
4730 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004731 * Update the state of a package, typically related to install state.
4732 *
4733 * Implementation of the method from LauncherModel.Callbacks.
4734 */
Sunny Goyale755d462014-07-22 13:48:29 -07004735 @Override
4736 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004737 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004738 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004739 }
4740 }
4741
4742 /**
Sunny Goyala22666f2014-09-18 13:25:15 -07004743 * Update the label and icon of all the icons in a package
4744 *
4745 * Implementation of the method from LauncherModel.Callbacks.
4746 */
4747 @Override
4748 public void updatePackageBadge(String packageName) {
4749 if (mWorkspace != null) {
4750 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4751 }
4752 }
4753
4754 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004755 * A package was uninstalled. We take both the super set of packageNames
4756 * in addition to specific applications to remove, the reason being that
4757 * this can be called when a package is updated as well. In that scenario,
4758 * we only remove specific components from the workspace, where as
4759 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004760 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004761 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004762 * Implementation of the method from LauncherModel.Callbacks.
4763 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004764 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004765 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004766 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004767 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004768 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004769 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004770 }
Winson Chungd64d1762013-08-20 14:37:16 -07004771 };
4772 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004773 return;
4774 }
4775
Sunny Goyal1a745e82014-10-02 15:58:31 -07004776 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004777 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4778 for (AppInfo info : appInfos) {
4779 removedComponents.add(info.componentName);
4780 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004781 if (!packageNames.isEmpty()) {
4782 mWorkspace.removeItemsByPackageName(packageNames, user);
4783 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004784 if (!removedComponents.isEmpty()) {
4785 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004786 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004787 // Notify the drag controller
4788 mDragController.onAppsRemoved(packageNames, removedComponents);
4789
Sunny Goyal1a745e82014-10-02 15:58:31 -07004790 } else {
4791 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004792 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004793
Winson Chungdf95eb12013-10-16 14:57:07 -07004794 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004795 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004796 mAppsCustomizeContent != null) {
4797 mAppsCustomizeContent.removeApps(appInfos);
4798 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004799 }
Joe Onoratobe386092009-11-17 17:32:16 -08004800
4801 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004802 * A number of packages were updated.
4803 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004804 private ArrayList<Object> mWidgetsAndShortcuts;
4805 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004806 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004807 bindPackagesUpdated(mWidgetsAndShortcuts);
4808 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004809 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004810 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004811 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4812 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4813 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004814 return;
4815 }
4816
Winson Chung64359a52013-07-08 17:17:08 -07004817 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004818 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004819 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004820 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004821 }
4822
Winson Chung400438b2011-01-16 17:53:48 -08004823 private int mapConfigurationOriActivityInfoOri(int configOri) {
4824 final Display d = getWindowManager().getDefaultDisplay();
4825 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4826 switch (d.getRotation()) {
4827 case Surface.ROTATION_0:
4828 case Surface.ROTATION_180:
4829 // We are currently in the same basic orientation as the natural orientation
4830 naturalOri = configOri;
4831 break;
4832 case Surface.ROTATION_90:
4833 case Surface.ROTATION_270:
4834 // We are currently in the other basic orientation to the natural orientation
4835 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4836 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4837 break;
4838 }
4839
4840 int[] oriMap = {
4841 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4842 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4843 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4844 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4845 };
4846 // Since the map starts at portrait, we need to offset if this device's natural orientation
4847 // is landscape.
4848 int indexOffset = 0;
4849 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4850 indexOffset = 1;
4851 }
4852 return oriMap[(d.getRotation() + indexOffset) % 4];
4853 }
Adam Cohen446e9402011-09-15 18:21:21 -07004854
Winson Chung4b919f82012-05-01 10:44:08 -07004855 public void lockScreenOrientation() {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004856 if (Utilities.isRotationEnabled(this)) {
Sunny Goyal7470c812015-02-10 14:28:44 -08004857 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
4858 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4859 .getConfiguration().orientation));
4860 } else {
4861 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4862 }
Winson Chung4b919f82012-05-01 10:44:08 -07004863 }
4864 }
4865 public void unlockScreenOrientation(boolean immediate) {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004866 if (Utilities.isRotationEnabled(this)) {
Winson Chung4b919f82012-05-01 10:44:08 -07004867 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004868 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004869 } else {
4870 mHandler.postDelayed(new Runnable() {
4871 public void run() {
4872 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4873 }
4874 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004875 }
Winson Chung4b919f82012-05-01 10:44:08 -07004876 }
Winson Chung400438b2011-01-16 17:53:48 -08004877 }
4878
Winson Chunge43a1e72014-01-15 10:33:02 -08004879 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004880 if (mLauncherCallbacks != null) {
4881 return mLauncherCallbacks.isLauncherPreinstalled();
4882 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004883 PackageManager pm = getPackageManager();
4884 try {
4885 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4886 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4887 return true;
4888 } else {
4889 return false;
4890 }
4891 } catch (NameNotFoundException e) {
4892 e.printStackTrace();
4893 return false;
4894 }
4895 }
4896
Adam Cohenea90f832014-05-21 15:03:34 -07004897 /**
4898 * This method indicates whether or not we should suggest default wallpaper dimensions
4899 * when our wallpaper cropper was not yet used to set a wallpaper.
4900 */
4901 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004902 if (mLauncherCallbacks != null) {
4903 return mLauncherCallbacks.overrideWallpaperDimensions();
4904 }
Adam Cohenea90f832014-05-21 15:03:34 -07004905 return true;
4906 }
4907
Adam Cohen432609a2014-03-13 17:03:22 -07004908 /**
4909 * To be overridden by subclasses to indicate that there is an activity to launch
4910 * before showing the standard launcher experience.
4911 */
4912 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004913 if (mLauncherCallbacks != null) {
4914 return mLauncherCallbacks.hasFirstRunActivity();
4915 }
Adam Cohen432609a2014-03-13 17:03:22 -07004916 return false;
4917 }
4918
4919 /**
4920 * To be overridden by subclasses to launch any first run activity
4921 */
4922 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004923 if (mLauncherCallbacks != null) {
4924 return mLauncherCallbacks.getFirstRunActivity();
4925 }
Adam Cohen432609a2014-03-13 17:03:22 -07004926 return null;
4927 }
4928
Winson Chunga6945242014-01-08 14:04:34 -08004929 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004930 return !ActivityManager.isRunningInTestHarness() &&
4931 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004932 }
4933
Adam Cohen4a9423d2014-03-28 14:22:31 -07004934 protected boolean hasRunFirstRunActivity() {
4935 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4936 }
4937
Adam Cohen432609a2014-03-13 17:03:22 -07004938 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004939 if (shouldRunFirstRunActivity() &&
4940 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004941 Intent firstRunIntent = getFirstRunActivity();
4942 if (firstRunIntent != null) {
4943 startActivity(firstRunIntent);
4944 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004945 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004946 }
4947 }
Adam Cohen432609a2014-03-13 17:03:22 -07004948 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004949 }
4950
4951 private void markFirstRunActivityShown() {
4952 SharedPreferences.Editor editor = mSharedPrefs.edit();
4953 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4954 editor.apply();
4955 }
4956
Adam Cohen432609a2014-03-13 17:03:22 -07004957 /**
4958 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4959 * screen that must be displayed and dismissed.
4960 */
4961 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004962 if (mLauncherCallbacks != null) {
4963 return mLauncherCallbacks.hasDismissableIntroScreen();
4964 }
Adam Cohen432609a2014-03-13 17:03:22 -07004965 return false;
4966 }
4967
4968 /**
4969 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4970 */
4971 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004972 if (mLauncherCallbacks != null) {
4973 return mLauncherCallbacks.getIntroScreen();
4974 }
Adam Cohen432609a2014-03-13 17:03:22 -07004975 return null;
4976 }
4977
4978 /**
4979 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4980 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4981 */
4982 private boolean shouldShowIntroScreen() {
4983 return hasDismissableIntroScreen() &&
4984 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4985 }
4986
4987 protected void showIntroScreen() {
4988 View introScreen = getIntroScreen();
4989 changeWallpaperVisiblity(false);
4990 if (introScreen != null) {
4991 mDragLayer.showOverlayView(introScreen);
4992 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004993 if (mLauncherOverlayContainer != null) {
4994 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4995 }
Adam Cohen432609a2014-03-13 17:03:22 -07004996 }
4997
4998 public void dismissIntroScreen() {
4999 markIntroScreenDismissed();
5000 if (showFirstRunActivity()) {
5001 // We delay hiding the intro view until the first run activity is showing. This
5002 // avoids a blip.
5003 mWorkspace.postDelayed(new Runnable() {
5004 @Override
5005 public void run() {
5006 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07005007 if (mLauncherOverlayContainer != null) {
5008 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
5009 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07005010 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07005011 }
5012 }, ACTIVITY_START_DELAY);
5013 } else {
5014 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07005015 if (mLauncherOverlayContainer != null) {
5016 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
5017 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07005018 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07005019 }
5020 changeWallpaperVisiblity(true);
5021 }
5022
5023 private void markIntroScreenDismissed() {
5024 SharedPreferences.Editor editor = mSharedPrefs.edit();
5025 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5026 editor.apply();
5027 }
5028
Sunny Goyal88d60f12014-09-08 03:47:29 -07005029 private void showFirstRunClings() {
5030 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
5031 // on the device, then we always show the first run cling experience (or if there is no
5032 // launcher2). Otherwise, we prompt the user upon started for migration
5033 LauncherClings launcherClings = new LauncherClings(this);
5034 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5035 if (mModel.canMigrateFromOldLauncherDb(this)) {
5036 launcherClings.showMigrationCling();
5037 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07005038 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07005039 }
5040 }
5041 }
5042
Winson Chunga6945242014-01-08 14:04:34 -08005043 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005044 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5045 if (mHotseat != null) mHotseat.setAlpha(1f);
5046 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5047 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005048 }
5049
5050 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005051 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5052 if (mHotseat != null) mHotseat.setAlpha(0f);
5053 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5054 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005055 }
5056
Mathew Inwood72fbec12013-11-19 15:45:07 +00005057 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01005058 // Called from search suggestion, not supported in other profiles.
5059 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5060 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5061 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5062 myUser);
5063 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00005064 return null;
5065 }
Kenny Guyed131872014-04-30 03:02:21 +01005066 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005067 }
5068
5069 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5070 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01005071 // Called from search suggestion, not supported in other profiles.
5072 return createShortcutDragInfo(shortcutIntent, caption, icon,
5073 UserHandleCompat.myUserHandle());
5074 }
5075
5076 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5077 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01005078 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005079 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005080 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005081 }
5082
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005083 protected void moveWorkspaceToDefaultScreen() {
5084 mWorkspace.moveToDefaultScreen(false);
5085 }
5086
Mathew Inwood72fbec12013-11-19 15:45:07 +00005087 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5088 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005089 mWorkspace.onExternalDragStartedWithItem(dragView);
5090 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005091 }
5092
Anjali Koppalf5d29132014-02-28 13:33:27 -08005093 @Override
5094 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07005095 if (mLauncherCallbacks != null) {
5096 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
5097 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08005098 }
5099
Winson Chung80baf5a2010-08-09 16:03:15 -07005100 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005101 * Prints out out state for debugging.
5102 */
5103 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005104 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005105 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005106 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5107 Log.d(TAG, "mRestoring=" + mRestoring);
5108 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5109 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005110 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005111 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005112
Winson Chung785d2eb2011-04-14 16:08:02 -07005113 if (mAppsCustomizeContent != null) {
5114 mAppsCustomizeContent.dumpState();
5115 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005116 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005117 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005118
5119 @Override
5120 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5121 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005122 synchronized (sDumpLogs) {
5123 writer.println(" ");
5124 writer.println("Debug logs: ");
5125 for (int i = 0; i < sDumpLogs.size(); i++) {
5126 writer.println(" " + sDumpLogs.get(i));
5127 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005128 }
Adam Cohen9211d422014-10-07 18:14:53 -07005129 if (mLauncherCallbacks != null) {
5130 mLauncherCallbacks.dump(prefix, fd, writer, args);
5131 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005132 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005133
5134 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005135 if (DEBUG_DUMP_LOG) {
5136 synchronized (sDumpLogs) {
5137 Log.d(TAG, "");
5138 Log.d(TAG, "*********************");
5139 Log.d(TAG, "Launcher debug logs: ");
5140 for (int i = 0; i < sDumpLogs.size(); i++) {
5141 Log.d(TAG, " " + sDumpLogs.get(i));
5142 }
5143 Log.d(TAG, "*********************");
5144 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005145 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005146 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005147 }
5148
5149 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005150 addDumpLog(tag, log, null, debugLog);
5151 }
5152
5153 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005154 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005155 if (e != null) {
5156 Log.d(tag, log, e);
5157 } else {
5158 Log.d(tag, log);
5159 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005160 }
Winson Chungede41292013-09-19 16:27:36 -07005161 if (DEBUG_DUMP_LOG) {
5162 sDateStamp.setTime(System.currentTimeMillis());
5163 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005164 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5165 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005166 }
Winson Chungede41292013-09-19 16:27:36 -07005167 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005168 }
5169
Adam Cohen59400422014-03-05 18:07:04 -08005170 public static CustomAppWidget getCustomAppWidget(String name) {
5171 return sCustomAppWidgets.get(name);
5172 }
5173
5174 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
5175 return sCustomAppWidgets;
5176 }
5177
Winson Chungede41292013-09-19 16:27:36 -07005178 public void dumpLogsToLocalData() {
5179 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005180 new AsyncTask<Void, Void, Void>() {
5181 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005182 boolean success = false;
5183 sDateStamp.setTime(sRunStart);
5184 String FILENAME = sDateStamp.getMonth() + "-"
5185 + sDateStamp.getDay() + "_"
5186 + sDateStamp.getHours() + "-"
5187 + sDateStamp.getMinutes() + "_"
5188 + sDateStamp.getSeconds() + ".txt";
5189
5190 FileOutputStream fos = null;
5191 File outFile = null;
5192 try {
5193 outFile = new File(getFilesDir(), FILENAME);
5194 outFile.createNewFile();
5195 fos = new FileOutputStream(outFile);
5196 } catch (Exception e) {
5197 e.printStackTrace();
5198 }
5199 if (fos != null) {
5200 PrintWriter writer = new PrintWriter(fos);
5201
5202 writer.println(" ");
5203 writer.println("Debug logs: ");
5204 synchronized (sDumpLogs) {
5205 for (int i = 0; i < sDumpLogs.size(); i++) {
5206 writer.println(" " + sDumpLogs.get(i));
5207 }
5208 }
5209 writer.close();
5210 }
5211 try {
5212 if (fos != null) {
5213 fos.close();
5214 success = true;
5215 }
5216 } catch (IOException e) {
5217 e.printStackTrace();
5218 }
Michael Jurka43467462013-11-14 12:03:58 +01005219 return null;
Winson Chungede41292013-09-19 16:27:36 -07005220 }
Michael Jurka43467462013-11-14 12:03:58 +01005221 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005222 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005223 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005224}
Michael Jurka2763be32011-02-24 11:19:57 -08005225
Michael Jurkaabded662011-03-04 12:06:57 -08005226interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005227 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005228 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005229 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005230 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005231 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005232}
Dan Sandlerd5024042014-01-09 15:01:33 -05005233
5234interface DebugIntents {
5235 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5236 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005237}