blob: 88e1532d34f9295aef20cf3a43273e72ccf896da [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyal28c6b962015-10-12 11:42:05 -070019import android.Manifest;
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;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070025import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Sunny Goyal756cd262015-08-20 12:33:21 -070039import android.content.ContentValues;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Sunny Goyal745bad92016-05-02 10:54:12 -070046import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
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;
Adam Cohen3f9c9712014-10-31 11:48:25 -070052import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Tony Wickhama3c74d12015-10-23 11:43:47 -070056import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070057import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070059import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070060import android.graphics.drawable.Drawable;
Sunny Goyal1acb9e92016-05-16 12:41:09 -070061import 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;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070070import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.Selection;
72import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070073import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070075import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Tony Wickhame2217252016-03-22 16:34:23 -070089import android.view.accessibility.AccessibilityManager;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070090import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080094import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070096
Sunny Goyal651077b2014-06-30 14:15:31 -070097import com.android.launcher3.DropTarget.DragObject;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070098import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080099import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700100import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100101import com.android.launcher3.compat.LauncherActivityInfoCompat;
102import com.android.launcher3.compat.LauncherAppsCompat;
103import com.android.launcher3.compat.UserHandleCompat;
104import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800105import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700106import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700107import com.android.launcher3.dragndrop.DragController;
108import com.android.launcher3.dragndrop.DragLayer;
109import com.android.launcher3.dragndrop.DragView;
Tony Wickham827cef22016-03-17 15:39:39 -0700110import com.android.launcher3.dynamicui.ExtractedColors;
Sunny Goyal26119432016-02-18 22:09:23 +0000111import com.android.launcher3.folder.Folder;
112import com.android.launcher3.folder.FolderIcon;
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800113import com.android.launcher3.logging.LoggerUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700114import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700115import com.android.launcher3.model.WidgetsModel;
Tony Wickhamf549dab2016-05-16 09:54:06 -0700116import com.android.launcher3.pageindicators.PageIndicator;
117import com.android.launcher3.pageindicators.PageIndicatorLine;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800118import com.android.launcher3.userevent.nano.LauncherLogProto;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700119import com.android.launcher3.util.ComponentKey;
Sunny Goyal713edfc2016-05-06 09:58:34 -0700120import com.android.launcher3.logging.FileLog;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700121import com.android.launcher3.util.PackageManagerHelper;
Sunny Goyal322d5562015-06-25 19:35:49 -0700122import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700123import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700124import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700125import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700126import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700127import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700128
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700129import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700130import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700132import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800133import java.util.Collections;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700134import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700135import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700136import java.util.List;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800137import java.util.Locale;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700138
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139/**
140 * Default launcher application.
141 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100142public class Launcher extends Activity
Adam Cohen79d90c52016-04-22 13:29:20 -0700143 implements LauncherExterns, View.OnClickListener, OnLongClickListener,
144 LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener,
Tony Wickhame2217252016-03-22 16:34:23 -0700145 AccessibilityManager.AccessibilityStateChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700146 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700147 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Daniel Sandlerf061f822013-06-27 13:59:36 -0400149 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700150 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700151 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400152 static final boolean DEBUG_RESUME_TIME = false;
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700153 static final boolean DEBUG_LOGGING = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700154
Dan Sandlerd5024042014-01-09 15:01:33 -0500155 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
156
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700158 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700159 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700160 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161
Michael Jurka8b805b12012-04-18 14:23:14 -0700162 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700163 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700164
Sunny Goyal28c6b962015-10-12 11:42:05 -0700165 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
166
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700167 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
168 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
169 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
170
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700171 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
172
Mathew Inwood876a8462013-06-14 14:12:41 +0100173 /**
174 * IntentStarter uses request codes starting with this. This must be greater than all activity
175 * request codes used internally.
176 */
177 protected static final int REQUEST_LAST = 100;
178
Michael Jurka0a457bf2012-11-19 14:05:05 -0800179 // To turn on these properties, type
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700180 // adb shell setprop logTap.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800181 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182
Winson Chung2672ff92012-05-04 16:22:30 -0700183 // The Intent extra that defines whether to ignore the launch animation
184 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400185 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700186
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 // Type: int
188 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700189 // Type: int
190 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700191 // Type: Content Values / parcelable
192 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700193 // Type: parcelable
194 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000195 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800196 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
Adam Cohen432609a2014-03-13 17:03:22 -0700198 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800199 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
200
Sunny Goyal594d76d2014-11-06 10:12:54 -0800201 private static final String QSB_WIDGET_ID = "qsb_widget_id";
202 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
203
Winson Chunga6945242014-01-08 14:04:34 -0800204 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
Sunny Goyal1acb9e92016-05-16 12:41:09 -0700205 private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
Winson Chunga6945242014-01-08 14:04:34 -0800206
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700208 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
209 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700210
Adam Cohen091440a2015-03-18 14:16:05 -0700211 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700212 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700213
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700214 private boolean mIsSafeModeEnabled;
215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800217 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700218 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700219 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
Winson Chunga2413752012-04-03 14:22:34 -0700221 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700222 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
223 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700225
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800226 private final BroadcastReceiver mCloseSystemDialogsReceiver
227 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800228
Adam Cohen091440a2015-03-18 14:16:05 -0700229 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700230 private View mLauncherView;
Tony Wickhamf549dab2016-05-16 09:54:06 -0700231 private PageIndicatorLine mPageIndicator;
Adam Cohen091440a2015-03-18 14:16:05 -0700232 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800233 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700234
235 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Sunny Goyalffe83f12014-08-14 17:39:34 -0700237 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700238 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700239
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700240 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800241 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800242 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700243
Michael Jurka0280c3b2010-09-17 15:00:07 -0700244 private int[] mTmpAddItemCellCoordinates = new int[2];
245
Sunny Goyal316490e2015-06-02 09:38:28 -0700246 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800247 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700248
Michael Jurka838a4ca2011-02-07 13:33:06 -0800249 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700250 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700251
Winson Chungc51db6a2011-10-05 11:44:49 -0700252 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700253 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700254
255 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700256 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700257
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700258 // Main container view and the model for the widget tray screen.
259 @Thunk WidgetsContainerView mWidgetsView;
260 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700261
Sunny Goyal594d76d2014-11-06 10:12:54 -0800262 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700265 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
266 // scroll issues (because the workspace may not have been measured yet) and extra work.
267 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
268 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269
270 private SpannableStringBuilder mDefaultKeySsb = null;
271
Adam Cohen091440a2015-03-18 14:16:05 -0700272 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400273
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800274 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 private boolean mRestoring;
276 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700277 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278
Michael Jurka1e2f4652013-07-08 18:03:46 -0700279 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700280 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700281 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700282
Joe Onorato9c1289c2009-08-17 11:03:03 -0400283 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800284 private IconCache mIconCache;
Tony Wickham827cef22016-03-17 15:39:39 -0700285 private ExtractedColors mExtractedColors;
Adam Cohen091440a2015-03-18 14:16:05 -0700286 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800287 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700288 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800289 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290
Sunny Goyal639e9062015-08-19 19:17:06 -0700291 private LauncherClings mClings;
292
Adam Cohen61f560d2013-09-30 15:58:20 -0700293 private View.OnTouchListener mHapticFeedbackTouchListener;
294
Adam Cohended9f8d2010-11-03 13:25:16 -0700295 // Related to the auto-advancing of widgets
296 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700297 private static final int ADVANCE_INTERVAL = 20000;
298 private static final int ADVANCE_STAGGER = 250;
299
300 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700301 private long mAutoAdvanceSentTime;
302 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700303 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700304
Winson Chung400438b2011-01-16 17:53:48 -0800305 // Determines how long to wait after a rotation before restoring the screen orientation to
306 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700307 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800308
Adam Cohen091440a2015-03-18 14:16:05 -0700309 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700310
Adam Cohen1462de32012-07-24 22:34:36 -0700311 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700312 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Winson Chungf0c6ae02012-03-21 16:10:31 -0700318 // Holds the page that we need to animate to, and the icon views that we need to animate up
319 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700320 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700321 private Bitmap mFolderIconBitmap;
322 private Canvas mFolderIconCanvas;
323 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700324
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700325 private DeviceProfile mDeviceProfile;
326
Adam Cohen4b66bf32015-09-18 12:15:19 -0700327 private boolean mMoveToDefaultScreenFromNewIntent;
328
Winson Chung13eb5272015-05-11 16:30:13 -0700329 // This is set to the view that launched the activity that navigated the user away from
330 // launcher. Since there is no callback for when the activity has finished launching, enable
331 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800332 private BubbleTextView mWaitingForResume;
333
Adam Cohen59400422014-03-05 18:07:04 -0800334 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
335 new HashMap<String, CustomAppWidget>();
336
Adam Cohen59400422014-03-05 18:07:04 -0800337 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700338 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
339 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800340 }
341 }
342
Adam Cohen091440a2015-03-18 14:16:05 -0700343 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700344 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700345 if (mWorkspace != null) {
346 mWorkspace.buildPageHardwareLayers();
347 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700348 }
349 };
350
Adam Cohendb364c32014-05-20 14:23:40 -0700351 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352
Adam Cohen091440a2015-03-18 14:16:05 -0700353 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int requestCode;
355 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700356 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700357 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358 int cellX;
359 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700360 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 }
362
Hyunyoung Songaa953652016-04-19 18:30:24 -0700363 private UserEventDispatcher mUserEventDispatcher;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800364
Adam Cohenf9c184a2016-01-15 16:47:43 -0800365 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700366 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400367
368 @Thunk void setOrientation() {
369 if (mRotationEnabled) {
370 unlockScreenOrientation(true);
371 } else {
372 setRequestedOrientation(
373 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700374 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400375 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700376
Sunny Goyal745bad92016-05-02 10:54:12 -0700377 private RotationPrefChangeHandler mRotationPrefChangeHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 @Override
380 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700381 if (DEBUG_STRICT_MODE) {
382 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
383 .detectDiskReads()
384 .detectDiskWrites()
385 .detectNetwork() // or .detectAll() for all detectable problems
386 .penaltyLog()
387 .build());
388 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
389 .detectLeakedSqlLiteObjects()
390 .detectLeakedClosableObjects()
391 .penaltyLog()
392 .penaltyDeath()
393 .build());
394 }
395
Adam Cohen9211d422014-10-07 18:14:53 -0700396 if (mLauncherCallbacks != null) {
397 mLauncherCallbacks.preOnCreate();
398 }
399
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400401
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400402 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700403
Adam Cohen2e6da152015-05-06 11:42:25 -0700404 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700405 mDeviceProfile = getResources().getConfiguration().orientation
406 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700407 app.getInvariantDeviceProfile().landscapeProfile
408 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700409
Sunny Goyalf7258242015-10-19 16:59:07 -0700410 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700411 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800412 mModel = app.setLauncher(this);
413 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700414
Joe Onorato41a12d22009-10-31 18:30:00 -0400415 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700416 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700417
Sunny Goyalffe83f12014-08-14 17:39:34 -0700418 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700419
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700420 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
421 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700422
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700423 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
424 // this also ensures that any synchronous binding below doesn't re-trigger another
425 // LauncherModel load.
426 mPaused = false;
427
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200429 android.os.Debug.startMethodTracing(
430 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 }
432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700434
Tony Wickhameef44322015-10-20 13:24:36 -0700435 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
436 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700438 mDeviceProfile.layout(this);
Tony Wickham827cef22016-03-17 15:39:39 -0700439 mExtractedColors = new ExtractedColors();
440 loadExtractedColorsAndColorItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441
Tony Wickhame2217252016-03-22 16:34:23 -0700442 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
443 .addAccessibilityStateChangeListener(this);
444
Joe Onorato7c312c12009-08-13 21:36:53 -0700445 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700446
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447 mSavedState = savedInstanceState;
448 restoreState(mSavedState);
449
450 if (PROFILE_STARTUP) {
451 android.os.Debug.stopMethodTracing();
452 }
453
454 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700455 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700456 // If the user leaves launcher, then we should just load items asynchronously when
457 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700458 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700459 } else {
460 // We only load the page synchronously if the user rotates (or triggers a
461 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700462 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 }
465
466 // For handling default keys
467 mDefaultKeySsb = new SpannableStringBuilder();
468 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800469
470 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
471 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800472
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800473 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700474 // In case we are on a device with locked rotation, we should look at preferences to check
475 // if the user has specifically allowed rotation.
476 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700477 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Sunny Goyal745bad92016-05-02 10:54:12 -0700478 mRotationPrefChangeHandler = new RotationPrefChangeHandler();
479 mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700480 }
481
482 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
483 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400484 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700485
Adam Cohen9211d422014-10-07 18:14:53 -0700486 if (mLauncherCallbacks != null) {
487 mLauncherCallbacks.onCreate(savedInstanceState);
488 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700489
490 if (shouldShowIntroScreen()) {
491 showIntroScreen();
492 } else {
493 showFirstRunActivity();
494 showFirstRunClings();
495 }
Adam Cohen9211d422014-10-07 18:14:53 -0700496 }
497
Sunny Goyal7779d622015-06-11 16:18:39 -0700498 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700499 public void onExtractedColorsChanged() {
500 loadExtractedColorsAndColorItems();
501 }
502
503 private void loadExtractedColorsAndColorItems() {
Tony Wickham462b5cc2016-04-01 16:00:49 -0700504 // TODO: do this in pre-N as well, once the extraction part is complete.
505 if (mExtractedColors != null && Utilities.isNycOrAbove()) {
Tony Wickham827cef22016-03-17 15:39:39 -0700506 mExtractedColors.load(this);
Tony Wickham462b5cc2016-04-01 16:00:49 -0700507 mHotseat.updateColor(mExtractedColors, !mPaused);
Tony Wickham770217c2016-05-18 15:16:40 -0700508 if (mPageIndicator != null) {
509 mPageIndicator.updateColor(mExtractedColors);
510 }
Tony Wickham827cef22016-03-17 15:39:39 -0700511 }
512 }
513
Adam Cohen9211d422014-10-07 18:14:53 -0700514 private LauncherCallbacks mLauncherCallbacks;
515
516 public void onPostCreate(Bundle savedInstanceState) {
517 super.onPostCreate(savedInstanceState);
518 if (mLauncherCallbacks != null) {
519 mLauncherCallbacks.onPostCreate(savedInstanceState);
520 }
521 }
522
Sunny Goyal32554d12015-12-03 15:31:25 -0800523 /**
524 * Call this after onCreate to set or clear overlay.
525 */
526 public void setLauncherOverlay(LauncherOverlay overlay) {
527 if (overlay != null) {
528 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
529 }
530 mWorkspace.setLauncherOverlay(overlay);
531 }
532
Adam Cohen9211d422014-10-07 18:14:53 -0700533 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
534 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700535 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700536 private boolean mWorkspaceImportanceStored = false;
537 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700538 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800539 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700540 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
541
542 @Override
543 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700544 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700545 return;
546 }
547 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700548 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700549 if (mWorkspace != null) {
550 mWorkspaceImportanceForAccessibility =
551 mWorkspace.getImportantForAccessibility();
552 mWorkspace.setImportantForAccessibility(
553 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
554 mWorkspaceImportanceStored = true;
555 }
556 if (mHotseat != null) {
557 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
558 mHotseat.setImportantForAccessibility(
559 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
560 mHotseatImportanceStored = true;
561 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700562 }
563
564 @Override
565 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700566 if (mWorkspaceImportanceStored && mWorkspace != null) {
567 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
568 }
569 if (mHotseatImportanceStored && mHotseat != null) {
570 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
571 }
572 mWorkspaceImportanceStored = false;
573 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700574 }
575 });
Adam Cohen9211d422014-10-07 18:14:53 -0700576 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700577 }
578
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700579 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700580 public void onLauncherProviderChange() {
581 if (mLauncherCallbacks != null) {
582 mLauncherCallbacks.onLauncherProviderChange();
583 }
584 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700585
Adam Cohen9211d422014-10-07 18:14:53 -0700586 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700587 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700588 if (mLauncherCallbacks != null) {
589 return mLauncherCallbacks.hasCustomContentToLeft();
590 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700591 return false;
592 }
593
Dave Hawkeya8881582013-09-17 15:55:33 -0600594 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500595 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600596 * {@link #addToCustomContentPage}. This will only be invoked if
597 * {@link #hasCustomContentToLeft()} is {@code true}.
598 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500599 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700600 if (mLauncherCallbacks != null) {
601 mLauncherCallbacks.populateCustomContentContainer();
602 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600603 }
604
605 /**
606 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
607 * ensure the custom content page is added or removed if necessary.
608 */
609 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600610 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600611 // Not bound yet, wait for bindScreens to be called.
612 return;
613 }
614
615 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
616 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500617 mWorkspace.createCustomContentContainer();
618 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600619 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
620 mWorkspace.removeCustomContentPage();
621 }
622 }
623
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800624 /**
625 * Logger object is a singleton and does not have to be coupled with the foreground activity.
626 * Since most user event logging is done on the UI, the object is retrieved from the
627 * callback for convenience.
628 */
Hyunyoung Songaa953652016-04-19 18:30:24 -0700629 private UserEventDispatcher createUserEventDispatcher() {
630 return new UserEventDispatcher() {
631 @Override
632 public void dispatchUserEvent(LauncherLogProto.LauncherEvent ev, Intent intent) {
633 if (!DEBUG_LOGGING) {
634 return;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800635 }
Hyunyoung Songaa953652016-04-19 18:30:24 -0700636 Log.d("UserEvent", String.format(Locale.US,
637 "action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
638 LoggerUtils.getActionStr(ev.action),
639 LoggerUtils.getTargetStr(ev.srcTarget[0]),
640 LoggerUtils.getTargetStr(ev.srcTarget[1]),
641 ev.elapsedContainerMillis,
642 ev.elapsedSessionMillis));
643 }
644 };
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800645 }
646
Hyunyoung Songaa953652016-04-19 18:30:24 -0700647 public UserEventDispatcher getUserEventDispatcher() {
648 if (mLauncherCallbacks != null) {
649 UserEventDispatcher dispatcher = mLauncherCallbacks.getUserEventDispatcher();
650 if (dispatcher != null) {
651 return dispatcher;
652 }
653 }
654
655 if (mUserEventDispatcher == null) {
656 mUserEventDispatcher = createUserEventDispatcher();
657 }
658 return mUserEventDispatcher;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800659 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100660
Hyunyoung Song3f471442015-04-08 19:01:34 -0700661 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700662 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
663 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700664 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700665 }
666
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000667 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700668 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
669 // This cast is safe as long as the id < 0x00FFFFFF
670 // Since we jail all the dynamically generated views, there should be no clashes
671 // with any other views.
672 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000673 }
674
675 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700676 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
677 * a configuration step, this allows the proper animations to run after other transitions.
678 */
Adam Cohendb364c32014-05-20 14:23:40 -0700679 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700680 long screenId = args.screenId;
681 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
682 // When the screen id represents an actual screen (as opposed to a rank) we make sure
683 // that the drop page actually exists.
684 screenId = ensurePendingDropLayoutExists(args.screenId);
685 }
Adam Cohendb364c32014-05-20 14:23:40 -0700686
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800687 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800688 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700689 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700690 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700691 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800692 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700693 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700695 case REQUEST_RECONFIGURE_APPWIDGET:
696 completeRestoreAppWidget(args.appWidgetId);
697 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800698 }
Michael Jurka27614d22012-04-02 06:40:22 -0700699 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
700 // if you turned the screen off and then back while in All Apps, Launcher would not
701 // return to the workspace. Clearing mAddInfo.container here fixes this issue
702 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700703 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800704 }
705
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800706 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700707 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700708 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700709 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700710 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800711 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700712
Adam Cohenad4e15c2013-10-17 16:21:35 -0700713 Runnable exitSpringLoaded = new Runnable() {
714 @Override
715 public void run() {
716 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
717 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
718 }
719 };
720
Michael Jurka8b805b12012-04-18 14:23:14 -0700721 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700722 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700723 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700724 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
725 if (resultCode == RESULT_CANCELED) {
726 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700727 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700728 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700729 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800730 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700731 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700732
733 // When the user has granted permission to bind widgets, we should check to see if
734 // we can inflate the default search bar widget.
735 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700736 }
737 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200738 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
739 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700740 // User could have free-scrolled between pages before picking a wallpaper; make sure
741 // we move to the closest one now.
742 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700743 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200744 }
745 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700746 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200747
Adam Cohened66b2b2012-01-23 17:28:51 -0800748 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700749 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700750
Adam Cohendb364c32014-05-20 14:23:40 -0700751 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800752 // We have special handling for widgets
753 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800754 final int appWidgetId;
755 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
756 : -1;
757 if (widgetId < 0) {
758 appWidgetId = pendingAddWidgetId;
759 } else {
760 appWidgetId = widgetId;
761 }
762
Adam Cohenad4e15c2013-10-17 16:21:35 -0700763 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800764 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700765 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
766 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700767 result = RESULT_CANCELED;
768 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700769 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 @Override
771 public void run() {
772 exitSpringLoadedDragModeDelayed(false, 0, null);
773 }
774 };
Adam Cohendb364c32014-05-20 14:23:40 -0700775 if (workspaceLocked) {
776 // No need to remove the empty screen if we're mid-binding, as the
777 // the bind will not add the empty screen.
778 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
779 } else {
780 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
781 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
782 }
Winson Chung5aaab772012-04-27 15:24:02 -0700783 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700784 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700785 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
786 // When the screen id represents an actual screen (as opposed to a rank)
787 // we make sure that the drop page actually exists.
788 mPendingAddInfo.screenId =
789 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
790 }
Adam Cohendb364c32014-05-20 14:23:40 -0700791 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
792
793 dropLayout.setDropPending(true);
794 final Runnable onComplete = new Runnable() {
795 @Override
796 public void run() {
797 completeTwoStageWidgetDrop(resultCode, appWidgetId);
798 dropLayout.setDropPending(false);
799 }
800 };
801 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
802 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
803 } else {
804 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
805 mPendingAddInfo);
806 sPendingAddItem = args;
807 }
Winson Chung5aaab772012-04-27 15:24:02 -0700808 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800809 return;
810 }
811
Sunny Goyalff572272014-07-23 13:58:07 -0700812 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
813 if (resultCode == RESULT_OK) {
814 // Update the widget view.
815 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
816 pendingAddWidgetId, mPendingAddInfo);
817 if (workspaceLocked) {
818 sPendingAddItem = args;
819 } else {
820 completeAdd(args);
821 }
822 }
823 // Leave the widget in the pending state if the user canceled the configure.
824 return;
825 }
826
Sunny Goyalaad90582015-07-09 14:22:50 -0700827 if (requestCode == REQUEST_CREATE_SHORTCUT) {
828 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
829 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
830 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
831 mPendingAddInfo);
832 if (isWorkspaceLocked()) {
833 sPendingAddItem = args;
834 } else {
835 completeAdd(args);
836 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
837 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
838 }
839 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700840 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
841 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800844 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800845
846 }
847
848 @Override
849 protected void onActivityResult(
850 final int requestCode, final int resultCode, final Intent data) {
851 handleActivityResult(requestCode, resultCode, data);
852 if (mLauncherCallbacks != null) {
853 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
854 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800855 }
856
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600857 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700858 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600859 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700860 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
861 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
862 View v = null;
863 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
864 if (layout != null) {
865 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
866 }
867 Intent intent = sPendingAddItem.intent;
868 sPendingAddItem = null;
869 if (grantResults.length > 0
870 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
871 startActivity(v, intent, null);
872 } else {
873 // TODO: Show a snack bar with link to settings
874 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
875 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
876 }
877 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600878 if (mLauncherCallbacks != null) {
879 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
880 grantResults);
881 }
882 }
883
Adam Cohendb364c32014-05-20 14:23:40 -0700884 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
885 appWidgetId, ItemInfo info) {
886 PendingAddArguments args = new PendingAddArguments();
887 args.requestCode = requestCode;
888 args.intent = data;
889 args.container = info.container;
890 args.screenId = info.screenId;
891 args.cellX = info.cellX;
892 args.cellY = info.cellY;
893 args.appWidgetId = appWidgetId;
894 return args;
895 }
896
897 /**
898 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
899 *
900 * @param screenId the screen id to check
901 * @return the new screen, or screenId if it exists
902 */
903 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800904 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700905 if (dropLayout == null) {
906 // it's possible that the add screen was removed because it was
907 // empty and a re-bind occurred
908 mWorkspace.addExtraEmptyScreen();
909 return mWorkspace.commitExtraEmptyScreen();
910 } else {
911 return screenId;
912 }
913 }
914
Adam Cohen091440a2015-03-18 14:16:05 -0700915 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800916 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800917 Runnable onCompleteRunnable = null;
918 int animationType = 0;
919
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700920 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800921 if (resultCode == RESULT_OK) {
922 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
923 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700924 mPendingAddWidgetInfo);
925 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800926 onCompleteRunnable = new Runnable() {
927 @Override
928 public void run() {
929 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700930 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700931 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
932 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800933 }
934 };
935 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800936 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800938 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700939 if (mDragLayer.getAnimatedView() != null) {
940 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
941 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
942 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700943 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700944 // The animated view may be null in the case of a rotation during widget configuration
945 onCompleteRunnable.run();
946 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947 }
948
949 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700950 protected void onStop() {
951 super.onStop();
952 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700953
954 if (mLauncherCallbacks != null) {
955 mLauncherCallbacks.onStop();
956 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700957 }
958
959 @Override
960 protected void onStart() {
961 super.onStart();
962 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700963
964 if (mLauncherCallbacks != null) {
965 mLauncherCallbacks.onStart();
966 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700967 }
968
969 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200971 long startTime = 0;
972 if (DEBUG_RESUME_TIME) {
973 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400974 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200975 }
Adam Cohen9211d422014-10-07 18:14:53 -0700976
977 if (mLauncherCallbacks != null) {
978 mLauncherCallbacks.preOnResume();
979 }
980
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 super.onResume();
Hyunyoung Songaa953652016-04-19 18:30:24 -0700982 getUserEventDispatcher().resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700983
Winson Chung4a2afa32012-07-19 14:53:05 -0700984 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700985 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700986 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800987 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700988 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700989 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700990 // view after launching an app, as they may be depending on the UI to be static to
991 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700992 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700993 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800994 } else if (mOnResumeState == State.WIDGETS) {
995 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700996 }
997 mOnResumeState = State.NONE;
998
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700999 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001000 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1001 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001002
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001003 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001004 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001005 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -07001006 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onorato9c1289c2009-08-17 11:03:03 -04001007 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001008 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001010 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001011 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1012 // execute them here
1013 long startTimeCallbacks = 0;
1014 if (DEBUG_RESUME_TIME) {
1015 startTimeCallbacks = System.currentTimeMillis();
1016 }
1017
Michael Jurka1e2f4652013-07-08 18:03:46 -07001018 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1019 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001020 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001021 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001022 if (DEBUG_RESUME_TIME) {
1023 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1024 (System.currentTimeMillis() - startTimeCallbacks));
1025 }
Michael Jurka447bf842013-05-15 14:52:15 +02001026 }
Michael Jurka54554252013-08-01 12:52:23 +02001027 if (mOnResumeCallbacks.size() > 0) {
1028 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1029 mOnResumeCallbacks.get(i).run();
1030 }
1031 mOnResumeCallbacks.clear();
1032 }
Winson Chunge4e50662012-01-23 14:45:13 -08001033
1034 // Reset the pressed state of icons that were locked in the press state while activities
1035 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001036 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001037 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001038 mWaitingForResume.setStayPressed(false);
1039 }
Winson Chung82963d52013-10-09 11:20:57 -07001040
Adam Cohen06dff352012-06-01 17:17:08 -07001041 // It is possible that widgets can receive updates while launcher is not in the foreground.
1042 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1043 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1044 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001045 if (!isWorkspaceLoading()) {
1046 getWorkspace().reinflateWidgetsIfNecessary();
1047 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001048 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001049
Michael Jurka447bf842013-05-15 14:52:15 +02001050 if (DEBUG_RESUME_TIME) {
1051 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1052 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001053
Adam Cohen4b66bf32015-09-18 12:15:19 -07001054 // We want to suppress callbacks about CustomContent being shown if we have just received
1055 // onNewIntent while the user was present within launcher. In that case, we post a call
1056 // to move the user to the main screen (which will occur after onResume). We don't want to
1057 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1058 // suppress here.
1059 if (mWorkspace.getCustomContentCallbacks() != null
1060 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001061 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001062 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001063 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1064 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001065 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001066 }
1067 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001068 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001069 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001070 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001071
Sunny Goyal756adbc2015-04-16 15:20:51 -07001072 if (!isWorkspaceLoading()) {
1073 // Process any items that were added while Launcher was away.
1074 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1075 }
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();
1086
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001087 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001088 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001089 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001090 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001091
1092 // We call onHide() aggressively. The custom content callbacks should be able to
1093 // debounce excess onHide calls.
1094 if (mWorkspace.getCustomContentCallbacks() != null) {
1095 mWorkspace.getCustomContentCallbacks().onHide();
1096 }
Romain Guycbb89e42009-06-08 15:52:54 -07001097
Adam Cohen9211d422014-10-07 18:14:53 -07001098 if (mLauncherCallbacks != null) {
1099 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001100 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001101 }
1102
1103 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001104 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1105 // by a onResume or by scrolling otherwise.
1106 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001107
1108 // Custom content is completely hidden
1109 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001110
1111 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1112 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001113
1114 // Indicates whether the user is allowed to scroll away from the custom content.
1115 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001116 }
1117
Adam Cohenc2d6e892014-10-16 09:49:24 -07001118 public interface LauncherOverlay {
1119
1120 /**
1121 * Touch interaction leading to overscroll has begun
1122 */
1123 public void onScrollInteractionBegin();
1124
1125 /**
1126 * Touch interaction related to overscroll has ended
1127 */
1128 public void onScrollInteractionEnd();
1129
1130 /**
1131 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1132 * screen (or in the case of RTL, the rightmost screen).
1133 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001134 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001135
1136 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001137 * Called when the launcher is ready to use the overlay
1138 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001139 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001140 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001141 }
1142
Jun Mukai8af0cd82015-05-12 12:32:12 -07001143 public interface LauncherSearchCallbacks {
1144 /**
1145 * Called when the search overlay is shown.
1146 */
1147 public void onSearchOverlayOpened();
1148
1149 /**
1150 * Called when the search overlay is dismissed.
1151 */
1152 public void onSearchOverlayClosed();
1153 }
1154
Adam Cohenc2d6e892014-10-16 09:49:24 -07001155 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001156 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001157 }
1158
1159 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1160
Sunny Goyalc86df472016-02-25 09:19:38 -08001161 public void onScrollChanged(float progress) {
1162 if (mWorkspace != null) {
1163 mWorkspace.onOverlayScrollChanged(progress);
1164 }
1165 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001166 }
1167
Jorim Jaggid017f882014-01-14 17:08:48 -08001168 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001169 if (mLauncherCallbacks != null) {
1170 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001171 } else {
1172 // On devices with a locked orientation, we will at least have the allow rotation
1173 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001174 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001175 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001176 }
1177
Adam Cohen9211d422014-10-07 18:14:53 -07001178 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001179 CustomContentCallbacks callbacks, String description) {
1180 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001181 }
1182
Adam Cohenedb40762013-07-18 16:45:45 -07001183 // The custom content needs to offset its content to account for the QSB
1184 public int getTopOffsetForCustomContent() {
1185 return mWorkspace.getPaddingTop();
1186 }
1187
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001188 @Override
1189 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001190 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001191 if (mModel.isCurrentCallbacks(this)) {
1192 mModel.stopLoader();
1193 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001194 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1195
Romain Guy13c2e7b2010-03-10 19:45:00 -08001196 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001197 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001198
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001199 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001200 @Override
1201 public void onWindowFocusChanged(boolean hasFocus) {
1202 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001203 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001204
1205 if (mLauncherCallbacks != null) {
1206 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1207 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001208 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001209
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 private boolean acceptFilter() {
1211 final InputMethodManager inputManager = (InputMethodManager)
1212 getSystemService(Context.INPUT_METHOD_SERVICE);
1213 return !inputManager.isFullscreenMode();
1214 }
1215
1216 @Override
1217 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001218 final int uniChar = event.getUnicodeChar();
1219 final boolean handled = super.onKeyDown(keyCode, event);
1220 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1221 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1223 keyCode, event);
1224 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001225 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001226 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001227 // showSearchDialog()
1228 // If there are multiple keystrokes before the search dialog takes focus,
1229 // onSearchRequested() will be called for every keystroke,
1230 // but it is idempotent, so it's fine.
1231 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 }
1233 }
1234
Joe Onorato8a9625e2010-01-28 15:55:35 -08001235 // Eat the long press event so the keyboard doesn't come up.
1236 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1237 return true;
1238 }
1239
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001240 return handled;
1241 }
1242
Winson46163472015-09-22 17:31:56 -07001243 @Override
1244 public boolean onKeyUp(int keyCode, KeyEvent event) {
1245 if (keyCode == KeyEvent.KEYCODE_MENU) {
1246 // Ignore the menu key if we are currently dragging or are on the custom content screen
1247 if (!isOnCustomContent() && !mDragController.isDragging()) {
1248 // Close any open folders
1249 closeFolder();
1250
1251 // Stop resizing any widgets
1252 mWorkspace.exitWidgetResizeMode();
1253
1254 // Show the overview mode if we are on the workspace
1255 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1256 !mWorkspace.isSwitchingState()) {
1257 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001258 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001259 }
1260 }
1261 return true;
1262 }
1263 return super.onKeyUp(keyCode, event);
1264 }
1265
Karl Rosaen138a0412009-04-23 19:00:21 -07001266 private String getTypedText() {
1267 return mDefaultKeySsb.toString();
1268 }
1269
1270 private void clearTypedText() {
1271 mDefaultKeySsb.clear();
1272 mDefaultKeySsb.clearSpans();
1273 Selection.setSelection(mDefaultKeySsb, 0);
1274 }
1275
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001277 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1278 * State
1279 */
1280 private static State intToState(int stateOrdinal) {
1281 State state = State.WORKSPACE;
1282 final State[] stateValues = State.values();
1283 for (int i = 0; i < stateValues.length; i++) {
1284 if (stateValues[i].ordinal() == stateOrdinal) {
1285 state = stateValues[i];
1286 break;
1287 }
1288 }
1289 return state;
1290 }
1291
1292 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 * Restores the previous state, if it exists.
1294 *
1295 * @param savedState The previous state.
1296 */
1297 private void restoreState(Bundle savedState) {
1298 if (savedState == null) {
1299 return;
1300 }
1301
Michael Jurka883f55b2010-10-21 15:47:14 -07001302 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001303 if (state == State.APPS || state == State.WIDGETS) {
1304 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001305 }
1306
Adam Cohen21cd0022013-10-09 18:57:02 -07001307 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1308 PagedView.INVALID_RESTORE_PAGE);
1309 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001310 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311 }
1312
Sunny Goyal756cd262015-08-20 12:33:21 -07001313 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1314 if (itemValues != null) {
1315 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001316 AppWidgetProviderInfo info = savedState.getParcelable(
1317 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001318 mPendingAddWidgetInfo = info == null ?
1319 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1320
Adam Cohen4637b5a2013-11-04 18:21:24 -08001321 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001322 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 mRestoring = true;
1324 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
1326
1327 /**
1328 * Finds all the views we need and configure them properly.
1329 */
1330 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001331 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001332
Craig Mautner360310b2012-10-26 15:13:08 -07001333 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001334 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001335 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1336 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Tony Wickhamf549dab2016-05-16 09:54:06 -07001337 mPageIndicator = (PageIndicatorLine) mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001338
Sunny Goyal784f9c32016-03-23 16:56:54 -07001339 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1340 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1341 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
Craig Mautner360310b2012-10-26 15:13:08 -07001342 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343
Winson Chung4c98d922011-05-31 16:50:48 -07001344 // Setup the drag layer
1345 mDragLayer.setup(this, dragController);
1346
Winson Chung3d503fb2011-07-13 17:25:49 -07001347 // Setup the hotseat
1348 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1349 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001350 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001351 }
1352
Winsone9f27272015-10-13 10:47:51 -07001353 // Setup the overview panel
1354 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001355
Winson Chung4c98d922011-05-31 16:50:48 -07001356 // Setup the workspace
1357 mWorkspace.setHapticFeedbackEnabled(false);
1358 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001359 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001360 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001361
Tony Wickham34d2c912015-09-11 09:27:58 -07001362 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001363 mSearchDropTargetBar = (SearchDropTargetBar)
1364 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001365 // Get the app info bar
1366 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1367 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001368
Winson Chungef7f8742015-06-04 17:18:17 -07001369 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001370 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001371 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001372 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1373 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1374 } else {
1375 mAppsView.setSearchBarController(new DefaultAppSearchController());
1376 }
Craig Mautner360310b2012-10-26 15:13:08 -07001377
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001379 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001380 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001381 dragController.setMoveTarget(mWorkspace);
1382 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001383 if (mSearchDropTargetBar != null) {
1384 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001385 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001386 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001387 if (mAppInfoDropTargetBar != null) {
1388 mAppInfoDropTargetBar.setup(this, dragController);
1389 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001390
Sunny Goyal322d5562015-06-25 19:35:49 -07001391 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1392 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001393 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 }
1395
Winsone9f27272015-10-13 10:47:51 -07001396 private void setupOverviewPanel() {
1397 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1398
1399 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1400 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1401 @Override
1402 public boolean onLongClick(View v) {
1403 return v.performClick();
1404 }
1405 };
1406
1407 // Bind wallpaper button actions
1408 View wallpaperButton = findViewById(R.id.wallpaper_button);
1409 wallpaperButton.setOnClickListener(new OnClickListener() {
1410 @Override
1411 public void onClick(View view) {
1412 if (!mWorkspace.isSwitchingState()) {
1413 onClickWallpaperPicker(view);
1414 }
1415 }
1416 });
1417 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1418 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1419
1420 // Bind widget button actions
1421 mWidgetsButton = findViewById(R.id.widget_button);
1422 mWidgetsButton.setOnClickListener(new OnClickListener() {
1423 @Override
1424 public void onClick(View view) {
1425 if (!mWorkspace.isSwitchingState()) {
1426 onClickAddWidgetButton(view);
1427 }
1428 }
1429 });
1430 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1431 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1432
1433 // Bind settings actions
1434 View settingsButton = findViewById(R.id.settings_button);
1435 boolean hasSettings = hasSettings();
1436 if (hasSettings) {
1437 settingsButton.setOnClickListener(new OnClickListener() {
1438 @Override
1439 public void onClick(View view) {
1440 if (!mWorkspace.isSwitchingState()) {
1441 onClickSettingsButton(view);
1442 }
1443 }
1444 });
1445 settingsButton.setOnLongClickListener(performClickOnLongClick);
1446 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1447 } else {
1448 settingsButton.setVisibility(View.GONE);
1449 }
1450
1451 mOverviewPanel.setAlpha(0f);
1452 }
1453
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001455 * Sets the all apps button. This method is called from {@link Hotseat}.
1456 */
1457 public void setAllAppsButton(View allAppsButton) {
1458 mAllAppsButton = allAppsButton;
1459 }
1460
1461 public View getAllAppsButton() {
1462 return mAllAppsButton;
1463 }
1464
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001465 public View getWidgetsButton() {
1466 return mWidgetsButton;
1467 }
1468
Anjali Koppal5ad44842014-03-10 20:34:39 -07001469 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 * Creates a view representing a shortcut.
1471 *
1472 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001474 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001475 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 }
1477
1478 /**
1479 * Creates a view representing a shortcut inflated from the specified resource.
1480 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 * @param parent The group the shortcut belongs to.
1482 * @param info The data structure describing the shortcut.
1483 *
1484 * @return A View inflated from layoutResId.
1485 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001486 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001487 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001488 parent, false);
1489 favorite.applyFromShortcutInfo(info, mIconCache);
1490 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001492 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 return favorite;
1494 }
1495
1496 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 * Add a shortcut to the workspace.
1498 *
1499 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001500 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001501 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001502 int cellY) {
1503 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001504 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001505
Sunny Goyal5c97f512015-05-19 16:03:28 -07001506 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001507 if (info == null) {
1508 return;
1509 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001510 final View view = createShortcut(info);
1511
Sunny Goyal5c97f512015-05-19 16:03:28 -07001512 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001513 // First we check if we already know the exact location where we want to add this item.
1514 if (cellX >= 0 && cellY >= 0) {
1515 cellXY[0] = cellX;
1516 cellXY[1] = cellY;
1517 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001518
1519 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001520 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001521 true, null,null)) {
1522 return;
1523 }
1524 DragObject dragObject = new DragObject();
1525 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001526 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1527 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001528 return;
1529 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001530 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001531 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001532 }
1533
1534 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001535 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001536 return;
1537 }
1538
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001539 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540
1541 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001542 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001543 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 }
1545 }
1546
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001548 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001550 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 */
Adam Cohen091440a2015-03-18 14:16:05 -07001552 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001553 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1554
1555 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001556 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001557 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001558 }
Romain Guycbb89e42009-06-08 15:52:54 -07001559
Adam Cohen59400422014-03-05 18:07:04 -08001560 if (appWidgetInfo.isCustomWidget) {
1561 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001562 }
1563
Adam Cohen59400422014-03-05 18:07:04 -08001564 LauncherAppWidgetInfo launcherInfo;
1565 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1566 launcherInfo.spanX = info.spanX;
1567 launcherInfo.spanY = info.spanY;
1568 launcherInfo.minSpanX = info.minSpanX;
1569 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001570 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001571
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001573 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574
1575 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001576 if (hostView == null) {
1577 // Perform actual inflation because we're live
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001578 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001579 }
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001580 hostView.setVisibility(View.VISIBLE);
1581 addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001582 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001583 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001584 }
Romain Guycbb89e42009-06-08 15:52:54 -07001585
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001586 private void addAppWidgetToWorkspace(
1587 AppWidgetHostView hostView, LauncherAppWidgetInfo item,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001588 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001589 hostView.setTag(item);
1590 item.onBindAppWidget(this, hostView);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001591
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001592 hostView.setFocusable(true);
1593 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001594
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001595 mWorkspace.addInScreen(hostView, item.container, item.screenId,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001596 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1597
1598 if (!item.isCustomWidget()) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001599 addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001600 }
1601 }
1602
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1604 @Override
1605 public void onReceive(Context context, Intent intent) {
1606 final String action = intent.getAction();
1607 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1608 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001609 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001610 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001611
Winson Chungc100e8e2011-08-09 16:02:43 -07001612 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001613 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001614 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001615 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001616 if (!showWorkspace(false)) {
1617 // If we are already on the workspace, then manually reset all apps
1618 mAppsView.reset();
1619 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001620 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001621 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1622 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001623 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001624 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1625 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001626 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001627 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1628 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1629 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001630 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001631 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1632 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001633 }
1634 }
1635 };
1636
1637 @Override
1638 public void onAttachedToWindow() {
1639 super.onAttachedToWindow();
1640
1641 // Listen for broadcasts related to user-presence
1642 final IntentFilter filter = new IntentFilter();
1643 filter.addAction(Intent.ACTION_SCREEN_OFF);
1644 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001645 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001646 if (ENABLE_DEBUG_INTENTS) {
1647 filter.addAction(DebugIntents.DELETE_DATABASE);
1648 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1649 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001650 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001651 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001652 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001653 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001654
1655 if (mLauncherCallbacks != null) {
1656 mLauncherCallbacks.onAttachedToWindow();
1657 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001658 }
1659
1660 @Override
1661 public void onDetachedFromWindow() {
1662 super.onDetachedFromWindow();
1663 mVisible = false;
1664
Adam Cohend113e0c2010-11-11 10:48:05 -08001665 if (mAttached) {
1666 unregisterReceiver(mReceiver);
1667 mAttached = false;
1668 }
Winson Chungb745afb2015-03-02 11:51:23 -08001669 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001670
1671 if (mLauncherCallbacks != null) {
1672 mLauncherCallbacks.onDetachedFromWindow();
1673 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001674 }
1675
1676 public void onWindowVisibilityChanged(int visibility) {
1677 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001678 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001679 // The following code used to be in onResume, but it turns out onResume is called when
1680 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1681 // is a more appropriate event to handle
1682 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001683 if (!mWorkspaceLoading) {
1684 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001685 // We want to let Launcher draw itself at least once before we force it to build
1686 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001687 // apps is nice and speedy.
1688 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001689 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001690 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001691 if (mStarted) return;
1692 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001693 // We delay the layer building a bit in order to give
1694 // other message processing a time to run. In particular
1695 // this avoids a delay in hiding the IME if it was
1696 // currently shown, because doing that may involve
1697 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001698 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001699 final ViewTreeObserver.OnDrawListener listener = this;
1700 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001701 public void run() {
1702 if (mWorkspace != null &&
1703 mWorkspace.getViewTreeObserver() != null) {
1704 mWorkspace.getViewTreeObserver().
1705 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001706 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001707 }
1708 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001709 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001710 }
1711 });
1712 }
1713 clearTypedText();
1714 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001715 }
1716
Adam Cohen091440a2015-03-18 14:16:05 -07001717 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001718 mHandler.removeMessages(ADVANCE_MSG);
1719 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1720 mHandler.sendMessageDelayed(msg, delay);
1721 mAutoAdvanceSentTime = System.currentTimeMillis();
1722 }
1723
Adam Cohen091440a2015-03-18 14:16:05 -07001724 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001725 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1726 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1727 mAutoAdvanceRunning = autoAdvanceRunning;
1728 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001729 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001730 sendAdvanceMessage(delay);
1731 } else {
1732 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001733 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001734 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1735 }
1736 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001737 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001738 }
1739 }
1740 }
1741
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001742 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1743
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001745 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001746 if (msg.what == ADVANCE_MSG) {
1747 int i = 0;
1748 for (View key: mWidgetsToAdvance.keySet()) {
1749 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001750 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001752 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001753 public void run() {
1754 ((Advanceable) v).advance();
1755 }
1756 }, delay);
1757 }
1758 i++;
1759 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001760 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001762 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001764 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001765
Winsonc0b52fe2015-09-09 16:38:15 -07001766 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001767 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001768 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1769 if (v instanceof Advanceable) {
1770 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001771 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001772 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001773 }
1774 }
1775
Winsonc0b52fe2015-09-09 16:38:15 -07001776 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001777 if (mWidgetsToAdvance.containsKey(hostView)) {
1778 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001779 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001780 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001781 }
1782
Hyunyoung Song3f471442015-04-08 19:01:34 -07001783 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001784 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1785 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
1787
Winson Chunga6945242014-01-08 14:04:34 -08001788 public DragLayer getDragLayer() {
1789 return mDragLayer;
1790 }
1791
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001792 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001793 return mAppsView;
1794 }
1795
Hyunyoung Song3f471442015-04-08 19:01:34 -07001796 public WidgetsContainerView getWidgetsView() {
1797 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001798 }
1799
Winson Chunga6945242014-01-08 14:04:34 -08001800 public Workspace getWorkspace() {
1801 return mWorkspace;
1802 }
1803
1804 public Hotseat getHotseat() {
1805 return mHotseat;
1806 }
1807
Jorim Jaggid017f882014-01-14 17:08:48 -08001808 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001809 return mOverviewPanel;
1810 }
1811
Winson Chung006ee262015-08-03 14:40:11 -07001812 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001813 return mSearchDropTargetBar;
1814 }
1815
Tony Wickham34d2c912015-09-11 09:27:58 -07001816 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1817 return mAppInfoDropTargetBar;
1818 }
1819
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001820 public LauncherAppWidgetHost getAppWidgetHost() {
1821 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 }
Romain Guycbb89e42009-06-08 15:52:54 -07001823
Winson Chunga9abd0e2010-10-27 17:18:37 -07001824 public LauncherModel getModel() {
1825 return mModel;
1826 }
1827
Adam Cohen79d90c52016-04-22 13:29:20 -07001828 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001829 return mSharedPrefs;
1830 }
1831
Adam Cohen2e6da152015-05-06 11:42:25 -07001832 public DeviceProfile getDeviceProfile() {
1833 return mDeviceProfile;
1834 }
1835
Bjorn Bringertc459e522013-06-07 19:36:01 +01001836 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001837 getWindow().closeAllPanels();
1838
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001839 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001840 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001841 }
1842
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 @Override
1844 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001845 long startTime = 0;
1846 if (DEBUG_RESUME_TIME) {
1847 startTime = System.currentTimeMillis();
1848 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 super.onNewIntent(intent);
1850
1851 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001852 Folder openFolder = mWorkspace.getOpenFolder();
1853 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1854 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1855 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1856 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1857 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001858 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001859 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001860
Adam Cohen6fecd412013-10-02 17:41:50 -07001861 if (mWorkspace == null) {
1862 // Can be cases where mWorkspace is null, this prevents a NPE
1863 return;
1864 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001865 // In all these cases, only animate if we're already on home
1866 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001867
Sunny Goyal935fca12015-10-13 10:19:01 -07001868 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001869 exitSpringLoadedDragMode();
1870
1871 // If we are already on home, then just animate back to the workspace,
1872 // otherwise, just wait until onResume to set the state back to Workspace
1873 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001874 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001875 } else {
1876 mOnResumeState = State.WORKSPACE;
1877 }
1878
1879 final View v = getWindow().peekDecorView();
1880 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001881 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001882 INPUT_METHOD_SERVICE);
1883 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1884 }
1885
Winson Chungb745afb2015-03-02 11:51:23 -08001886 // Reset the apps view
1887 if (!alreadyOnHome && mAppsView != null) {
1888 mAppsView.scrollToTop();
1889 }
1890
Hyunyoung Song3f471442015-04-08 19:01:34 -07001891 // Reset the widgets view
1892 if (!alreadyOnHome && mWidgetsView != null) {
1893 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001894 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001895
Adam Cohen9211d422014-10-07 18:14:53 -07001896 if (mLauncherCallbacks != null) {
1897 mLauncherCallbacks.onHomeIntent();
1898 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 }
Adam Cohened307df2013-10-02 09:37:31 -07001900
Adam Cohen9211d422014-10-07 18:14:53 -07001901 if (mLauncherCallbacks != null) {
1902 mLauncherCallbacks.onNewIntent(intent);
1903 }
Winson15f8b172015-08-19 11:02:39 -07001904
1905 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1906 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1907 // animation.
1908 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001909 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1910 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001911 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1912 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001913
1914 // We use this flag to suppress noisy callbacks above custom content state
1915 // from onResume.
1916 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001917 mWorkspace.post(new Runnable() {
1918 @Override
1919 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001920 if (mWorkspace != null) {
1921 mWorkspace.moveToDefaultScreen(true);
1922 }
Winson15f8b172015-08-19 11:02:39 -07001923 }
1924 });
1925 }
1926 }
1927
1928 if (DEBUG_RESUME_TIME) {
1929 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1930 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001931 }
1932
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001934 public void onRestoreInstanceState(Bundle state) {
1935 super.onRestoreInstanceState(state);
1936 for (int page: mSynchronouslyBoundPages) {
1937 mWorkspace.restoreInstanceStateForChild(page);
1938 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 }
1940
1941 @Override
1942 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001943 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001944 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1945 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001946 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001947 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948
Michael Jurka883f55b2010-10-21 15:47:14 -07001949 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001950 // We close any open folder since it will not be re-opened, and we need to make sure
1951 // this state is reflected.
1952 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1953 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001957 ContentValues itemValues = new ContentValues();
1958 mPendingAddInfo.writeToValues(itemValues);
1959 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001960 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001961 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
1963
Adam Cohen9211d422014-10-07 18:14:53 -07001964 if (mLauncherCallbacks != null) {
1965 mLauncherCallbacks.onSaveInstanceState(outState);
1966 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 }
1968
1969 @Override
1970 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001972
Winson Chunge7a03942011-08-05 15:05:12 -07001973 // Remove all pending runnables
1974 mHandler.removeMessages(ADVANCE_MSG);
1975 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001976 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001977 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001978
Winson Chungcd2b0142011-06-08 16:02:26 -07001979 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001980 // It's possible to receive onDestroy after a new Launcher activity has
1981 // been created. In this case, don't interfere with the new Launcher.
1982 if (mModel.isCurrentCallbacks(this)) {
1983 mModel.stopLoader();
Sunny Goyald365ed62016-02-12 09:44:03 -08001984 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001985 }
Winson Chungcd2b0142011-06-08 16:02:26 -07001986
Sunny Goyal745bad92016-05-02 10:54:12 -07001987 if (mRotationPrefChangeHandler != null) {
1988 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
1989 }
1990
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001992 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001994 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001996 mAppWidgetHost = null;
1997
1998 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999
2000 TextKeyListener.getInstance().release();
2001
Tony Wickhame2217252016-03-22 16:34:23 -07002002 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
2003 .removeAccessibilityStateChangeListener(this);
2004
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002005 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002006
Michael Jurka2ecf9952012-06-18 12:52:28 -07002007 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002008
2009 if (mLauncherCallbacks != null) {
2010 mLauncherCallbacks.onDestroy();
2011 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 }
2013
Adam Cohena9cf38f2011-05-02 15:36:58 -07002014 public DragController getDragController() {
2015 return mDragController;
2016 }
2017
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 @Override
2019 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002020 onStartForResult(requestCode);
2021 super.startActivityForResult(intent, requestCode);
2022 }
2023
2024 @Override
2025 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2026 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2027 onStartForResult(requestCode);
2028 try {
2029 super.startIntentSenderForResult(intent, requestCode,
2030 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2031 } catch (IntentSender.SendIntentException e) {
2032 throw new ActivityNotFoundException();
2033 }
2034 }
2035
2036 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002037 if (requestCode >= 0) {
2038 setWaitingForResult(true);
2039 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 }
2041
Winson Chung70d72102011-08-12 11:24:35 -07002042 /**
2043 * Indicates that we want global search for this activity by setting the globalSearch
2044 * argument for {@link #startSearch} to true.
2045 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002047 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002049
Karl Rosaen138a0412009-04-23 19:00:21 -07002050 if (initialQuery == null) {
2051 // Use any text typed in the launcher as the initial query
2052 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002053 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 if (appSearchData == null) {
2055 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002056 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 }
Winson Chungadf0c182012-08-23 14:59:07 -07002058 Rect sourceBounds = new Rect();
2059 if (mSearchDropTargetBar != null) {
2060 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2061 }
Romain Guycbb89e42009-06-08 15:52:54 -07002062
Ian Parkinson047036e2014-09-01 15:40:53 +01002063 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002064 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002065 if (clearTextImmediately) {
2066 clearTypedText();
2067 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002068
2069 // We need to show the workspace after starting the search
2070 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002071 }
2072
Ian Parkinson047036e2014-09-01 15:40:53 +01002073 /**
2074 * Start a text search.
2075 *
2076 * @return {@code true} if the search will start immediately, so any further keypresses
2077 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2078 * to buffer keypresses.
2079 */
2080 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002081 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002082 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2083 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2084 sourceBounds);
2085 }
2086
Michael Jurkaa33411c2012-06-14 16:18:21 -07002087 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002088 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002089 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002090 }
2091
2092 /**
2093 * Starts the global search activity. This code is a copied from SearchManager
2094 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002095 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002096 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002097 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002098 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2099 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2100 if (globalSearchActivity == null) {
2101 Log.w(TAG, "No global search activity found.");
2102 return;
2103 }
2104 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2105 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2106 intent.setComponent(globalSearchActivity);
2107 // Make sure that we have a Bundle to put source in
2108 if (appSearchData == null) {
2109 appSearchData = new Bundle();
2110 } else {
2111 appSearchData = new Bundle(appSearchData);
2112 }
Adam Cohen9211d422014-10-07 18:14:53 -07002113 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002114 if (!appSearchData.containsKey("source")) {
2115 appSearchData.putString("source", getPackageName());
2116 }
2117 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2118 if (!TextUtils.isEmpty(initialQuery)) {
2119 intent.putExtra(SearchManager.QUERY, initialQuery);
2120 }
2121 if (selectInitialQuery) {
2122 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2123 }
2124 intent.setSourceBounds(sourceBounds);
2125 try {
2126 startActivity(intent);
2127 } catch (ActivityNotFoundException ex) {
2128 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2129 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 }
2131
Yura4f93ec62014-02-04 14:15:21 +00002132 public boolean isOnCustomContent() {
2133 return mWorkspace.isOnOrMovingToCustomContent();
2134 }
2135
Winson Chung70d72102011-08-12 11:24:35 -07002136 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002137 public boolean onPrepareOptionsMenu(Menu menu) {
2138 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002139 if (mLauncherCallbacks != null) {
2140 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2141 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002142 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002143 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002145 @Override
2146 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002147 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002148 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002149 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002150 }
2151
Joe Onorato9c1289c2009-08-17 11:03:03 -04002152 public boolean isWorkspaceLocked() {
2153 return mWorkspaceLoading || mWaitingForResult;
2154 }
2155
Adam Cohen517a7f52014-03-01 12:12:59 -08002156 public boolean isWorkspaceLoading() {
2157 return mWorkspaceLoading;
2158 }
2159
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002160 private void setWorkspaceLoading(boolean value) {
2161 boolean isLocked = isWorkspaceLocked();
2162 mWorkspaceLoading = value;
2163 if (isLocked != isWorkspaceLocked()) {
2164 onWorkspaceLockedChanged();
2165 }
2166 }
2167
2168 private void setWaitingForResult(boolean value) {
2169 boolean isLocked = isWorkspaceLocked();
2170 mWaitingForResult = value;
2171 if (isLocked != isWorkspaceLocked()) {
2172 onWorkspaceLockedChanged();
2173 }
2174 }
2175
Adam Cohen9211d422014-10-07 18:14:53 -07002176 protected void onWorkspaceLockedChanged() {
2177 if (mLauncherCallbacks != null) {
2178 mLauncherCallbacks.onWorkspaceLockedChanged();
2179 }
2180 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002181
Michael Jurka0280c3b2010-09-17 15:00:07 -07002182 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002183 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002184 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002185 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2186 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002187 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002188 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002189
Tony Wickhama0628cc2015-10-14 15:23:04 -07002190 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002191 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002192 if (LOGD) {
2193 Log.d(TAG, "Adding widget from drop");
2194 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002195 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2196 }
2197
Sunny Goyale6b63a32015-01-16 16:14:29 -08002198 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002199 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2200 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002201 if (appWidgetInfo.configure != null) {
2202 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002203 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002204
Bjorn Bringert7984c942009-12-09 15:38:25 +00002205 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002206 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2207 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2208
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002209 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002210 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002211 Runnable onComplete = new Runnable() {
2212 @Override
2213 public void run() {
2214 // Exit spring loaded mode if necessary after adding the widget
2215 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2216 null);
2217 }
2218 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002219 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002220 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002221 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 }
2223 }
Romain Guycbb89e42009-06-08 15:52:54 -07002224
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002225 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002226 // Close any folders that may be open.
2227 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002228 mWorkspace.moveToCustomContentScreen(animate);
2229 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002230
2231 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2232 int[] cell, int spanX, int spanY) {
2233 switch (info.itemType) {
2234 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2235 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2236 int span[] = new int[2];
2237 span[0] = spanX;
2238 span[1] = spanY;
2239 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2240 container, screenId, cell, span);
2241 break;
2242 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2243 processShortcutFromDrop(info.componentName, container, screenId, cell);
2244 break;
2245 default:
2246 throw new IllegalStateException("Unknown item type: " + info.itemType);
2247 }
2248 }
2249
Adam Cohenfbba09b2011-07-18 21:43:05 -07002250 /**
2251 * Process a shortcut drop.
2252 *
2253 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002254 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002255 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002256 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002257 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2258 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002259 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002260 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002261 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002262
2263 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002264 mPendingAddInfo.cellX = cell[0];
2265 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002266 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002267
2268 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2269 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002270 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002271 }
2272
Adam Cohenfbba09b2011-07-18 21:43:05 -07002273 /**
2274 * Process a widget drop.
2275 *
2276 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002277 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002278 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002279 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002280 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2281 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002282 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002284 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002285 mPendingAddInfo.minSpanX = info.minSpanX;
2286 mPendingAddInfo.minSpanY = info.minSpanY;
2287
Adam Cohenfbba09b2011-07-18 21:43:05 -07002288 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002289 mPendingAddInfo.cellX = cell[0];
2290 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002291 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002292 if (span != null) {
2293 mPendingAddInfo.spanX = span[0];
2294 mPendingAddInfo.spanY = span[1];
2295 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002296
Adam Cohened66b2b2012-01-23 17:28:51 -08002297 AppWidgetHostView hostView = info.boundWidget;
2298 int appWidgetId;
2299 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002300 // In the case where we've prebound the widget, we remove it from the DragLayer
2301 if (LOGD) {
2302 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2303 }
2304 getDragLayer().removeView(hostView);
2305
Adam Cohened66b2b2012-01-23 17:28:51 -08002306 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002307 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002308
2309 // Clear the boundWidget so that it doesn't get destroyed.
2310 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002311 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002312 // In this case, we either need to start an activity to get permission to bind
2313 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002314 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002315 Bundle options = info.bindOptions;
2316
Sunny Goyalffe83f12014-08-14 17:39:34 -07002317 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2318 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002319 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002320 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002321 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002322 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002323 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2324 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2325 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002326 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2327 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002328 // TODO: we need to make sure that this accounts for the options bundle.
2329 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002330 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2331 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002332 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002333 }
2334
Adam Cohendcd297f2013-06-18 13:13:40 -07002335 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002336 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002337 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 folderInfo.title = getText(R.string.folder_name);
2339
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002341 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2342 cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343
2344 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002345 FolderIcon newFolder =
2346 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002347 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002348 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002349 // Force measure the new folder icon
2350 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2351 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002352 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002353 }
Romain Guycbb89e42009-06-08 15:52:54 -07002354
Winsonc0b52fe2015-09-09 16:38:15 -07002355 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002356 * Unbinds the view for the specified item, and removes the item and all its children.
2357 *
2358 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002359 * @param itemInfo the {@link ItemInfo} for this view.
2360 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002361 */
Winson2949fb52015-09-24 09:56:11 -07002362 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002363 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002364 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07002365 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
2366 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07002367 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07002368 } else {
2369 mWorkspace.removeWorkspaceItem(v);
2370 }
Winsonc0b52fe2015-09-09 16:38:15 -07002371 if (deleteFromDb) {
2372 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2373 }
2374 } else if (itemInfo instanceof FolderInfo) {
2375 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07002376 if (v instanceof FolderIcon) {
2377 ((FolderIcon) v).removeListeners();
2378 }
Winsonc0b52fe2015-09-09 16:38:15 -07002379 mWorkspace.removeWorkspaceItem(v);
2380 if (deleteFromDb) {
2381 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2382 }
2383 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2384 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002385 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07002386 removeWidgetToAutoAdvance(v);
Winsonc0b52fe2015-09-09 16:38:15 -07002387 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002388 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002389 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002390
Winsonc0b52fe2015-09-09 16:38:15 -07002391 } else {
2392 return false;
2393 }
2394 return true;
2395 }
2396
2397 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002398 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002399 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002400 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002401 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002402 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002403 // Deleting an app widget ID is a void call but writes to disk before returning
2404 // to the caller...
2405 new AsyncTask<Void, Void, Void>() {
2406 public Void doInBackground(Void ... args) {
2407 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2408 return null;
2409 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002410 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002411 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002412 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002413 }
2414
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002415 @Override
2416 public boolean dispatchKeyEvent(KeyEvent event) {
2417 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2418 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002419 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002420 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002421 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002422 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002423 dumpState();
2424 return true;
2425 }
2426 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002427 }
2428 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2429 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002430 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002431 return true;
2432 }
2433 }
2434
2435 return super.dispatchKeyEvent(event);
2436 }
2437
Joe Onorato88ec0992009-11-19 13:16:06 -08002438 @Override
2439 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002440 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2441 return;
2442 }
2443
Sunny Goyal45478022015-06-08 16:52:41 -07002444 if (mDragController.isDragging()) {
2445 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002446 return;
2447 }
2448
Winson Chungb745afb2015-03-02 11:51:23 -08002449 if (isAppsViewVisible()) {
2450 showWorkspace(true);
2451 } else if (isWidgetsViewVisible()) {
2452 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002453 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002454 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002455 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002456 Folder openFolder = mWorkspace.getOpenFolder();
2457 if (openFolder.isEditingName()) {
2458 openFolder.dismissEditingName();
2459 } else {
2460 closeFolder();
2461 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002462 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002463 mWorkspace.exitWidgetResizeMode();
2464
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002465 // Back button is a no-op here, but give at least some feedback for the button press
2466 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002467 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002468 }
2469
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002470 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002471 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002472 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002473 @Override
2474 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002475 if (mAppWidgetHost != null) {
2476 mAppWidgetHost.startListening();
2477 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002478
2479 // Recreate the QSB, as the widget has been reset.
2480 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002481 }
2482
2483 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002484 * Launches the intent referred by the clicked shortcut.
2485 *
2486 * @param v The view representing the clicked shortcut.
2487 */
2488 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002489 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2490 // view has detached (it's possible for this to happen if the view is removed mid touch).
2491 if (v.getWindowToken() == null) {
2492 return;
2493 }
2494
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002495 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002496 return;
2497 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002498
Adam Cohen1697b792013-09-17 19:08:21 -07002499 if (v instanceof Workspace) {
2500 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002501 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002502 }
2503 return;
2504 }
2505
2506 if (v instanceof CellLayout) {
2507 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002508 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2509 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002510 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002511 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002512 }
2513
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002514 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002515 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002516 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002517 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002518 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002519 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002520 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002521 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002522 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002523 } else if (tag instanceof AppInfo) {
2524 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002525 } else if (tag instanceof LauncherAppWidgetInfo) {
2526 if (v instanceof PendingAppWidgetHostView) {
2527 onClickPendingWidget((PendingAppWidgetHostView) v);
2528 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002529 }
2530 }
2531
Sunny Goyal70660032015-05-14 00:07:08 -07002532 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002533 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002534 return false;
2535 }
2536
Michael Jurkaaf442092010-06-10 17:01:57 -07002537 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002538 * Event handler for the app widget view which has not fully restored.
2539 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002540 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002541 if (mIsSafeModeEnabled) {
2542 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2543 return;
2544 }
2545
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002546 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002547 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002548 int widgetId = info.appWidgetId;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002549 LauncherAppWidgetProviderInfo appWidgetInfo =
2550 mAppWidgetManager.getLauncherAppWidgetInfo(widgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002551 if (appWidgetInfo != null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002552 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002553 mPendingAddInfo.copyFrom(info);
2554 mPendingAddWidgetId = widgetId;
2555
Sunny Goyalffe83f12014-08-14 17:39:34 -07002556 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2557 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002558 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002559 } else if (info.installProgress < 0) {
2560 // The install has not been queued
2561 final String packageName = info.providerName.getPackageName();
2562 showBrokenAppInstallDialog(packageName,
2563 new DialogInterface.OnClickListener() {
2564 public void onClick(DialogInterface dialog, int id) {
2565 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2566 }
2567 });
2568 } else {
2569 // Download has started.
2570 final String packageName = info.providerName.getPackageName();
2571 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002572 }
2573 }
2574
2575 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002576 * Event handler for the "grid" button that appears on the home screen, which
2577 * enters all apps mode.
2578 *
2579 * @param v The view that was clicked.
2580 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002581 protected void onClickAllAppsButton(View v) {
2582 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002583 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002584 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002585 true /* updatePredictedApps */, false /* focusSearchBar */);
2586 }
2587 }
2588
2589 protected void onLongClickAllAppsButton(View v) {
2590 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2591 if (!isAppsViewVisible()) {
2592 showAppsView(true /* animated */, false /* resetListToTop */,
2593 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002594 }
2595 }
2596
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002597 private void showBrokenAppInstallDialog(final String packageName,
2598 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002599 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002600 .setTitle(R.string.abandoned_promises_title)
2601 .setMessage(R.string.abandoned_promise_explanation)
2602 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2603 .setNeutralButton(R.string.abandoned_clean_this,
2604 new DialogInterface.OnClickListener() {
2605 public void onClick(DialogInterface dialog, int id) {
2606 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2607 mWorkspace.removeAbandonedPromise(packageName, user);
2608 }
2609 })
2610 .create().show();
2611 return;
2612 }
2613
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002614 /**
2615 * Event handler for an app shortcut click.
2616 *
2617 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2618 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002619 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002620 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2621 Object tag = v.getTag();
2622 if (!(tag instanceof ShortcutInfo)) {
2623 throw new IllegalArgumentException("Input must be a Shortcut");
2624 }
2625
2626 // Open shortcut
2627 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002628
2629 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002630 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2631 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002632 // Launch activity anyway, framework will tell the user why the app is suspended.
2633 } else {
2634 int error = R.string.activity_not_available;
2635 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2636 error = R.string.safemode_shortcut_error;
2637 }
2638 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2639 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002640 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002641 }
2642
Chris Wren40c5ed32014-06-24 18:24:23 -04002643 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002644 if ((v instanceof BubbleTextView)
2645 && shortcut.isPromise()
2646 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002647 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002648 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002649 new DialogInterface.OnClickListener() {
2650 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002651 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002652 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002653 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002654 return;
2655 }
2656
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002657 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002658 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002659 }
2660
Adam Cohen091440a2015-03-18 14:16:05 -07002661 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002662 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002663 final ShortcutInfo shortcut;
2664 final Intent intent;
2665 if (tag instanceof ShortcutInfo) {
2666 shortcut = (ShortcutInfo) tag;
2667 intent = shortcut.intent;
2668 int[] pos = new int[2];
2669 v.getLocationOnScreen(pos);
2670 intent.setSourceBounds(new Rect(pos[0], pos[1],
2671 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002672
Sunny Goyal508da152014-08-14 10:53:27 -07002673 } else if (tag instanceof AppInfo) {
2674 shortcut = null;
2675 intent = ((AppInfo) tag).intent;
2676 } else {
2677 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2678 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002679
2680 boolean success = startActivitySafely(v, intent, tag);
Hyunyoung Songaa953652016-04-19 18:30:24 -07002681 getUserEventDispatcher().logAppLaunch(v, intent);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002682
2683 if (success && v instanceof BubbleTextView) {
2684 mWaitingForResume = (BubbleTextView) v;
2685 mWaitingForResume.setStayPressed(true);
2686 }
2687 }
2688
2689 /**
2690 * Event handler for a folder icon click.
2691 *
2692 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2693 */
2694 protected void onClickFolderIcon(View v) {
2695 if (LOGD) Log.d(TAG, "onClickFolder");
2696 if (!(v instanceof FolderIcon)){
2697 throw new IllegalArgumentException("Input must be a FolderIcon");
2698 }
2699
2700 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002701 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002702 // Open the requested folder
Adam Cohen37b2a492016-04-06 18:36:06 -07002703 openFolder(folderIcon);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002704 }
Michael Jurka5130e402011-10-13 04:55:35 -07002705 }
2706
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002707 /**
2708 * Event handler for the (Add) Widgets button that appears after a long press
2709 * on the home screen.
2710 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002711 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002712 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002713 if (mIsSafeModeEnabled) {
2714 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2715 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002716 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Adam Cohen9211d422014-10-07 18:14:53 -07002717 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002718 }
2719
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002720 /**
2721 * Event handler for the wallpaper picker button that appears after a long press
2722 * on the home screen.
2723 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002724 protected void onClickWallpaperPicker(View v) {
Sunny Goyal1ed6c4a2016-04-21 15:16:11 -07002725 if (!Utilities.isWallapaperAllowed(this)) {
2726 Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show();
2727 return;
2728 }
2729
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002730 String pickerPackage = getString(R.string.wallpaper_picker_package);
2731 if (TextUtils.isEmpty(pickerPackage)) {
2732 pickerPackage = PackageManagerHelper.getWallpaperPickerPackage(getPackageManager());
2733 }
2734
Tony Wickham785f7a52015-08-31 17:28:32 -07002735 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2736 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002737 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER)
2738 .setPackage(pickerPackage)
2739 .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset),
2740 REQUEST_PICK_WALLPAPER);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002741 }
2742
2743 /**
2744 * Event handler for a click on the settings button that appears after a long press
2745 * on the home screen.
2746 */
Sunny Goyal745bad92016-05-02 10:54:12 -07002747 private void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002748 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Sunny Goyal745bad92016-05-02 10:54:12 -07002749 startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES)
2750 .setPackage(getPackageName()));
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002751 }
2752
Adam Cohen61f560d2013-09-30 15:58:20 -07002753 public View.OnTouchListener getHapticFeedbackTouchListener() {
2754 if (mHapticFeedbackTouchListener == null) {
2755 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002756 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002757 @Override
2758 public boolean onTouch(View v, MotionEvent event) {
2759 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2760 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2761 }
2762 return false;
2763 }
2764 };
2765 }
2766 return mHapticFeedbackTouchListener;
2767 }
2768
Tony Wickhame2217252016-03-22 16:34:23 -07002769 @Override
2770 public void onAccessibilityStateChanged(boolean enabled) {
2771 mDragLayer.onAccessibilityStateChanged(enabled);
2772 }
2773
Adam Cohen9211d422014-10-07 18:14:53 -07002774 public void onDragStarted(View view) {
2775 if (isOnCustomContent()) {
2776 // Custom content screen doesn't participate in drag and drop. If on custom
2777 // content screen, move to default.
2778 moveWorkspaceToDefaultScreen();
2779 }
Adam Cohen9211d422014-10-07 18:14:53 -07002780 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002781
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002782 /**
2783 * Called when the user stops interacting with the launcher.
2784 * This implies that the user is now on the homescreen and is not doing housekeeping.
2785 */
Adam Cohen9211d422014-10-07 18:14:53 -07002786 protected void onInteractionEnd() {
2787 if (mLauncherCallbacks != null) {
2788 mLauncherCallbacks.onInteractionEnd();
2789 }
2790 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002791
2792 /**
2793 * Called when the user starts interacting with the launcher.
2794 * The possible interactions are:
2795 * - open all apps
2796 * - reorder an app shortcut, or a widget
2797 * - open the overview mode.
2798 * This is a good time to stop doing things that only make sense
2799 * when the user is on the homescreen and not doing housekeeping.
2800 */
Adam Cohen9211d422014-10-07 18:14:53 -07002801 protected void onInteractionBegin() {
2802 if (mLauncherCallbacks != null) {
2803 mLauncherCallbacks.onInteractionBegin();
2804 }
2805 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002806
Winson Chungcd99cd32015-04-29 11:03:24 -07002807 /** Updates the interaction state. */
2808 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002809 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002810 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002811 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2812 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002813 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002814 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002815 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002816 onInteractionEnd();
2817 }
2818 }
2819
Winson Chung8f1eff72015-05-28 17:33:40 -07002820 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002821 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002822 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002823 // Only launch using the new animation if the shortcut has not opted out (this is a
2824 // private contract between launcher and may be ignored in the future).
2825 boolean useLaunchAnimation = (v != null) &&
2826 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002827 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2828 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002829
Kenny Guy1317e2d2014-05-08 18:52:50 +01002830 UserHandleCompat user = null;
2831 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2832 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2833 user = userManager.getUserForSerialNumber(serialNumber);
2834 }
2835
2836 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002837 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002838 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002839 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002840 int left = 0, top = 0;
2841 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2842 if (v instanceof TextView) {
2843 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002844 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2845 if (icon != null) {
2846 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002847 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002848 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002849 width = bounds.width();
2850 height = bounds.height();
2851 }
2852 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002853 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2854 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002855 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002856 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002857 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002858 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002859 // On L devices, we use the device default slide-up transition.
2860 // On L MR1 devices, we a custom version of the slide-up transition which
2861 // doesn't have the delay present in the device default.
2862 opts = ActivityOptions.makeCustomAnimation(this,
2863 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002864 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002865 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002866 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002867
2868 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2869 // Could be launching some bookkeeping activity
2870 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002871 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002872 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002873 launcherApps.startActivityForProfile(intent.getComponent(), user,
2874 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002875 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002876 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002877 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002878 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2879 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2880 // corresponding permission. Show the appropriate permission prompt if that
2881 // is the case.
2882 if (intent.getComponent() == null
2883 && Intent.ACTION_CALL.equals(intent.getAction())
2884 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2885 PackageManager.PERMISSION_GRANTED) {
2886 // TODO: Rename sPendingAddItem to a generic name.
2887 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2888 0, (ItemInfo) tag);
2889 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2890 REQUEST_PERMISSION_CALL_PHONE);
2891 return false;
2892 }
2893 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002895 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002896 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002897 "or use the exported attribute for this activity. "
2898 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002900 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002901 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002902
Winson Chungbedf9232015-07-10 12:38:30 -07002903 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002904 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002905 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2906 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2907 return false;
2908 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002909 try {
2910 success = startActivity(v, intent, tag);
2911 } catch (ActivityNotFoundException e) {
2912 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2913 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2914 }
2915 return success;
2916 }
2917
Adam Cohen268c4752012-06-06 17:47:33 -07002918 /**
2919 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2920 * in the DragLayer in the exact absolute location of the original FolderIcon.
2921 */
2922 private void copyFolderIconToImage(FolderIcon fi) {
2923 final int width = fi.getMeasuredWidth();
2924 final int height = fi.getMeasuredHeight();
2925
2926 // Lazy load ImageView, Bitmap and Canvas
2927 if (mFolderIconImageView == null) {
2928 mFolderIconImageView = new ImageView(this);
2929 }
2930 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2931 mFolderIconBitmap.getHeight() != height) {
2932 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2933 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2934 }
2935
2936 DragLayer.LayoutParams lp;
2937 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2938 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2939 } else {
2940 lp = new DragLayer.LayoutParams(width, height);
2941 }
2942
Adam Cohen307fe232012-08-16 17:55:58 -07002943 // The layout from which the folder is being opened may be scaled, adjust the starting
2944 // view size by this scale factor.
2945 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002946 lp.customPosition = true;
2947 lp.x = mRectForFolderAnimation.left;
2948 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002949 lp.width = (int) (scale * width);
2950 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002951
2952 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2953 fi.draw(mFolderIconCanvas);
2954 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002955 if (fi.getFolder() != null) {
2956 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2957 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002958 }
Adam Cohen268c4752012-06-06 17:47:33 -07002959 // Just in case this image view is still in the drag layer from a previous animation,
2960 // we remove it and re-add it.
2961 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2962 mDragLayer.removeView(mFolderIconImageView);
2963 }
2964 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002965 if (fi.getFolder() != null) {
2966 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002967 }
Adam Cohen268c4752012-06-06 17:47:33 -07002968 }
2969
Adam Cohen37b2a492016-04-06 18:36:06 -07002970 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002971 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07002972 FolderInfo info = (FolderInfo) fi.getTag();
2973 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2974 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002975 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2976 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002977 }
2978
Adam Cohen268c4752012-06-06 17:47:33 -07002979 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2980 copyFolderIconToImage(fi);
2981 fi.setVisibility(View.INVISIBLE);
2982
Sunny Goyal5d2fc322015-07-06 22:52:49 -07002983 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
2984 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002985 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002986 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2987 }
2988 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002989 oa.start();
2990 }
2991
Sunny Goyal935fca12015-10-13 10:19:01 -07002992 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002993 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07002994 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002995
Adam Cohen268c4752012-06-06 17:47:33 -07002996 // We remove and re-draw the FolderIcon in-case it has changed
2997 mDragLayer.removeView(mFolderIconImageView);
2998 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08002999
3000 if (cl != null) {
3001 cl.clearFolderLeaveBehind();
3002 }
3003
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003004 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003005 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003006 oa.addListener(new AnimatorListenerAdapter() {
3007 @Override
3008 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003009 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003010 // Remove the ImageView copy of the FolderIcon and make the original visible.
3011 mDragLayer.removeView(mFolderIconImageView);
3012 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003013 }
3014 }
3015 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003016 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003017 if (!animate) {
3018 oa.end();
3019 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003020 }
3021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003022 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003023 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003024 * is animated relative to the specified View. If the View is null, no animation
3025 * is played.
3026 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003027 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003028 */
Adam Cohen37b2a492016-04-06 18:36:06 -07003029 public void openFolder(FolderIcon folderIcon) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003030
Adam Cohenfb91f302012-06-11 15:45:18 -07003031 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003032 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3033 if (openFolder != null && openFolder != folder) {
3034 // Close any open folder before opening a folder.
3035 closeFolder();
3036 }
3037
Adam Cohena9cf38f2011-05-02 15:36:58 -07003038 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003039
Adam Cohena9cf38f2011-05-02 15:36:58 -07003040 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003041
Sunny Goyalf4066152015-04-15 09:42:19 -07003042 // While the folder is open, the position of the icon cannot change.
3043 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3044
Adam Cohen4554ee12011-08-03 16:13:21 -07003045 // Just verify that the folder hasn't already been added to the DragLayer.
3046 // There was a one-off crash where the folder had a parent already.
3047 if (folder.getParent() == null) {
3048 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003049 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003050 } else {
3051 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3052 folder.getParent() + ").");
3053 }
Adam Cohen37b2a492016-04-06 18:36:06 -07003054 folder.animateOpen();
3055
3056 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003057
3058 // Notify the accessibility manager that this folder "window" has appeared and occluded
3059 // the workspace items
3060 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3061 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003062 }
3063
3064 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003065 closeFolder(true);
3066 }
3067
3068 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003069 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003070 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003071 if (folder.isEditingName()) {
3072 folder.dismissEditingName();
3073 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003074 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003075 }
3076 }
3077
Sunny Goyal935fca12015-10-13 10:19:01 -07003078 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003079 animate &= !Utilities.isPowerSaverOn(this);
3080
Adam Cohen4554ee12011-08-03 16:13:21 -07003081 folder.getInfo().opened = false;
3082
3083 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3084 if (parent != null) {
3085 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003086 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003087 if (fi != null) {
3088 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3089 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003090 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003091 if (animate) {
3092 folder.animateClosed();
3093 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003094 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003095 }
Winson Chung83ca4802013-04-12 15:10:52 -07003096
Sunny Goyal935fca12015-10-13 10:19:01 -07003097 // Notify the accessibility manager that this folder "window" has disappeared and no
3098 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003099 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003100 }
3101
Tony Wickhamdadb3042016-02-24 11:07:00 -08003102 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003103 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003104 if (!isDraggingEnabled()) return false;
3105 if (isWorkspaceLocked()) return false;
3106 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003107
Winson Chung76648c52015-07-10 14:33:23 -07003108 if (v == mAllAppsButton) {
3109 onLongClickAllAppsButton(v);
3110 return true;
3111 }
3112
Adam Cohen1697b792013-09-17 19:08:21 -07003113 if (v instanceof Workspace) {
3114 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003115 if (!mWorkspace.isTouchActive()) {
3116 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003117 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3118 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3119 return true;
3120 } else {
3121 return false;
3122 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003123 } else {
3124 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003125 }
Adam Cohen1697b792013-09-17 19:08:21 -07003126 }
3127
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003128 CellLayout.CellInfo longClickCellInfo = null;
3129 View itemUnderLongClick = null;
3130 if (v.getTag() instanceof ItemInfo) {
3131 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003132 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003133 itemUnderLongClick = longClickCellInfo.cell;
3134 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003135 }
3136
Winson Chung3d503fb2011-07-13 17:25:49 -07003137 // The hotseat touch handling does not go through Workspace, and we always allow long press
3138 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003139 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003140 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003141 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003142 // User long pressed on empty space
3143 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3144 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003145 if (mWorkspace.isInOverviewMode()) {
3146 mWorkspace.startReordering(v);
3147 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003148 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003149 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003150 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003151 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3152 mHotseat.getOrderInHotseat(
3153 longClickCellInfo.cellX,
3154 longClickCellInfo.cellY));
3155 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003156 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003157 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003158 }
3159 }
3160 }
3161 return true;
3162 }
3163
Winson Chung3d503fb2011-07-13 17:25:49 -07003164 boolean isHotseatLayout(View layout) {
3165 return mHotseat != null && layout != null &&
3166 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3167 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003168
Winson Chung3d503fb2011-07-13 17:25:49 -07003169 /**
3170 * Returns the CellLayout of the specified container at the specified screen.
3171 */
Sunny Goyal92820592015-03-02 11:31:35 -08003172 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003173 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3174 if (mHotseat != null) {
3175 return mHotseat.getLayout();
3176 } else {
3177 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003178 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003179 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003180 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003181 }
3182 }
3183
Winson Chungb745afb2015-03-02 11:51:23 -08003184 /**
3185 * For overridden classes.
3186 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003187 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003188 return isAppsViewVisible();
3189 }
3190
3191 public boolean isAppsViewVisible() {
3192 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3193 }
3194
3195 public boolean isWidgetsViewVisible() {
3196 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003197 }
3198
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003199 private void setWorkspaceBackground(int background) {
3200 switch (background) {
3201 case WORKSPACE_BACKGROUND_TRANSPARENT:
3202 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3203 break;
3204 case WORKSPACE_BACKGROUND_BLACK:
3205 getWindow().setBackgroundDrawable(null);
3206 break;
3207 default:
3208 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3209 }
Craig Mautner360310b2012-10-26 15:13:08 -07003210 }
3211
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003212 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003213 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3214 int curflags = getWindow().getAttributes().flags
3215 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3216 if (wpflags != curflags) {
3217 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3218 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003219 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003220 }
3221
Michael Jurkae326f182011-11-21 14:05:46 -08003222 @Override
3223 public void onTrimMemory(int level) {
3224 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003225 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3226 // The widget preview db can result in holding onto over
3227 // 3MB of memory for caching which isn't necessary.
3228 SQLiteDatabase.releaseMemory();
3229
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003230 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003231 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003232 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003233 if (mLauncherCallbacks != null) {
3234 mLauncherCallbacks.onTrimMemory(level);
3235 }
Michael Jurkae326f182011-11-21 14:05:46 -08003236 }
3237
Winson5c6bdbb2015-09-03 11:36:19 -07003238 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003239 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003240 }
3241
Winson5c6bdbb2015-09-03 11:36:19 -07003242 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003243 boolean changed = mState != State.WORKSPACE ||
3244 mWorkspace.getState() != Workspace.State.NORMAL;
3245 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003246 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003247 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003248 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003249
Michael Jurkab3e22d92011-10-31 15:58:33 -07003250 // Set focus to the AppsCustomize button
3251 if (mAllAppsButton != null) {
3252 mAllAppsButton.requestFocus();
3253 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003254 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003255
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003256 // Change the state *after* we've called all the transition code
3257 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003258
Winson Chung5fb63472011-02-02 17:03:37 -08003259 // Resume the auto-advance of widgets
3260 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003261 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003262
Winson Chung0f785722015-04-08 10:27:49 -07003263 if (changed) {
3264 // Send an accessibility event to announce the context change
3265 getWindow().getDecorView()
3266 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003267 }
Winson5c6bdbb2015-09-03 11:36:19 -07003268 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003269 }
3270
Winsone9f27272015-10-13 10:47:51 -07003271 /**
3272 * Shows the overview button.
3273 */
Adam Cohened307df2013-10-02 09:37:31 -07003274 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003275 showOverviewMode(animated, false);
3276 }
3277
3278 /**
3279 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3280 * onto one of the overview panel buttons.
3281 */
3282 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3283 Runnable postAnimRunnable = null;
3284 if (requestButtonFocus) {
3285 postAnimRunnable = new Runnable() {
3286 @Override
3287 public void run() {
3288 // Hitting the menu button when in touch mode does not trigger touch mode to
3289 // be disabled, so if requested, force focus on one of the overview panel
3290 // buttons.
3291 mOverviewPanel.requestFocusFromTouch();
3292 }
3293 };
3294 }
Adam Cohened307df2013-10-02 09:37:31 -07003295 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003296 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003297 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003298 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003299 }
3300
Winson Chungb745afb2015-03-02 11:51:23 -08003301 /**
3302 * Shows the apps view.
3303 */
Winson Chung76648c52015-07-10 14:33:23 -07003304 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3305 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003306 if (resetListToTop) {
3307 mAppsView.scrollToTop();
3308 }
Winson Chung4ac30062015-05-08 17:34:17 -07003309 if (updatePredictedApps) {
3310 tryAndUpdatePredictedApps();
3311 }
Winson Chung76648c52015-07-10 14:33:23 -07003312 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003313 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003314
Winson Chungb745afb2015-03-02 11:51:23 -08003315 /**
3316 * Shows the widgets view.
3317 */
3318 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003319 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003320 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003321 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003322 }
Winson Chung76648c52015-07-10 14:33:23 -07003323 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003324
3325 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003326 @Override
3327 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003328 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003329 }
3330 });
Winson Chungb745afb2015-03-02 11:51:23 -08003331 }
3332
3333 /**
3334 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003335 *
3336 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003337 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003338 // TODO: calling method should use the return value so that when {@code false} is returned
3339 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003340 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003341 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3342 mState != State.WIDGETS_SPRING_LOADED) {
3343 return false;
3344 }
3345 if (toState != State.APPS && toState != State.WIDGETS) {
3346 return false;
3347 }
Winson Chungb745afb2015-03-02 11:51:23 -08003348
3349 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003350 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3351 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003352 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003353 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003354 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003355
Michael Jurkab3e22d92011-10-31 15:58:33 -07003356 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003357 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003358
3359 // Pause the auto-advance of widgets until we are out of AllApps
3360 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003361 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003362 closeFolder();
3363
3364 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003365 getWindow().getDecorView()
3366 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003367 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003368 }
3369
Winson Chungcd99cd32015-04-29 11:03:24 -07003370 /**
3371 * Updates the workspace and interaction state on state change, and return the animation to this
3372 * new state.
3373 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003374 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003375 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003376 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003377 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003378 updateInteraction(fromState, toState);
3379 return anim;
3380 }
3381
Jun Mukaif0033da2015-08-04 18:34:30 -07003382 public void onLauncherClingShown() {
3383 // When a launcher cling appears, it should cover the underlying layers, so their focus
3384 // should be blocked.
3385 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3386 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3387 }
3388 }
3389
3390 public void onLauncherClingDismissed() {
3391 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3392 }
3393
Hyunyoung Song3f471442015-04-08 19:01:34 -07003394 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003395 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003396 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003397 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003398 }
Winson Chungb745afb2015-03-02 11:51:23 -08003399
Winson Chung006ee262015-08-03 14:40:11 -07003400 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003401 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003402 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003403
3404 if (isAppsViewVisible()) {
3405 mState = State.APPS_SPRING_LOADED;
3406 } else if (isWidgetsViewVisible()) {
3407 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003408 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003409 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003410 } else {
3411 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003412 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003413 }
Adam Cohen7777d962011-08-18 18:58:38 -07003414
Hyunyoung Song3f471442015-04-08 19:01:34 -07003415 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003416 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003417 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003418
Winson Chunge7a03942011-08-05 15:05:12 -07003419 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003420 @Override
3421 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003422 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003423 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3424 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003425 // Before we show workspace, hide all apps again because
3426 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3427 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003428 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003429 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003430 } else {
3431 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003432 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003433 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003434 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003435 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003436
Tony Wickhame0c33232016-02-08 11:37:04 -08003437 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003438 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3439 || mState == State.WIDGETS_SPRING_LOADED;
3440 }
3441
Michael Jurkad3ef3062010-11-23 16:23:58 -08003442 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003443 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003444 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003445 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003446 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003447 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003448 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3449 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003450 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003451 }
3452
Winson Chung4ac30062015-05-08 17:34:17 -07003453 /**
3454 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3455 * resumed.
3456 */
3457 private void tryAndUpdatePredictedApps() {
3458 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003459 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003460 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003461 mAppsView.setPredictedApps(apps);
Hyunyoung Songaa953652016-04-19 18:30:24 -07003462 getUserEventDispatcher().setPredictedApps(apps);
Winson Chung4ac30062015-05-08 17:34:17 -07003463 }
3464 }
3465 }
3466
Michael Jurkab3e22d92011-10-31 15:58:33 -07003467 void lockAllApps() {
3468 // TODO
3469 }
3470
3471 void unlockAllApps() {
3472 // TODO
3473 }
3474
Winsonf768d932015-09-25 16:12:35 -07003475 public boolean launcherCallbacksProvidesSearch() {
3476 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3477 }
3478
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003479 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003480 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003481 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003482 }
3483
Adam Cohen24ce0b32014-01-14 16:18:14 -08003484 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003485 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3486 if (searchProvider == null) {
3487 return null;
3488 }
3489
3490 Bundle opts = new Bundle();
3491 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003492 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003493
Tony Wickham3a3517f2015-10-06 11:27:04 -07003494 // Determine the min and max dimensions of the widget.
3495 LauncherAppState app = LauncherAppState.getInstance();
3496 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3497 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3498 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003499 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3500 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003501 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003502 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003503 int minWidth = maxWidth;
3504 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003505 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3506 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3507 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3508 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3509 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003510 }
3511 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3512 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3513 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3514 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003515 if (LOGD) {
3516 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3517 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3518 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003519
Tony Wickham775455c2015-10-16 09:49:32 -07003520 if (mLauncherCallbacks != null) {
3521 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3522 }
3523
Sunny Goyalf7258242015-10-19 16:59:07 -07003524 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003525 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003526 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003527 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003528 || (widgetInfo == null)
3529 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003530 // A valid widget is not already bound.
3531 if (widgetId > -1) {
3532 mAppWidgetHost.deleteAppWidgetId(widgetId);
3533 widgetId = -1;
3534 }
3535
3536 // Try to bind a new widget
3537 widgetId = mAppWidgetHost.allocateAppWidgetId();
3538
3539 if (!AppWidgetManagerCompat.getInstance(this)
3540 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3541 mAppWidgetHost.deleteAppWidgetId(widgetId);
3542 widgetId = -1;
3543 }
3544
Sunny Goyalf7258242015-10-19 16:59:07 -07003545 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003546 .putInt(QSB_WIDGET_ID, widgetId)
3547 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003548 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003549 }
3550
Sunny Goyal8d595092015-07-06 12:22:14 -07003551 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003552 if (widgetId != -1) {
3553 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003554 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003555 mQsb.updateAppWidgetOptions(opts);
3556 mQsb.setPadding(0, 0, 0, 0);
3557 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003558 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003559 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003560 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003561 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003562 }
3563
Sunny Goyal22235bc2015-04-03 09:23:43 -07003564 private void reinflateQSBIfNecessary() {
3565 if (mQsb instanceof LauncherAppWidgetHostView &&
3566 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3567 mSearchDropTargetBar.removeView(mQsb);
3568 mQsb = null;
3569 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3570 }
3571 }
3572
Michael Jurkad7c28052012-04-27 15:43:36 -07003573 @Override
3574 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003575 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003576 final List<CharSequence> text = event.getText();
3577 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003578 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003579 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003580 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003581 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003582 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003583 } else if (mWorkspace != null) {
3584 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003585 } else {
3586 text.add(getString(R.string.all_apps_home_button_label));
3587 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003588 return result;
3589 }
3590
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003591 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003592 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003593 */
Adam Cohen091440a2015-03-18 14:16:05 -07003594 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003595 @Override
3596 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003597 closeSystemDialogs();
3598 }
3599 }
3600
3601 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003602 * If the activity is currently paused, signal that we need to run the passed Runnable
3603 * in onResume.
3604 *
3605 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003606 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3607 * wrong when we're not running, and if the activity comes back to what the configuration was
3608 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003609 *
3610 * Implementation of the method from LauncherModel.Callbacks.
3611 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003612 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003613 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003614 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003615 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003616 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003617 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003618 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003619 }
3620 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003621 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003622 return true;
3623 } else {
3624 return false;
3625 }
3626 }
3627
Michael Jurkac402cd92013-05-20 15:49:32 +02003628 private boolean waitUntilResume(Runnable run) {
3629 return waitUntilResume(run, false);
3630 }
3631
Michael Jurka1e2f4652013-07-08 18:03:46 -07003632 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003633 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003634 }
3635
Michael Jurka7607c2f2013-04-03 14:33:19 -07003636 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003637 * If the activity is currently paused, signal that we need to re-run the loader
3638 * in onResume.
3639 *
3640 * This needs to be called from incoming places where resources might have been loaded
3641 * while we are paused. That is becaues the Configuration might be wrong
3642 * when we're not running, and if it comes back to what it was when we
3643 * were paused, we are not restarted.
3644 *
3645 * Implementation of the method from LauncherModel.Callbacks.
3646 *
3647 * @return true if we are currently paused. The caller might be able to
3648 * skip some work in that case since we will come back again.
3649 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003650 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003651 public boolean setLoadOnResume() {
3652 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003653 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003654 mOnResumeNeedsLoad = true;
3655 return true;
3656 } else {
3657 return false;
3658 }
3659 }
3660
3661 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003662 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003663 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003664 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04003665 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003666 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003667 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003668 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003669 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003670 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003671 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003672
Joe Onorato9c1289c2009-08-17 11:03:03 -04003673 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003674 * Clear any pending bind callbacks. This is called when is loader is planning to
3675 * perform a full rebind from scratch.
3676 */
3677 @Override
3678 public void clearPendingBinds() {
3679 mBindOnResumeCallbacks.clear();
3680 if (mPendingExecutor != null) {
3681 mPendingExecutor.markCompleted();
3682 mPendingExecutor = null;
3683 }
3684 }
3685
3686 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003687 * Refreshes the shortcuts shown on the workspace.
3688 *
3689 * Implementation of the method from LauncherModel.Callbacks.
3690 */
3691 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003692 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003693
Winson Chungd64d1762013-08-20 14:37:16 -07003694 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003695 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003696 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003697
Michael Jurka05bf644e2011-11-30 20:28:53 -08003698 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003699 if (mHotseat != null) {
3700 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003701 }
3702 }
3703
Adam Cohendcd297f2013-06-18 13:13:40 -07003704 @Override
3705 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003706 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003707
Adam Cohen5084cba2013-09-03 12:01:16 -07003708 // If there are no screens, we need to have an empty screen
3709 if (orderedScreenIds.size() == 0) {
3710 mWorkspace.addExtraEmptyScreen();
3711 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003712
3713 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003714 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003715 if (hasCustomContentToLeft()) {
3716 mWorkspace.createCustomContentContainer();
3717 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003718 }
Winson Chung64359a52013-07-08 17:17:08 -07003719 }
3720
3721 @Override
3722 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003723 int count = orderedScreenIds.size();
3724 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003725 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003726 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003727 }
3728
Winson Chungd64d1762013-08-20 14:37:16 -07003729 public void bindAppsAdded(final ArrayList<Long> newScreens,
3730 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003731 final ArrayList<ItemInfo> addAnimated,
3732 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003733 Runnable r = new Runnable() {
3734 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003735 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003736 }
3737 };
3738 if (waitUntilResume(r)) {
3739 return;
3740 }
3741
Winson Chungd64d1762013-08-20 14:37:16 -07003742 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003743 if (newScreens != null) {
3744 bindAddScreens(newScreens);
3745 }
Winson Chungd64d1762013-08-20 14:37:16 -07003746
3747 // We add the items without animation on non-visible pages, and with
3748 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003749 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003750 bindItems(addNotAnimated, 0,
3751 addNotAnimated.size(), false);
3752 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003753 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003754 bindItems(addAnimated, 0,
3755 addAnimated.size(), true);
3756 }
Winson Chungc58497e2013-09-03 17:48:37 -07003757
Winson Chung87412982013-10-03 18:34:14 -07003758 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003759 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003760
Winson Chungb745afb2015-03-02 11:51:23 -08003761 if (addedApps != null && mAppsView != null) {
3762 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003763 }
Winson Chungd64d1762013-08-20 14:37:16 -07003764 }
3765
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003766 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767 * Bind the items start-end from the list.
3768 *
3769 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003770 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003771 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003772 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3773 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003774 Runnable r = new Runnable() {
3775 public void run() {
3776 bindItems(shortcuts, start, end, forceAnimateIcons);
3777 }
3778 };
3779 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003780 return;
3781 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003782
Winson Chungf0c6ae02012-03-21 16:10:31 -07003783 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003784 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3785 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003786 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003787 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003788 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003789 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003790 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003791
3792 // Short circuit if we are loading dock items for a configuration which has no dock
3793 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3794 mHotseat == null) {
3795 continue;
3796 }
3797
Sunny Goyal639e9062015-08-19 19:17:06 -07003798 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003799 switch (item.itemType) {
3800 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3801 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003802 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003803 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003804
Winson Chung64359a52013-07-08 17:17:08 -07003805 /*
3806 * TODO: FIX collision case
3807 */
Winson Chungce376632013-07-11 16:12:41 -07003808 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3809 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3810 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003811 View v = cl.getChildAt(item.cellX, item.cellY);
3812 Object tag = v.getTag();
3813 String desc = "Collision while binding workspace item: " + item
3814 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003815 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003816 throw (new RuntimeException(desc));
3817 } else {
3818 Log.d(TAG, desc);
3819 }
Winson Chungce376632013-07-11 16:12:41 -07003820 }
Winson Chung64359a52013-07-08 17:17:08 -07003821 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003822 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003823 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003824 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003825 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003826 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003827 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003828 default:
3829 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003831
3832 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3833 item.cellY, 1, 1);
3834 if (animateIcons) {
3835 // Animate all the applications up now
3836 view.setAlpha(0f);
3837 view.setScaleX(0f);
3838 view.setScaleY(0f);
3839 bounceAnims.add(createNewAppBounceAnimation(view, i));
3840 newShortcutsScreenId = item.screenId;
3841 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003842 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003843
Winson Chung997a9232013-07-24 15:33:46 -07003844 if (animateIcons) {
3845 // Animate to the correct page
3846 if (newShortcutsScreenId > -1) {
3847 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003848 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003849 final Runnable startBounceAnimRunnable = new Runnable() {
3850 public void run() {
3851 anim.playTogether(bounceAnims);
3852 anim.start();
3853 }
3854 };
Winson Chung997a9232013-07-24 15:33:46 -07003855 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003856 // We post the animation slightly delayed to prevent slowdowns
3857 // when we are loading right after we return to launcher.
3858 mWorkspace.postDelayed(new Runnable() {
3859 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003860 if (mWorkspace != null) {
3861 mWorkspace.snapToPage(newScreenIndex);
3862 mWorkspace.postDelayed(startBounceAnimRunnable,
3863 NEW_APPS_ANIMATION_DELAY);
3864 }
Winson Chung94d67682013-09-25 16:29:40 -07003865 }
3866 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003867 } else {
3868 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003869 }
3870 }
Winson Chung64359a52013-07-08 17:17:08 -07003871 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003872 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003873 }
3874
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003875 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3876 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3877 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003878 view.updateAppWidget(null);
3879 view.setOnClickListener(this);
3880 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003881 mWorkspace.requestLayout();
3882 }
3883
Joe Onorato9c1289c2009-08-17 11:03:03 -04003884 /**
3885 * Add the views for a widget to the workspace.
3886 *
3887 * Implementation of the method from LauncherModel.Callbacks.
3888 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003889 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003890 Runnable r = new Runnable() {
3891 public void run() {
3892 bindAppWidget(item);
3893 }
3894 };
3895 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003896 return;
3897 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003898
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003899 if (mIsSafeModeEnabled) {
3900 bindSafeModeWidget(item);
3901 return;
3902 }
3903
Daniel Sandler843e8602010-06-07 14:59:01 -04003904 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3905 if (DEBUG_WIDGETS) {
3906 Log.d(TAG, "bindAppWidget: " + item);
3907 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003908
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003909 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003910
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003911 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3912 // If the provider is not ready, bind as a pending widget.
3913 appWidgetInfo = null;
3914 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3915 // The widget id is not valid. Try to find the widget based on the provider info.
3916 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3917 } else {
3918 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3919 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003920
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003921 // If the provider is ready, but the width is not yet restored, try to restore it.
3922 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3923 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003924 if (appWidgetInfo == null) {
3925 if (DEBUG_WIDGETS) {
3926 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3927 + " belongs to component " + item.providerName
3928 + ", as the povider is null");
3929 }
3930 LauncherModel.deleteItemFromDatabase(this, item);
3931 return;
3932 }
Sunny Goyalff572272014-07-23 13:58:07 -07003933
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003934 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003935 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003936 // Note: This assumes that the id remap broadcast is received before this step.
3937 // If that is not the case, the id remap will be ignored and user may see the
3938 // click to setup view.
Sunny Goyal16466f12016-03-10 05:34:30 -08003939 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003940 pendingInfo.spanX = item.spanX;
3941 pendingInfo.spanY = item.spanY;
3942 pendingInfo.minSpanX = item.minSpanX;
3943 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08003944 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07003945
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003946 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
3947 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
3948 newWidgetId, appWidgetInfo, options);
3949
3950 // TODO consider showing a permission dialog when the widget is clicked.
3951 if (!success) {
3952 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
3953 if (DEBUG_WIDGETS) {
3954 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3955 + " belongs to component " + item.providerName
3956 + ", as the launcher is unable to bing a new widget id");
3957 }
3958 LauncherModel.deleteItemFromDatabase(this, item);
3959 return;
Sunny Goyalff572272014-07-23 13:58:07 -07003960 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003961
3962 item.appWidgetId = newWidgetId;
3963
3964 // If the widget has a configure activity, it is still needs to set it up, otherwise
3965 // the widget is ready to go.
3966 item.restoreStatus = (appWidgetInfo.configure == null)
3967 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
3968 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
3969
3970 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003971 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003972 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003973 // The widget was marked as UI not ready, but there is no configure activity to
3974 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003975 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
3976 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07003977 }
Sunny Goyalff572272014-07-23 13:58:07 -07003978 }
3979
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003980 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07003981 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08003982 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
3983 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07003984 }
Daniel Sandler843e8602010-06-07 14:59:01 -04003985
Sunny Goyal56c73602015-09-25 12:55:01 -07003986 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003987 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07003988 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07003989 deleteWidgetInfo(item);
3990 return;
3991 }
3992
Sunny Goyal233ee962015-08-03 13:05:01 -07003993 item.minSpanX = appWidgetInfo.minSpanX;
3994 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003995 addAppWidgetToWorkspace(
3996 mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo),
3997 item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07003998 } else {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003999 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004000 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07004001 view.updateAppWidget(null);
4002 view.setOnClickListener(this);
4003 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004004 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004005 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004006
Daniel Sandler843e8602010-06-07 14:59:01 -04004007 if (DEBUG_WIDGETS) {
4008 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4009 + (SystemClock.uptimeMillis()-start) + "ms");
4010 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004011 }
4012
Sunny Goyalff572272014-07-23 13:58:07 -07004013 /**
4014 * Restores a pending widget.
4015 *
4016 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07004017 */
4018 private void completeRestoreAppWidget(final int appWidgetId) {
4019 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4020 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4021 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4022 return;
4023 }
4024
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004025 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004026 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4027
4028 mWorkspace.reinflateWidgetsIfNecessary();
4029 LauncherModel.updateItemInDatabase(this, info);
4030 }
4031
Adam Cohen1462de32012-07-24 22:34:36 -07004032 public void onPageBoundSynchronously(int page) {
4033 mSynchronouslyBoundPages.add(page);
4034 }
4035
Sunny Goyal527c7d32015-08-28 15:19:36 -07004036 @Override
4037 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4038 if (mPendingExecutor != null) {
4039 mPendingExecutor.markCompleted();
4040 }
4041 mPendingExecutor = executor;
4042 executor.attachTo(this);
4043 }
4044
4045 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4046 if (mPendingExecutor == executor) {
4047 mPendingExecutor = null;
4048 }
4049 }
4050
Joe Onorato9c1289c2009-08-17 11:03:03 -04004051 /**
4052 * Callback saying that there aren't any more items to bind.
4053 *
4054 * Implementation of the method from LauncherModel.Callbacks.
4055 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004056 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004057 Runnable r = new Runnable() {
4058 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004059 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004060 }
4061 };
4062 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004063 return;
4064 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004065 if (mSavedState != null) {
4066 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004067 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004068 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004069
Joe Onorato9c1289c2009-08-17 11:03:03 -04004070 mSavedState = null;
4071 }
4072
Adam Cohen1462de32012-07-24 22:34:36 -07004073 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004074
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004075 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07004076
4077 // If we received the result of any pending adds while the loader was running (e.g. the
4078 // widget configuration forced an orientation change), process them now.
4079 if (sPendingAddItem != null) {
4080 final long screenId = completeAdd(sPendingAddItem);
4081
4082 // TODO: this moves the user to the page where the pending item was added. Ideally,
4083 // the screen would be guaranteed to exist after bind, and the page would be set through
4084 // the workspace restore process.
4085 mWorkspace.post(new Runnable() {
4086 @Override
4087 public void run() {
4088 mWorkspace.snapToScreenId(screenId);
4089 }
4090 });
4091 sPendingAddItem = null;
4092 }
4093
Sunny Goyal756adbc2015-04-16 15:20:51 -07004094 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004095
4096 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004097 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004098 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004099 }
4100
Winson Chunga0b7e862013-09-05 16:03:15 -07004101 public boolean isAllAppsButtonRank(int rank) {
4102 if (mHotseat != null) {
4103 return mHotseat.isAllAppsButtonRank(rank);
4104 }
4105 return false;
4106 }
4107
Winson Chunga2413752012-04-03 14:22:34 -07004108 private boolean canRunNewAppsAnimation() {
4109 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004110 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4111 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004112 }
4113
Winson Chungc9168342013-06-26 14:54:55 -07004114 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004115 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004116 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4117 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004118 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004119 return bounceAnim;
4120 }
4121
Adam Cohen27772732013-11-11 14:00:56 +00004122 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004123 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004124 }
4125
Tony Wickham3a3517f2015-10-06 11:27:04 -07004126 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004127 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004128 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004129 }
4130
Tony Wickham55616cd2015-09-23 14:55:17 -07004131 public int getSearchBarHeight() {
4132 if (mLauncherCallbacks != null) {
4133 return mLauncherCallbacks.getSearchBarHeight();
4134 }
4135 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4136 }
4137
Winson Chung88fa7412015-08-03 14:25:28 -07004138 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004139 if (mSearchDropTargetBar == null) {
4140 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004141 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004142 if (mQsb != null) {
4143 mSearchDropTargetBar.removeView(mQsb);
4144 mQsb = null;
4145 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004146 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004147 }
4148
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004149 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004150 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4151 * multiple calls to bind the same list.)
4152 */
4153 @Thunk ArrayList<AppInfo> mTmpAppsList;
4154 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4155 public void run() {
4156 bindAllApplications(mTmpAppsList);
4157 mTmpAppsList = null;
4158 }
4159 };
4160
4161 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004162 * Add the icons for all apps.
4163 *
4164 * Implementation of the method from LauncherModel.Callbacks.
4165 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004166 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004167 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4168 mTmpAppsList = apps;
4169 return;
4170 }
4171
Winson Chungb745afb2015-03-02 11:51:23 -08004172 if (mAppsView != null) {
4173 mAppsView.setApps(apps);
4174 }
Adam Cohen9211d422014-10-07 18:14:53 -07004175 if (mLauncherCallbacks != null) {
4176 mLauncherCallbacks.bindAllApplications(apps);
4177 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004178 }
4179
4180 /**
4181 * A package was updated.
4182 *
4183 * Implementation of the method from LauncherModel.Callbacks.
4184 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004185 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004186 Runnable r = new Runnable() {
4187 public void run() {
4188 bindAppsUpdated(apps);
4189 }
4190 };
4191 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004192 return;
4193 }
4194
Winson Chungb745afb2015-03-02 11:51:23 -08004195 if (mAppsView != null) {
4196 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004197 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004198 }
4199
Sunny Goyal4390ace2014-10-13 11:33:11 -07004200 @Override
4201 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4202 Runnable r = new Runnable() {
4203 public void run() {
4204 bindWidgetsRestored(widgets);
4205 }
4206 };
4207 if (waitUntilResume(r)) {
4208 return;
4209 }
4210 mWorkspace.widgetsRestored(widgets);
4211 }
4212
Joe Onorato9c1289c2009-08-17 11:03:03 -04004213 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004214 * Some shortcuts were updated in the background.
4215 *
4216 * Implementation of the method from LauncherModel.Callbacks.
4217 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004218 @Override
4219 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4220 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004221 Runnable r = new Runnable() {
4222 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004223 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004224 }
4225 };
4226 if (waitUntilResume(r)) {
4227 return;
4228 }
4229
Sunny Goyal4390ace2014-10-13 11:33:11 -07004230 if (!updated.isEmpty()) {
4231 mWorkspace.updateShortcuts(updated);
4232 }
4233
4234 if (!removed.isEmpty()) {
4235 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4236 for (ShortcutInfo si : removed) {
4237 removedComponents.add(si.getTargetComponent());
4238 }
4239 mWorkspace.removeItemsByComponentName(removedComponents, user);
4240 // Notify the drag controller
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004241 mDragController.onAppsRemoved(new HashSet<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004242 }
4243 }
4244
4245 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004246 * Update the state of a package, typically related to install state.
4247 *
4248 * Implementation of the method from LauncherModel.Callbacks.
4249 */
Sunny Goyale755d462014-07-22 13:48:29 -07004250 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004251 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4252 Runnable r = new Runnable() {
4253 public void run() {
4254 bindRestoreItemsChange(updates);
4255 }
4256 };
4257 if (waitUntilResume(r)) {
4258 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004259 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004260
Sunny Goyal756adbc2015-04-16 15:20:51 -07004261 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004262 }
4263
4264 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004265 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07004266 * in addition to specific applications to remove, the reason being that
4267 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004268 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07004269 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004270 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004271 @Override
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004272 public void bindWorkspaceComponentsRemoved(
4273 final HashSet<String> packageNames, final HashSet<ComponentName> components,
4274 final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004275 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004276 public void run() {
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004277 bindWorkspaceComponentsRemoved(packageNames, components, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004278 }
Winson Chungd64d1762013-08-20 14:37:16 -07004279 };
4280 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004281 return;
4282 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004283 if (!packageNames.isEmpty()) {
4284 mWorkspace.removeItemsByPackageName(packageNames, user);
4285 }
4286 if (!components.isEmpty()) {
4287 mWorkspace.removeItemsByComponentName(components, user);
4288 }
4289 // Notify the drag controller
4290 mDragController.onAppsRemoved(packageNames, components);
Winson Chung83892cc2013-05-01 16:53:33 -07004291
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004292 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004293
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004294 @Override
4295 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
4296 Runnable r = new Runnable() {
4297 public void run() {
4298 bindAppInfosRemoved(appInfos);
4299 }
4300 };
4301 if (waitUntilResume(r)) {
4302 return;
Joe Onorato36115782010-06-17 13:28:48 -04004303 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004304
Winson Chungdf95eb12013-10-16 14:57:07 -07004305 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004306 if (mAppsView != null) {
4307 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004308 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004309 }
Joe Onoratobe386092009-11-17 17:32:16 -08004310
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004311 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004312 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004313 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004314 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004315 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004316
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004317 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004318 public void bindWidgetsModel(WidgetsModel model) {
4319 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004320 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004321 return;
4322 }
4323
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004324 if (mWidgetsView != null && model != null) {
4325 mWidgetsView.addWidgets(model);
4326 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004327 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004328 }
4329
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004330 @Override
4331 public void notifyWidgetProvidersChanged() {
4332 if (mWorkspace.getState().shouldUpdateWidget) {
4333 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4334 }
4335 }
4336
Winson Chung400438b2011-01-16 17:53:48 -08004337 private int mapConfigurationOriActivityInfoOri(int configOri) {
4338 final Display d = getWindowManager().getDefaultDisplay();
4339 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4340 switch (d.getRotation()) {
4341 case Surface.ROTATION_0:
4342 case Surface.ROTATION_180:
4343 // We are currently in the same basic orientation as the natural orientation
4344 naturalOri = configOri;
4345 break;
4346 case Surface.ROTATION_90:
4347 case Surface.ROTATION_270:
4348 // We are currently in the other basic orientation to the natural orientation
4349 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4350 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4351 break;
4352 }
4353
4354 int[] oriMap = {
4355 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4356 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4357 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4358 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4359 };
4360 // Since the map starts at portrait, we need to offset if this device's natural orientation
4361 // is landscape.
4362 int indexOffset = 0;
4363 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4364 indexOffset = 1;
4365 }
4366 return oriMap[(d.getRotation() + indexOffset) % 4];
4367 }
Adam Cohen446e9402011-09-15 18:21:21 -07004368
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004369 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004370 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004371 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004372 if (Utilities.ATLEAST_JB_MR2) {
4373 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4374 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004375 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4376 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004377 }
Winson Chung4b919f82012-05-01 10:44:08 -07004378 }
4379 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004380
Winson Chung4b919f82012-05-01 10:44:08 -07004381 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004382 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004383 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004384 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004385 } else {
4386 mHandler.postDelayed(new Runnable() {
4387 public void run() {
4388 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4389 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004390 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004391 }
Winson Chung4b919f82012-05-01 10:44:08 -07004392 }
Winson Chung400438b2011-01-16 17:53:48 -08004393 }
4394
Adam Cohenea90f832014-05-21 15:03:34 -07004395 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004396 * To be overridden by subclasses to indicate that there is an activity to launch
4397 * before showing the standard launcher experience.
4398 */
4399 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004400 if (mLauncherCallbacks != null) {
4401 return mLauncherCallbacks.hasFirstRunActivity();
4402 }
Adam Cohen432609a2014-03-13 17:03:22 -07004403 return false;
4404 }
4405
4406 /**
4407 * To be overridden by subclasses to launch any first run activity
4408 */
4409 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004410 if (mLauncherCallbacks != null) {
4411 return mLauncherCallbacks.getFirstRunActivity();
4412 }
Adam Cohen432609a2014-03-13 17:03:22 -07004413 return null;
4414 }
4415
Winson Chunga6945242014-01-08 14:04:34 -08004416 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004417 return !ActivityManager.isRunningInTestHarness() &&
4418 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004419 }
4420
Adam Cohen4a9423d2014-03-28 14:22:31 -07004421 protected boolean hasRunFirstRunActivity() {
4422 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4423 }
4424
Adam Cohen432609a2014-03-13 17:03:22 -07004425 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004426 if (shouldRunFirstRunActivity() &&
4427 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004428 Intent firstRunIntent = getFirstRunActivity();
4429 if (firstRunIntent != null) {
4430 startActivity(firstRunIntent);
4431 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004432 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004433 }
4434 }
Adam Cohen432609a2014-03-13 17:03:22 -07004435 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004436 }
4437
4438 private void markFirstRunActivityShown() {
4439 SharedPreferences.Editor editor = mSharedPrefs.edit();
4440 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4441 editor.apply();
4442 }
4443
Adam Cohen432609a2014-03-13 17:03:22 -07004444 /**
4445 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4446 * screen that must be displayed and dismissed.
4447 */
4448 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004449 if (mLauncherCallbacks != null) {
4450 return mLauncherCallbacks.hasDismissableIntroScreen();
4451 }
Adam Cohen432609a2014-03-13 17:03:22 -07004452 return false;
4453 }
4454
4455 /**
4456 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4457 */
4458 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004459 if (mLauncherCallbacks != null) {
4460 return mLauncherCallbacks.getIntroScreen();
4461 }
Adam Cohen432609a2014-03-13 17:03:22 -07004462 return null;
4463 }
4464
4465 /**
4466 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4467 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4468 */
4469 private boolean shouldShowIntroScreen() {
4470 return hasDismissableIntroScreen() &&
4471 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4472 }
4473
4474 protected void showIntroScreen() {
4475 View introScreen = getIntroScreen();
4476 changeWallpaperVisiblity(false);
4477 if (introScreen != null) {
4478 mDragLayer.showOverlayView(introScreen);
4479 }
4480 }
4481
4482 public void dismissIntroScreen() {
4483 markIntroScreenDismissed();
4484 if (showFirstRunActivity()) {
4485 // We delay hiding the intro view until the first run activity is showing. This
4486 // avoids a blip.
4487 mWorkspace.postDelayed(new Runnable() {
4488 @Override
4489 public void run() {
4490 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004491 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004492 }
4493 }, ACTIVITY_START_DELAY);
4494 } else {
4495 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004496 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004497 }
4498 changeWallpaperVisiblity(true);
4499 }
4500
4501 private void markIntroScreenDismissed() {
4502 SharedPreferences.Editor editor = mSharedPrefs.edit();
4503 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4504 editor.apply();
4505 }
4506
Adam Cohen091440a2015-03-18 14:16:05 -07004507 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004508 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4509 // on the device, then we always show the first run cling experience (or if there is no
4510 // launcher2). Otherwise, we prompt the user upon started for migration
4511 LauncherClings launcherClings = new LauncherClings(this);
4512 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004513 mClings = launcherClings;
Sunny Goyal1acb9e92016-05-16 12:41:09 -07004514 if (canMigrateFromOldLauncherDb()) {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004515 launcherClings.showMigrationCling();
4516 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004517 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004518 }
4519 }
4520 }
4521
Sunny Goyal1acb9e92016-05-16 12:41:09 -07004522 private boolean canMigrateFromOldLauncherDb() {
4523 // Return true if launcher was not preinstalled and and old content provider exists.
4524 return ((getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) &&
4525 providerExists(MIGRATE_AUTHORITY) &&
4526 providerExists(Uri.parse(getString(R.string.old_launcher_provider_uri)).getAuthority());
4527
4528 }
4529
4530 private boolean providerExists(String authority) {
4531 return getPackageManager().resolveContentProvider(authority, 0) != null;
4532 }
4533
4534
Winson Chunga6945242014-01-08 14:04:34 -08004535 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004536 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4537 if (mHotseat != null) mHotseat.setAlpha(1f);
Tony Wickhamf549dab2016-05-16 09:54:06 -07004538 if (mPageIndicator != null) mPageIndicator.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004539 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4540 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004541 }
4542
4543 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004544 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4545 if (mHotseat != null) mHotseat.setAlpha(0f);
Tony Wickhamf549dab2016-05-16 09:54:06 -07004546 if (mPageIndicator != null) mPageIndicator.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004547 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4548 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004549 }
4550
Winson Chung5ffd51d2015-06-25 11:36:50 -07004551 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004552 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004553 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004554 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004555 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004556 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004557 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4558 if (userHandle != null) {
4559 user = UserHandleCompat.fromUser(userHandle);
4560 }
4561 }
4562 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004563 }
4564
4565 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004566 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004567 if (user == null) {
4568 user = UserHandleCompat.myUserHandle();
4569 }
4570
4571 // Called from search suggestion, add the profile extra to the intent to ensure that we
4572 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004573 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004574 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004575 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004576 return null;
4577 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004578 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004579 }
4580
Winson Chung5ffd51d2015-06-25 11:36:50 -07004581 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004582 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4583 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004584 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004585 UserHandleCompat.myUserHandle());
4586 }
4587
Winson Chung5ffd51d2015-06-25 11:36:50 -07004588 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004589 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4590 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004591 mWorkspace.onExternalDragStartedWithItem(dragView);
4592 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004593 }
4594
Winson Chung5ffd51d2015-06-25 11:36:50 -07004595 protected void moveWorkspaceToDefaultScreen() {
4596 mWorkspace.moveToDefaultScreen(false);
4597 }
4598
Winson Chung80baf5a2010-08-09 16:03:15 -07004599 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004600 * Returns a FastBitmapDrawable with the icon, accurately sized.
4601 */
4602 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4603 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4604 d.setFilterBitmap(true);
4605 resizeIconDrawable(d);
4606 return d;
4607 }
4608
4609 /**
4610 * Resizes an icon drawable to the correct icon size.
4611 */
Winson5fbe0742015-09-30 15:33:00 -07004612 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004613 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004614 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004615 }
4616
4617 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004618 * Prints out out state for debugging.
4619 */
4620 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004621 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004622 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004623 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4624 Log.d(TAG, "mRestoring=" + mRestoring);
4625 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Joe Onoratobe386092009-11-17 17:32:16 -08004626 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004627 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004628
Daniel Sandler325dc232013-06-05 22:57:57 -04004629 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004630 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004631
4632 @Override
4633 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4634 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004635 // Dump workspace
4636 writer.println(prefix + "Workspace Items");
4637 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4638 writer.println(prefix + " Homescreen " + i);
4639
4640 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4641 for (int j = 0; j < layout.getChildCount(); j++) {
4642 Object tag = layout.getChildAt(j).getTag();
4643 if (tag != null) {
4644 writer.println(prefix + " " + tag.toString());
4645 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004646 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004647 }
Sunny Goyala1365452015-10-01 15:46:24 -07004648
4649 writer.println(prefix + " Hotseat");
4650 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4651 for (int j = 0; j < layout.getChildCount(); j++) {
4652 Object tag = layout.getChildAt(j).getTag();
4653 if (tag != null) {
4654 writer.println(prefix + " " + tag.toString());
4655 }
4656 }
4657
Sunny Goyal713edfc2016-05-06 09:58:34 -07004658 try {
4659 FileLog.flushAll(writer);
4660 } catch (Exception e) {
4661 // Ignore
Sunny Goyala1365452015-10-01 15:46:24 -07004662 }
4663
Adam Cohen9211d422014-10-07 18:14:53 -07004664 if (mLauncherCallbacks != null) {
4665 mLauncherCallbacks.dump(prefix, fd, writer, args);
4666 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004667 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004668
Adam Cohen59400422014-03-05 18:07:04 -08004669 public static CustomAppWidget getCustomAppWidget(String name) {
4670 return sCustomAppWidgets.get(name);
4671 }
4672
4673 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4674 return sCustomAppWidgets;
4675 }
4676
Sunny Goyal29538332016-02-18 09:10:19 -08004677 public static List<View> getFolderContents(View icon) {
4678 if (icon instanceof FolderIcon) {
4679 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4680 } else {
4681 return Collections.EMPTY_LIST;
4682 }
4683 }
Sunny Goyal745bad92016-05-02 10:54:12 -07004684
4685 private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable {
4686
4687 @Override
4688 public void onSharedPreferenceChanged(
4689 SharedPreferences sharedPreferences, String key) {
4690 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
4691 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
4692 if (!waitUntilResume(this, true)) {
4693 run();
4694 }
4695 }
4696 }
4697
4698 @Override
4699 public void run() {
4700 setOrientation();
4701 }
4702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004703}
Michael Jurka2763be32011-02-24 11:19:57 -08004704
Dan Sandlerd5024042014-01-09 15:01:33 -05004705interface DebugIntents {
4706 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4707 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004708}