blob: 5873368028c4344fb434204d441b032df8724e89 [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;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070051import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Tony Wickhama3c74d12015-10-23 11:43:47 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070060import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020061import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020063import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080064import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070065import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070066import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040067import android.os.SystemClock;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070068import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.HapticFeedbackConstants;
76import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070078import android.view.MotionEvent;
79import android.view.Surface;
80import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070081import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080082import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070083import android.view.ViewGroup;
84import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080086import android.view.accessibility.AccessibilityEvent;
Tony Wickhame2217252016-03-22 16:34:23 -070087import android.view.accessibility.AccessibilityManager;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070088import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080092import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070094
Sunny Goyal651077b2014-06-30 14:15:31 -070095import com.android.launcher3.DropTarget.DragObject;
96import com.android.launcher3.PagedView.PageSwitchListener;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070097import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080098import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -070099import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100100import com.android.launcher3.compat.LauncherActivityInfoCompat;
101import com.android.launcher3.compat.LauncherAppsCompat;
102import com.android.launcher3.compat.UserHandleCompat;
103import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800104import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700105import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700106import com.android.launcher3.dragndrop.DragController;
107import com.android.launcher3.dragndrop.DragLayer;
108import com.android.launcher3.dragndrop.DragView;
Tony Wickham827cef22016-03-17 15:39:39 -0700109import com.android.launcher3.dynamicui.ExtractedColors;
Sunny Goyal26119432016-02-18 22:09:23 +0000110import com.android.launcher3.folder.Folder;
111import com.android.launcher3.folder.FolderIcon;
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800112import com.android.launcher3.logging.LoggerUtils;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800113import com.android.launcher3.logging.UserEventLogger;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700114import com.android.launcher3.model.WidgetsModel;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800115import com.android.launcher3.userevent.nano.LauncherLogProto;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700116import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700117import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700118import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700119import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700120import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700121import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700122import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700123import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700124
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700125import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700126import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700127import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700129import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800130import java.util.Collections;
Adam Cohen4caf2982013-08-20 18:54:31 -0700131import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700132import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700133import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700134import java.util.List;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800135import java.util.Locale;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700136
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137/**
138 * Default launcher application.
139 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100140public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700141 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Tony Wickhame2217252016-03-22 16:34:23 -0700142 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener,
143 AccessibilityManager.AccessibilityStateChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700144 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700145 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Daniel Sandlerf061f822013-06-27 13:59:36 -0400147 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700148 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700149 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400150 static final boolean DEBUG_RESUME_TIME = false;
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700151 static final boolean DEBUG_LOGGING = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700152
Dan Sandlerd5024042014-01-09 15:01:33 -0500153 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
154
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700156 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700157 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700158 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Michael Jurka8b805b12012-04-18 14:23:14 -0700160 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700161 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700162
Sunny Goyal28c6b962015-10-12 11:42:05 -0700163 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
164
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700165 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
166 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
167 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
168
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700169 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
170
Mathew Inwood876a8462013-06-14 14:12:41 +0100171 /**
172 * IntentStarter uses request codes starting with this. This must be greater than all activity
173 * request codes used internally.
174 */
175 protected static final int REQUEST_LAST = 100;
176
Michael Jurka0a457bf2012-11-19 14:05:05 -0800177 // To turn on these properties, type
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700178 // adb shell setprop logTap.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800179 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
Winson Chung2672ff92012-05-04 16:22:30 -0700181 // The Intent extra that defines whether to ignore the launch animation
182 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400183 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700184
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 // Type: int
186 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700187 // Type: int
188 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700189 // Type: Content Values / parcelable
190 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700191 // Type: parcelable
192 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000193 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800194 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
Adam Cohen432609a2014-03-13 17:03:22 -0700196 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800197 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
198
Adam Cohen3ed316a2014-07-23 18:21:20 -0700199 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
200 static final String ACTION_FIRST_LOAD_COMPLETE =
201 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
202
Sunny Goyal594d76d2014-11-06 10:12:54 -0800203 private static final String QSB_WIDGET_ID = "qsb_widget_id";
204 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
205
Winson Chunga6945242014-01-08 14:04:34 -0800206 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
207
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700208 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700209 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
210 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700211
Adam Cohen091440a2015-03-18 14:16:05 -0700212 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700213 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700214
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700215 private boolean mIsSafeModeEnabled;
216
Joe Onorato9c1289c2009-08-17 11:03:03 -0400217 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800218 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700219 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700220 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
Winson Chunga2413752012-04-03 14:22:34 -0700222 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700223 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
224 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700225 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700226
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800227 private final BroadcastReceiver mCloseSystemDialogsReceiver
228 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800229
Adam Cohen091440a2015-03-18 14:16:05 -0700230 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700231 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800232 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700233 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800234 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700235
236 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700237
Sunny Goyalffe83f12014-08-14 17:39:34 -0700238 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700239 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700240
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700241 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800242 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800243 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700244
Michael Jurka0280c3b2010-09-17 15:00:07 -0700245 private int[] mTmpAddItemCellCoordinates = new int[2];
246
Sunny Goyal316490e2015-06-02 09:38:28 -0700247 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800248 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700249
Michael Jurka838a4ca2011-02-07 13:33:06 -0800250 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700251 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700252
Winson Chungc51db6a2011-10-05 11:44:49 -0700253 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700254 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700255
256 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700257 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700258
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700259 // Main container view and the model for the widget tray screen.
260 @Thunk WidgetsContainerView mWidgetsView;
261 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700262
Sunny Goyal594d76d2014-11-06 10:12:54 -0800263 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
267 // scroll issues (because the workspace may not have been measured yet) and extra work.
268 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
269 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
271 private SpannableStringBuilder mDefaultKeySsb = null;
272
Adam Cohen091440a2015-03-18 14:16:05 -0700273 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800275 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 private boolean mRestoring;
277 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700278 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279
Michael Jurka1e2f4652013-07-08 18:03:46 -0700280 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700281 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700282 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700283
Joe Onorato9c1289c2009-08-17 11:03:03 -0400284 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800285 private IconCache mIconCache;
Tony Wickham827cef22016-03-17 15:39:39 -0700286 private ExtractedColors mExtractedColors;
Adam Cohen091440a2015-03-18 14:16:05 -0700287 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800288 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700289 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800290 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291
Sunny Goyal639e9062015-08-19 19:17:06 -0700292 private LauncherClings mClings;
293
Adam Cohen61f560d2013-09-30 15:58:20 -0700294 private View.OnTouchListener mHapticFeedbackTouchListener;
295
Adam Cohended9f8d2010-11-03 13:25:16 -0700296 // Related to the auto-advancing of widgets
297 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700298 private static final int ADVANCE_INTERVAL = 20000;
299 private static final int ADVANCE_STAGGER = 250;
300
301 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700302 private long mAutoAdvanceSentTime;
303 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700304 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700305
Winson Chung400438b2011-01-16 17:53:48 -0800306 // Determines how long to wait after a rotation before restoring the screen orientation to
307 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700308 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800309
Adam Cohen091440a2015-03-18 14:16:05 -0700310 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700311
Adam Cohen1462de32012-07-24 22:34:36 -0700312 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700313 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700314
Sunny Goyala1365452015-10-01 15:46:24 -0700315 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
316 private static final Date sDateStamp = new Date();
317 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700318 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700319
Winson Chung46353de2012-02-16 14:05:10 -0800320 // We only want to get the SharedPreferences once since it does an FS stat each time we get
321 // it from the context.
322 private SharedPreferences mSharedPrefs;
323
Winson Chungf0c6ae02012-03-21 16:10:31 -0700324 // Holds the page that we need to animate to, and the icon views that we need to animate up
325 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700326 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700327 private Bitmap mFolderIconBitmap;
328 private Canvas mFolderIconCanvas;
329 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700330
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700331 private DeviceProfile mDeviceProfile;
332
Adam Cohen4b66bf32015-09-18 12:15:19 -0700333 private boolean mMoveToDefaultScreenFromNewIntent;
334
Winson Chung13eb5272015-05-11 16:30:13 -0700335 // This is set to the view that launched the activity that navigated the user away from
336 // launcher. Since there is no callback for when the activity has finished launching, enable
337 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800338 private BubbleTextView mWaitingForResume;
339
Adam Cohen59400422014-03-05 18:07:04 -0800340 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
341 new HashMap<String, CustomAppWidget>();
342
Adam Cohen59400422014-03-05 18:07:04 -0800343 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700344 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
345 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800346 }
347 }
348
Adam Cohen091440a2015-03-18 14:16:05 -0700349 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700350 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700351 if (mWorkspace != null) {
352 mWorkspace.buildPageHardwareLayers();
353 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700354 }
355 };
356
Adam Cohendb364c32014-05-20 14:23:40 -0700357 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358
Adam Cohen091440a2015-03-18 14:16:05 -0700359 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800360 int requestCode;
361 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700362 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700363 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800364 int cellX;
365 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700366 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800367 }
368
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800369 private UserEventLogger mUserEventLogger;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800370
Adam Cohenf9c184a2016-01-15 16:47:43 -0800371 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700372 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400373
374 @Thunk void setOrientation() {
375 if (mRotationEnabled) {
376 unlockScreenOrientation(true);
377 } else {
378 setRequestedOrientation(
379 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700380 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400381 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700382
Sunny Goyal7779d622015-06-11 16:18:39 -0700383 private Runnable mUpdateOrientationRunnable = new Runnable() {
384 public void run() {
385 setOrientation();
386 }
387 };
388
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 @Override
390 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700391 if (DEBUG_STRICT_MODE) {
392 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
393 .detectDiskReads()
394 .detectDiskWrites()
395 .detectNetwork() // or .detectAll() for all detectable problems
396 .penaltyLog()
397 .build());
398 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
399 .detectLeakedSqlLiteObjects()
400 .detectLeakedClosableObjects()
401 .penaltyLog()
402 .penaltyDeath()
403 .build());
404 }
405
Adam Cohen9211d422014-10-07 18:14:53 -0700406 if (mLauncherCallbacks != null) {
407 mLauncherCallbacks.preOnCreate();
408 }
409
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400411
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400412 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700413
Adam Cohen2e6da152015-05-06 11:42:25 -0700414 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700415 mDeviceProfile = getResources().getConfiguration().orientation
416 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700417 app.getInvariantDeviceProfile().landscapeProfile
418 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700419
Sunny Goyalf7258242015-10-19 16:59:07 -0700420 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700421 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800422 mModel = app.setLauncher(this);
423 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700424
Joe Onorato41a12d22009-10-31 18:30:00 -0400425 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700426 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700427
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800428 initLogger();
Daniel Sandlerff02d492013-08-05 02:12:05 -0400429
Sunny Goyalffe83f12014-08-14 17:39:34 -0700430 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700431
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700432 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
433 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700434
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700435 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
436 // this also ensures that any synchronous binding below doesn't re-trigger another
437 // LauncherModel load.
438 mPaused = false;
439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200441 android.os.Debug.startMethodTracing(
442 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 }
444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700446
Tony Wickhameef44322015-10-20 13:24:36 -0700447 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
448 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700450 mDeviceProfile.layout(this);
Tony Wickham827cef22016-03-17 15:39:39 -0700451 mExtractedColors = new ExtractedColors();
452 loadExtractedColorsAndColorItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453
Tony Wickhame2217252016-03-22 16:34:23 -0700454 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
455 .addAccessibilityStateChangeListener(this);
456
Joe Onorato7c312c12009-08-13 21:36:53 -0700457 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700458
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 mSavedState = savedInstanceState;
460 restoreState(mSavedState);
461
462 if (PROFILE_STARTUP) {
463 android.os.Debug.stopMethodTracing();
464 }
465
466 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700467 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700468 // If the user leaves launcher, then we should just load items asynchronously when
469 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700470 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 } else {
472 // We only load the page synchronously if the user rotates (or triggers a
473 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700474 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700475 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800476 }
477
478 // For handling default keys
479 mDefaultKeySsb = new SpannableStringBuilder();
480 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800481
482 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
483 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800484
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800485 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700486 // In case we are on a device with locked rotation, we should look at preferences to check
487 // if the user has specifically allowed rotation.
488 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700489 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700490 }
491
492 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
493 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400494 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700495
Adam Cohen9211d422014-10-07 18:14:53 -0700496 if (mLauncherCallbacks != null) {
497 mLauncherCallbacks.onCreate(savedInstanceState);
498 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700499
500 if (shouldShowIntroScreen()) {
501 showIntroScreen();
502 } else {
503 showFirstRunActivity();
504 showFirstRunClings();
505 }
Adam Cohen9211d422014-10-07 18:14:53 -0700506 }
507
Sunny Goyal7779d622015-06-11 16:18:39 -0700508 @Override
509 public void onSettingsChanged(String settings, boolean value) {
510 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
511 mRotationEnabled = value;
512 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
513 mUpdateOrientationRunnable.run();
514 }
515 }
516 }
517
Tony Wickham827cef22016-03-17 15:39:39 -0700518 @Override
519 public void onExtractedColorsChanged() {
520 loadExtractedColorsAndColorItems();
521 }
522
523 private void loadExtractedColorsAndColorItems() {
524 if (mExtractedColors != null) {
525 mExtractedColors.load(this);
526 // TODO: pass mExtractedColors to interested items such as hotseat.
Tony Wickham827cef22016-03-17 15:39:39 -0700527 }
528 }
529
Adam Cohen9211d422014-10-07 18:14:53 -0700530 private LauncherCallbacks mLauncherCallbacks;
531
532 public void onPostCreate(Bundle savedInstanceState) {
533 super.onPostCreate(savedInstanceState);
534 if (mLauncherCallbacks != null) {
535 mLauncherCallbacks.onPostCreate(savedInstanceState);
536 }
537 }
538
Sunny Goyal32554d12015-12-03 15:31:25 -0800539 /**
540 * Call this after onCreate to set or clear overlay.
541 */
542 public void setLauncherOverlay(LauncherOverlay overlay) {
543 if (overlay != null) {
544 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
545 }
546 mWorkspace.setLauncherOverlay(overlay);
547 }
548
Adam Cohen9211d422014-10-07 18:14:53 -0700549 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
550 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700551 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700552 private boolean mWorkspaceImportanceStored = false;
553 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700554 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800555 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700556 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
557
558 @Override
559 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700560 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700561 return;
562 }
563 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700564 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700565 if (mWorkspace != null) {
566 mWorkspaceImportanceForAccessibility =
567 mWorkspace.getImportantForAccessibility();
568 mWorkspace.setImportantForAccessibility(
569 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
570 mWorkspaceImportanceStored = true;
571 }
572 if (mHotseat != null) {
573 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
574 mHotseat.setImportantForAccessibility(
575 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
576 mHotseatImportanceStored = true;
577 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700578 }
579
580 @Override
581 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700582 if (mWorkspaceImportanceStored && mWorkspace != null) {
583 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
584 }
585 if (mHotseatImportanceStored && mHotseat != null) {
586 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
587 }
588 mWorkspaceImportanceStored = false;
589 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700590 }
591 });
Adam Cohen9211d422014-10-07 18:14:53 -0700592 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700593 }
594
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700595 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700596 public void onLauncherProviderChange() {
597 if (mLauncherCallbacks != null) {
598 mLauncherCallbacks.onLauncherProviderChange();
599 }
600 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700601
Adam Cohen9211d422014-10-07 18:14:53 -0700602 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700603 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700604 if (mLauncherCallbacks != null) {
605 return mLauncherCallbacks.hasCustomContentToLeft();
606 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700607 return false;
608 }
609
Dave Hawkeya8881582013-09-17 15:55:33 -0600610 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500611 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600612 * {@link #addToCustomContentPage}. This will only be invoked if
613 * {@link #hasCustomContentToLeft()} is {@code true}.
614 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500615 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700616 if (mLauncherCallbacks != null) {
617 mLauncherCallbacks.populateCustomContentContainer();
618 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600619 }
620
621 /**
622 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
623 * ensure the custom content page is added or removed if necessary.
624 */
625 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600626 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600627 // Not bound yet, wait for bindScreens to be called.
628 return;
629 }
630
631 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
632 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500633 mWorkspace.createCustomContentContainer();
634 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600635 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
636 mWorkspace.removeCustomContentPage();
637 }
638 }
639
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800640 /**
641 * Logger object is a singleton and does not have to be coupled with the foreground activity.
642 * Since most user event logging is done on the UI, the object is retrieved from the
643 * callback for convenience.
644 */
645 private void initLogger() {
646 if (mLauncherCallbacks != null) {
647 mUserEventLogger = mLauncherCallbacks.getLogger();
648 }
649 if (mUserEventLogger == null) {
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700650 mUserEventLogger = new UserEventLogger(this) {
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800651 @Override
652 public void processEvent(LauncherLogProto.LauncherEvent ev) {
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700653 if (!DEBUG_LOGGING) {
654 return;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800655 }
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700656 Log.d("UserEvent", String.format(Locale.US,
657 "action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
658 LoggerUtils.getActionStr(ev.action),
659 LoggerUtils.getTargetStr(ev.srcTarget[0]),
660 LoggerUtils.getTargetStr(ev.srcTarget[1]),
661 ev.elapsedContainerMillis,
662 ev.elapsedSessionMillis));
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800663 }
664 };
665 }
666 }
667
668 public UserEventLogger getLogger() {
669 return mUserEventLogger;
670 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100671
Hyunyoung Song3f471442015-04-08 19:01:34 -0700672 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700673 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
674 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700675 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700676 }
677
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000678 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700679 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
680 // This cast is safe as long as the id < 0x00FFFFFF
681 // Since we jail all the dynamically generated views, there should be no clashes
682 // with any other views.
683 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000684 }
685
686 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700687 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
688 * a configuration step, this allows the proper animations to run after other transitions.
689 */
Adam Cohendb364c32014-05-20 14:23:40 -0700690 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700691 long screenId = args.screenId;
692 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
693 // When the screen id represents an actual screen (as opposed to a rank) we make sure
694 // that the drop page actually exists.
695 screenId = ensurePendingDropLayoutExists(args.screenId);
696 }
Adam Cohendb364c32014-05-20 14:23:40 -0700697
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800698 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800699 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700700 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700701 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700702 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800703 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700704 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700705 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700706 case REQUEST_RECONFIGURE_APPWIDGET:
707 completeRestoreAppWidget(args.appWidgetId);
708 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800709 }
Michael Jurka27614d22012-04-02 06:40:22 -0700710 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
711 // if you turned the screen off and then back while in All Apps, Launcher would not
712 // return to the workspace. Clearing mAddInfo.container here fixes this issue
713 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700714 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800715 }
716
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800717 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700718 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700719 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700720 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700721 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800722 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700723
Adam Cohenad4e15c2013-10-17 16:21:35 -0700724 Runnable exitSpringLoaded = new Runnable() {
725 @Override
726 public void run() {
727 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
728 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
729 }
730 };
731
Michael Jurka8b805b12012-04-18 14:23:14 -0700732 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700733 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700734 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700735 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
736 if (resultCode == RESULT_CANCELED) {
737 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700738 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700739 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700740 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800741 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700742 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700743
744 // When the user has granted permission to bind widgets, we should check to see if
745 // we can inflate the default search bar widget.
746 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700747 }
748 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200749 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
750 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700751 // User could have free-scrolled between pages before picking a wallpaper; make sure
752 // we move to the closest one now.
753 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700754 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200755 }
756 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200758
Adam Cohened66b2b2012-01-23 17:28:51 -0800759 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700760 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700761
Adam Cohendb364c32014-05-20 14:23:40 -0700762 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 // We have special handling for widgets
764 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800765 final int appWidgetId;
766 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
767 : -1;
768 if (widgetId < 0) {
769 appWidgetId = pendingAddWidgetId;
770 } else {
771 appWidgetId = widgetId;
772 }
773
Adam Cohenad4e15c2013-10-17 16:21:35 -0700774 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800775 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700776 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
777 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 result = RESULT_CANCELED;
779 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700780 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700781 @Override
782 public void run() {
783 exitSpringLoadedDragModeDelayed(false, 0, null);
784 }
785 };
Adam Cohendb364c32014-05-20 14:23:40 -0700786 if (workspaceLocked) {
787 // No need to remove the empty screen if we're mid-binding, as the
788 // the bind will not add the empty screen.
789 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
790 } else {
791 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
792 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
793 }
Winson Chung5aaab772012-04-27 15:24:02 -0700794 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700795 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700796 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
797 // When the screen id represents an actual screen (as opposed to a rank)
798 // we make sure that the drop page actually exists.
799 mPendingAddInfo.screenId =
800 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
801 }
Adam Cohendb364c32014-05-20 14:23:40 -0700802 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
803
804 dropLayout.setDropPending(true);
805 final Runnable onComplete = new Runnable() {
806 @Override
807 public void run() {
808 completeTwoStageWidgetDrop(resultCode, appWidgetId);
809 dropLayout.setDropPending(false);
810 }
811 };
812 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
813 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
814 } else {
815 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
816 mPendingAddInfo);
817 sPendingAddItem = args;
818 }
Winson Chung5aaab772012-04-27 15:24:02 -0700819 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800820 return;
821 }
822
Sunny Goyalff572272014-07-23 13:58:07 -0700823 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
824 if (resultCode == RESULT_OK) {
825 // Update the widget view.
826 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
827 pendingAddWidgetId, mPendingAddInfo);
828 if (workspaceLocked) {
829 sPendingAddItem = args;
830 } else {
831 completeAdd(args);
832 }
833 }
834 // Leave the widget in the pending state if the user canceled the configure.
835 return;
836 }
837
Sunny Goyalaad90582015-07-09 14:22:50 -0700838 if (requestCode == REQUEST_CREATE_SHORTCUT) {
839 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
840 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
841 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
842 mPendingAddInfo);
843 if (isWorkspaceLocked()) {
844 sPendingAddItem = args;
845 } else {
846 completeAdd(args);
847 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
848 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
849 }
850 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700851 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
852 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800855 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800856
857 }
858
859 @Override
860 protected void onActivityResult(
861 final int requestCode, final int resultCode, final Intent data) {
862 handleActivityResult(requestCode, resultCode, data);
863 if (mLauncherCallbacks != null) {
864 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
865 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 }
867
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600868 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700869 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600870 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700871 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
872 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
873 View v = null;
874 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
875 if (layout != null) {
876 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
877 }
878 Intent intent = sPendingAddItem.intent;
879 sPendingAddItem = null;
880 if (grantResults.length > 0
881 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
882 startActivity(v, intent, null);
883 } else {
884 // TODO: Show a snack bar with link to settings
885 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
886 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
887 }
888 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600889 if (mLauncherCallbacks != null) {
890 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
891 grantResults);
892 }
893 }
894
Adam Cohendb364c32014-05-20 14:23:40 -0700895 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
896 appWidgetId, ItemInfo info) {
897 PendingAddArguments args = new PendingAddArguments();
898 args.requestCode = requestCode;
899 args.intent = data;
900 args.container = info.container;
901 args.screenId = info.screenId;
902 args.cellX = info.cellX;
903 args.cellY = info.cellY;
904 args.appWidgetId = appWidgetId;
905 return args;
906 }
907
908 /**
909 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
910 *
911 * @param screenId the screen id to check
912 * @return the new screen, or screenId if it exists
913 */
914 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800915 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700916 if (dropLayout == null) {
917 // it's possible that the add screen was removed because it was
918 // empty and a re-bind occurred
919 mWorkspace.addExtraEmptyScreen();
920 return mWorkspace.commitExtraEmptyScreen();
921 } else {
922 return screenId;
923 }
924 }
925
Adam Cohen091440a2015-03-18 14:16:05 -0700926 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800927 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 Runnable onCompleteRunnable = null;
929 int animationType = 0;
930
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700931 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800932 if (resultCode == RESULT_OK) {
933 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
934 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700935 mPendingAddWidgetInfo);
936 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 onCompleteRunnable = new Runnable() {
938 @Override
939 public void run() {
940 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700941 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700942 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
943 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800944 }
945 };
946 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800947 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800948 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800949 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700950 if (mDragLayer.getAnimatedView() != null) {
951 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
952 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
953 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700954 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700955 // The animated view may be null in the case of a rotation during widget configuration
956 onCompleteRunnable.run();
957 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800958 }
959
960 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700961 protected void onStop() {
962 super.onStop();
963 FirstFrameAnimatorHelper.setIsVisible(false);
Sunny Goyal23ac9cb2016-04-07 12:14:37 -0700964 if (Utilities.isNycOrAbove()) {
965 mAppWidgetHost.stopListening();
966 }
Adam Cohen9211d422014-10-07 18:14:53 -0700967
968 if (mLauncherCallbacks != null) {
969 mLauncherCallbacks.onStop();
970 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700971 }
972
973 @Override
974 protected void onStart() {
975 super.onStart();
976 FirstFrameAnimatorHelper.setIsVisible(true);
Sunny Goyal23ac9cb2016-04-07 12:14:37 -0700977 if (Utilities.isNycOrAbove()) {
978 mAppWidgetHost.startListening();
979 }
Adam Cohen9211d422014-10-07 18:14:53 -0700980
981 if (mLauncherCallbacks != null) {
982 mLauncherCallbacks.onStart();
983 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700984 }
985
986 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200988 long startTime = 0;
989 if (DEBUG_RESUME_TIME) {
990 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400991 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200992 }
Adam Cohen9211d422014-10-07 18:14:53 -0700993
994 if (mLauncherCallbacks != null) {
995 mLauncherCallbacks.preOnResume();
996 }
997
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998 super.onResume();
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800999 mUserEventLogger.resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001000
Winson Chung4a2afa32012-07-19 14:53:05 -07001001 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001002 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001003 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001004 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001005 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001006 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001007 // view after launching an app, as they may be depending on the UI to be static to
1008 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001009 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07001010 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08001011 } else if (mOnResumeState == State.WIDGETS) {
1012 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001013 }
1014 mOnResumeState = State.NONE;
1015
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001016 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001017 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1018 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001019
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001020 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001021 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001022 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -07001023 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onorato9c1289c2009-08-17 11:03:03 -04001024 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001025 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001027 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001028 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1029 // execute them here
1030 long startTimeCallbacks = 0;
1031 if (DEBUG_RESUME_TIME) {
1032 startTimeCallbacks = System.currentTimeMillis();
1033 }
1034
Michael Jurka1e2f4652013-07-08 18:03:46 -07001035 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1036 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001037 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001038 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001039 if (DEBUG_RESUME_TIME) {
1040 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1041 (System.currentTimeMillis() - startTimeCallbacks));
1042 }
Michael Jurka447bf842013-05-15 14:52:15 +02001043 }
Michael Jurka54554252013-08-01 12:52:23 +02001044 if (mOnResumeCallbacks.size() > 0) {
1045 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1046 mOnResumeCallbacks.get(i).run();
1047 }
1048 mOnResumeCallbacks.clear();
1049 }
Winson Chunge4e50662012-01-23 14:45:13 -08001050
1051 // Reset the pressed state of icons that were locked in the press state while activities
1052 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001053 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001054 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001055 mWaitingForResume.setStayPressed(false);
1056 }
Winson Chung82963d52013-10-09 11:20:57 -07001057
Adam Cohen06dff352012-06-01 17:17:08 -07001058 // It is possible that widgets can receive updates while launcher is not in the foreground.
1059 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1060 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1061 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001062 if (!isWorkspaceLoading()) {
1063 getWorkspace().reinflateWidgetsIfNecessary();
1064 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001065 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001066
Michael Jurka447bf842013-05-15 14:52:15 +02001067 if (DEBUG_RESUME_TIME) {
1068 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1069 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001070
Adam Cohen4b66bf32015-09-18 12:15:19 -07001071 // We want to suppress callbacks about CustomContent being shown if we have just received
1072 // onNewIntent while the user was present within launcher. In that case, we post a call
1073 // to move the user to the main screen (which will occur after onResume). We don't want to
1074 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1075 // suppress here.
1076 if (mWorkspace.getCustomContentCallbacks() != null
1077 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001078 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001079 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001080 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1081 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001082 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001083 }
1084 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001085 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001086 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001087 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001088
Sunny Goyal756adbc2015-04-16 15:20:51 -07001089 if (!isWorkspaceLoading()) {
1090 // Process any items that were added while Launcher was away.
1091 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1092 }
Adam Cohen9211d422014-10-07 18:14:53 -07001093
1094 if (mLauncherCallbacks != null) {
1095 mLauncherCallbacks.onResume();
1096 }
Adam Cohen06dff352012-06-01 17:17:08 -07001097 }
1098
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001100 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001101 // Ensure that items added to Launcher are queued until Launcher returns
1102 InstallShortcutReceiver.enableInstallQueue();
1103
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001104 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001105 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001106 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001107 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001108
1109 // We call onHide() aggressively. The custom content callbacks should be able to
1110 // debounce excess onHide calls.
1111 if (mWorkspace.getCustomContentCallbacks() != null) {
1112 mWorkspace.getCustomContentCallbacks().onHide();
1113 }
Romain Guycbb89e42009-06-08 15:52:54 -07001114
Adam Cohen9211d422014-10-07 18:14:53 -07001115 if (mLauncherCallbacks != null) {
1116 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001117 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001118 }
1119
1120 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001121 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1122 // by a onResume or by scrolling otherwise.
1123 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001124
1125 // Custom content is completely hidden
1126 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001127
1128 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1129 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001130
1131 // Indicates whether the user is allowed to scroll away from the custom content.
1132 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001133 }
1134
Adam Cohenc2d6e892014-10-16 09:49:24 -07001135 public interface LauncherOverlay {
1136
1137 /**
1138 * Touch interaction leading to overscroll has begun
1139 */
1140 public void onScrollInteractionBegin();
1141
1142 /**
1143 * Touch interaction related to overscroll has ended
1144 */
1145 public void onScrollInteractionEnd();
1146
1147 /**
1148 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1149 * screen (or in the case of RTL, the rightmost screen).
1150 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001151 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001152
1153 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001154 * Called when the launcher is ready to use the overlay
1155 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001156 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001157 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001158 }
1159
Jun Mukai8af0cd82015-05-12 12:32:12 -07001160 public interface LauncherSearchCallbacks {
1161 /**
1162 * Called when the search overlay is shown.
1163 */
1164 public void onSearchOverlayOpened();
1165
1166 /**
1167 * Called when the search overlay is dismissed.
1168 */
1169 public void onSearchOverlayClosed();
1170 }
1171
Adam Cohenc2d6e892014-10-16 09:49:24 -07001172 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001173 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001174 }
1175
1176 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1177
Sunny Goyalc86df472016-02-25 09:19:38 -08001178 public void onScrollChanged(float progress) {
1179 if (mWorkspace != null) {
1180 mWorkspace.onOverlayScrollChanged(progress);
1181 }
1182 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001183 }
1184
Jorim Jaggid017f882014-01-14 17:08:48 -08001185 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001186 if (mLauncherCallbacks != null) {
1187 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001188 } else {
1189 // On devices with a locked orientation, we will at least have the allow rotation
1190 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001191 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001192 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001193 }
1194
Adam Cohen9211d422014-10-07 18:14:53 -07001195 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001196 CustomContentCallbacks callbacks, String description) {
1197 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001198 }
1199
Adam Cohenedb40762013-07-18 16:45:45 -07001200 // The custom content needs to offset its content to account for the QSB
1201 public int getTopOffsetForCustomContent() {
1202 return mWorkspace.getPaddingTop();
1203 }
1204
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001205 @Override
1206 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001207 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001208 if (mModel.isCurrentCallbacks(this)) {
1209 mModel.stopLoader();
1210 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001211 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1212
Romain Guy13c2e7b2010-03-10 19:45:00 -08001213 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001214 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001215
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001216 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001217 @Override
1218 public void onWindowFocusChanged(boolean hasFocus) {
1219 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001220 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001221
1222 if (mLauncherCallbacks != null) {
1223 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1224 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001225 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001226
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001227 private boolean acceptFilter() {
1228 final InputMethodManager inputManager = (InputMethodManager)
1229 getSystemService(Context.INPUT_METHOD_SERVICE);
1230 return !inputManager.isFullscreenMode();
1231 }
1232
1233 @Override
1234 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001235 final int uniChar = event.getUnicodeChar();
1236 final boolean handled = super.onKeyDown(keyCode, event);
1237 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1238 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1240 keyCode, event);
1241 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001242 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001243 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001244 // showSearchDialog()
1245 // If there are multiple keystrokes before the search dialog takes focus,
1246 // onSearchRequested() will be called for every keystroke,
1247 // but it is idempotent, so it's fine.
1248 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 }
1250 }
1251
Joe Onorato8a9625e2010-01-28 15:55:35 -08001252 // Eat the long press event so the keyboard doesn't come up.
1253 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1254 return true;
1255 }
1256
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 return handled;
1258 }
1259
Winson46163472015-09-22 17:31:56 -07001260 @Override
1261 public boolean onKeyUp(int keyCode, KeyEvent event) {
1262 if (keyCode == KeyEvent.KEYCODE_MENU) {
1263 // Ignore the menu key if we are currently dragging or are on the custom content screen
1264 if (!isOnCustomContent() && !mDragController.isDragging()) {
1265 // Close any open folders
1266 closeFolder();
1267
1268 // Stop resizing any widgets
1269 mWorkspace.exitWidgetResizeMode();
1270
1271 // Show the overview mode if we are on the workspace
1272 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1273 !mWorkspace.isSwitchingState()) {
1274 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001275 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001276 }
1277 }
1278 return true;
1279 }
1280 return super.onKeyUp(keyCode, event);
1281 }
1282
Karl Rosaen138a0412009-04-23 19:00:21 -07001283 private String getTypedText() {
1284 return mDefaultKeySsb.toString();
1285 }
1286
1287 private void clearTypedText() {
1288 mDefaultKeySsb.clear();
1289 mDefaultKeySsb.clearSpans();
1290 Selection.setSelection(mDefaultKeySsb, 0);
1291 }
1292
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001294 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1295 * State
1296 */
1297 private static State intToState(int stateOrdinal) {
1298 State state = State.WORKSPACE;
1299 final State[] stateValues = State.values();
1300 for (int i = 0; i < stateValues.length; i++) {
1301 if (stateValues[i].ordinal() == stateOrdinal) {
1302 state = stateValues[i];
1303 break;
1304 }
1305 }
1306 return state;
1307 }
1308
1309 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 * Restores the previous state, if it exists.
1311 *
1312 * @param savedState The previous state.
1313 */
1314 private void restoreState(Bundle savedState) {
1315 if (savedState == null) {
1316 return;
1317 }
1318
Michael Jurka883f55b2010-10-21 15:47:14 -07001319 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001320 if (state == State.APPS || state == State.WIDGETS) {
1321 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001322 }
1323
Adam Cohen21cd0022013-10-09 18:57:02 -07001324 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1325 PagedView.INVALID_RESTORE_PAGE);
1326 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001327 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
1329
Sunny Goyal756cd262015-08-20 12:33:21 -07001330 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1331 if (itemValues != null) {
1332 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001333 AppWidgetProviderInfo info = savedState.getParcelable(
1334 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001335 mPendingAddWidgetInfo = info == null ?
1336 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1337
Adam Cohen4637b5a2013-11-04 18:21:24 -08001338 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001339 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340 mRestoring = true;
1341 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001342 }
1343
1344 /**
1345 * Finds all the views we need and configure them properly.
1346 */
1347 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001348 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001349
Craig Mautner360310b2012-10-26 15:13:08 -07001350 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001351 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001352 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1353 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001354 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001355 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001356
Sunny Goyal784f9c32016-03-23 16:56:54 -07001357 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1358 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1359 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
Craig Mautner360310b2012-10-26 15:13:08 -07001360 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361
Winson Chung4c98d922011-05-31 16:50:48 -07001362 // Setup the drag layer
1363 mDragLayer.setup(this, dragController);
1364
Winson Chung3d503fb2011-07-13 17:25:49 -07001365 // Setup the hotseat
1366 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1367 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001368 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001369 }
1370
Winsone9f27272015-10-13 10:47:51 -07001371 // Setup the overview panel
1372 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001373
Winson Chung4c98d922011-05-31 16:50:48 -07001374 // Setup the workspace
1375 mWorkspace.setHapticFeedbackEnabled(false);
1376 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001377 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001378 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001379
Tony Wickham34d2c912015-09-11 09:27:58 -07001380 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001381 mSearchDropTargetBar = (SearchDropTargetBar)
1382 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001383 // Get the app info bar
1384 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1385 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001386
Winson Chungef7f8742015-06-04 17:18:17 -07001387 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001388 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001389 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001390 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1391 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1392 } else {
1393 mAppsView.setSearchBarController(new DefaultAppSearchController());
1394 }
Craig Mautner360310b2012-10-26 15:13:08 -07001395
Winson Chung3d503fb2011-07-13 17:25:49 -07001396 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001397 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001398 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001399 dragController.setMoveTarget(mWorkspace);
1400 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001401 if (mSearchDropTargetBar != null) {
1402 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001403 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001404 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001405 if (mAppInfoDropTargetBar != null) {
1406 mAppInfoDropTargetBar.setup(this, dragController);
1407 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001408
Sunny Goyal322d5562015-06-25 19:35:49 -07001409 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1410 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001411 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 }
1413
Winsone9f27272015-10-13 10:47:51 -07001414 private void setupOverviewPanel() {
1415 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1416
1417 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1418 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1419 @Override
1420 public boolean onLongClick(View v) {
1421 return v.performClick();
1422 }
1423 };
1424
1425 // Bind wallpaper button actions
1426 View wallpaperButton = findViewById(R.id.wallpaper_button);
1427 wallpaperButton.setOnClickListener(new OnClickListener() {
1428 @Override
1429 public void onClick(View view) {
1430 if (!mWorkspace.isSwitchingState()) {
1431 onClickWallpaperPicker(view);
1432 }
1433 }
1434 });
1435 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1436 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1437
1438 // Bind widget button actions
1439 mWidgetsButton = findViewById(R.id.widget_button);
1440 mWidgetsButton.setOnClickListener(new OnClickListener() {
1441 @Override
1442 public void onClick(View view) {
1443 if (!mWorkspace.isSwitchingState()) {
1444 onClickAddWidgetButton(view);
1445 }
1446 }
1447 });
1448 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1449 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1450
1451 // Bind settings actions
1452 View settingsButton = findViewById(R.id.settings_button);
1453 boolean hasSettings = hasSettings();
1454 if (hasSettings) {
1455 settingsButton.setOnClickListener(new OnClickListener() {
1456 @Override
1457 public void onClick(View view) {
1458 if (!mWorkspace.isSwitchingState()) {
1459 onClickSettingsButton(view);
1460 }
1461 }
1462 });
1463 settingsButton.setOnLongClickListener(performClickOnLongClick);
1464 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1465 } else {
1466 settingsButton.setVisibility(View.GONE);
1467 }
1468
1469 mOverviewPanel.setAlpha(0f);
1470 }
1471
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001473 * Sets the all apps button. This method is called from {@link Hotseat}.
1474 */
1475 public void setAllAppsButton(View allAppsButton) {
1476 mAllAppsButton = allAppsButton;
1477 }
1478
1479 public View getAllAppsButton() {
1480 return mAllAppsButton;
1481 }
1482
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001483 public View getWidgetsButton() {
1484 return mWidgetsButton;
1485 }
1486
Anjali Koppal5ad44842014-03-10 20:34:39 -07001487 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 * Creates a view representing a shortcut.
1489 *
1490 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001492 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001493 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001494 }
1495
1496 /**
1497 * Creates a view representing a shortcut inflated from the specified resource.
1498 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 * @param parent The group the shortcut belongs to.
1500 * @param info The data structure describing the shortcut.
1501 *
1502 * @return A View inflated from layoutResId.
1503 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001504 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001505 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001506 parent, false);
1507 favorite.applyFromShortcutInfo(info, mIconCache);
1508 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001510 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 return favorite;
1512 }
1513
1514 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515 * Add a shortcut to the workspace.
1516 *
1517 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001519 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001520 int cellY) {
1521 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001522 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001523
Sunny Goyal5c97f512015-05-19 16:03:28 -07001524 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001525 if (info == null) {
1526 return;
1527 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001528 final View view = createShortcut(info);
1529
Sunny Goyal5c97f512015-05-19 16:03:28 -07001530 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001531 // First we check if we already know the exact location where we want to add this item.
1532 if (cellX >= 0 && cellY >= 0) {
1533 cellXY[0] = cellX;
1534 cellXY[1] = cellY;
1535 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001536
1537 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001538 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001539 true, null,null)) {
1540 return;
1541 }
1542 DragObject dragObject = new DragObject();
1543 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001544 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1545 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001546 return;
1547 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001548 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001549 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001550 }
1551
1552 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001553 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001554 return;
1555 }
1556
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001557 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558
1559 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001560 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001561 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001562 }
1563 }
1564
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001566 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001568 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 */
Adam Cohen091440a2015-03-18 14:16:05 -07001570 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001571 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1572
1573 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001574 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001575 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001576 }
Romain Guycbb89e42009-06-08 15:52:54 -07001577
Adam Cohen59400422014-03-05 18:07:04 -08001578 if (appWidgetInfo.isCustomWidget) {
1579 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001580 }
1581
Adam Cohen59400422014-03-05 18:07:04 -08001582 LauncherAppWidgetInfo launcherInfo;
1583 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1584 launcherInfo.spanX = info.spanX;
1585 launcherInfo.spanY = info.spanY;
1586 launcherInfo.minSpanX = info.minSpanX;
1587 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001588 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001589
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001590 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001591 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592
1593 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001594 if (hostView == null) {
1595 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001596 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1597 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001598 } else {
1599 // The AppWidgetHostView has already been inflated and instantiated
1600 launcherInfo.hostView = hostView;
1601 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001602 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001603 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001605 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
Romain Guycbb89e42009-06-08 15:52:54 -07001607
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001608 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1609 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1610 item.hostView.setTag(item);
1611 item.onBindAppWidget(this);
1612
1613 item.hostView.setFocusable(true);
1614 item.hostView.setOnFocusChangeListener(mFocusHandler);
1615
1616 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1617 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1618
1619 if (!item.isCustomWidget()) {
1620 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1621 }
1622 }
1623
Adam Cohended9f8d2010-11-03 13:25:16 -07001624 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1625 @Override
1626 public void onReceive(Context context, Intent intent) {
1627 final String action = intent.getAction();
1628 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1629 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001630 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001631 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001632
Winson Chungc100e8e2011-08-09 16:02:43 -07001633 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001634 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001635 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001636 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001637 if (!showWorkspace(false)) {
1638 // If we are already on the workspace, then manually reset all apps
1639 mAppsView.reset();
1640 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001641 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001642 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1643 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001644 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001645 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1646 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001647 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001648 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1649 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1650 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001651 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001652 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1653 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001654 }
1655 }
1656 };
1657
1658 @Override
1659 public void onAttachedToWindow() {
1660 super.onAttachedToWindow();
1661
1662 // Listen for broadcasts related to user-presence
1663 final IntentFilter filter = new IntentFilter();
1664 filter.addAction(Intent.ACTION_SCREEN_OFF);
1665 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001666 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001667 if (ENABLE_DEBUG_INTENTS) {
1668 filter.addAction(DebugIntents.DELETE_DATABASE);
1669 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1670 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001671 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001672 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001673 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001674 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001675
1676 if (mLauncherCallbacks != null) {
1677 mLauncherCallbacks.onAttachedToWindow();
1678 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001679 }
1680
1681 @Override
1682 public void onDetachedFromWindow() {
1683 super.onDetachedFromWindow();
1684 mVisible = false;
1685
Adam Cohend113e0c2010-11-11 10:48:05 -08001686 if (mAttached) {
1687 unregisterReceiver(mReceiver);
1688 mAttached = false;
1689 }
Winson Chungb745afb2015-03-02 11:51:23 -08001690 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001691
1692 if (mLauncherCallbacks != null) {
1693 mLauncherCallbacks.onDetachedFromWindow();
1694 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001695 }
1696
1697 public void onWindowVisibilityChanged(int visibility) {
1698 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001699 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001700 // The following code used to be in onResume, but it turns out onResume is called when
1701 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1702 // is a more appropriate event to handle
1703 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001704 if (!mWorkspaceLoading) {
1705 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001706 // We want to let Launcher draw itself at least once before we force it to build
1707 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001708 // apps is nice and speedy.
1709 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001710 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001711 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001712 if (mStarted) return;
1713 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001714 // We delay the layer building a bit in order to give
1715 // other message processing a time to run. In particular
1716 // this avoids a delay in hiding the IME if it was
1717 // currently shown, because doing that may involve
1718 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001719 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001720 final ViewTreeObserver.OnDrawListener listener = this;
1721 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001722 public void run() {
1723 if (mWorkspace != null &&
1724 mWorkspace.getViewTreeObserver() != null) {
1725 mWorkspace.getViewTreeObserver().
1726 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001727 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001728 }
1729 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001730 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001731 }
1732 });
1733 }
1734 clearTypedText();
1735 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001736 }
1737
Adam Cohen091440a2015-03-18 14:16:05 -07001738 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001739 mHandler.removeMessages(ADVANCE_MSG);
1740 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1741 mHandler.sendMessageDelayed(msg, delay);
1742 mAutoAdvanceSentTime = System.currentTimeMillis();
1743 }
1744
Adam Cohen091440a2015-03-18 14:16:05 -07001745 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001746 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1747 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1748 mAutoAdvanceRunning = autoAdvanceRunning;
1749 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001750 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 sendAdvanceMessage(delay);
1752 } else {
1753 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001754 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001755 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1756 }
1757 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001758 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 }
1760 }
1761 }
1762
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001763 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1764
Adam Cohended9f8d2010-11-03 13:25:16 -07001765 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001766 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 if (msg.what == ADVANCE_MSG) {
1768 int i = 0;
1769 for (View key: mWidgetsToAdvance.keySet()) {
1770 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001771 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001772 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001773 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001774 public void run() {
1775 ((Advanceable) v).advance();
1776 }
1777 }, delay);
1778 }
1779 i++;
1780 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001781 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001782 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001783 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001784 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001785 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001786
Winsonc0b52fe2015-09-09 16:38:15 -07001787 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001788 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001789 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1790 if (v instanceof Advanceable) {
1791 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001792 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001793 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001794 }
1795 }
1796
Winsonc0b52fe2015-09-09 16:38:15 -07001797 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001798 if (mWidgetsToAdvance.containsKey(hostView)) {
1799 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001800 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001801 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001802 }
1803
Hyunyoung Song3f471442015-04-08 19:01:34 -07001804 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001805 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1806 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001807 }
1808
Winson Chunga6945242014-01-08 14:04:34 -08001809 public DragLayer getDragLayer() {
1810 return mDragLayer;
1811 }
1812
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001813 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001814 return mAppsView;
1815 }
1816
Hyunyoung Song3f471442015-04-08 19:01:34 -07001817 public WidgetsContainerView getWidgetsView() {
1818 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001819 }
1820
Winson Chunga6945242014-01-08 14:04:34 -08001821 public Workspace getWorkspace() {
1822 return mWorkspace;
1823 }
1824
1825 public Hotseat getHotseat() {
1826 return mHotseat;
1827 }
1828
Jorim Jaggid017f882014-01-14 17:08:48 -08001829 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001830 return mOverviewPanel;
1831 }
1832
Winson Chung006ee262015-08-03 14:40:11 -07001833 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001834 return mSearchDropTargetBar;
1835 }
1836
Tony Wickham34d2c912015-09-11 09:27:58 -07001837 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1838 return mAppInfoDropTargetBar;
1839 }
1840
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001841 public LauncherAppWidgetHost getAppWidgetHost() {
1842 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 }
Romain Guycbb89e42009-06-08 15:52:54 -07001844
Winson Chunga9abd0e2010-10-27 17:18:37 -07001845 public LauncherModel getModel() {
1846 return mModel;
1847 }
1848
Winson Chunga6945242014-01-08 14:04:34 -08001849 protected SharedPreferences getSharedPrefs() {
1850 return mSharedPrefs;
1851 }
1852
Adam Cohen2e6da152015-05-06 11:42:25 -07001853 public DeviceProfile getDeviceProfile() {
1854 return mDeviceProfile;
1855 }
1856
Bjorn Bringertc459e522013-06-07 19:36:01 +01001857 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001858 getWindow().closeAllPanels();
1859
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001860 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001861 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001862 }
1863
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864 @Override
1865 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001866 long startTime = 0;
1867 if (DEBUG_RESUME_TIME) {
1868 startTime = System.currentTimeMillis();
1869 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 super.onNewIntent(intent);
1871
1872 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001873 Folder openFolder = mWorkspace.getOpenFolder();
1874 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1875 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1876 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1877 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1878 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001879 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001880 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001881
Adam Cohen6fecd412013-10-02 17:41:50 -07001882 if (mWorkspace == null) {
1883 // Can be cases where mWorkspace is null, this prevents a NPE
1884 return;
1885 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001886 // In all these cases, only animate if we're already on home
1887 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001888
Sunny Goyal935fca12015-10-13 10:19:01 -07001889 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001890 exitSpringLoadedDragMode();
1891
1892 // If we are already on home, then just animate back to the workspace,
1893 // otherwise, just wait until onResume to set the state back to Workspace
1894 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001895 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001896 } else {
1897 mOnResumeState = State.WORKSPACE;
1898 }
1899
1900 final View v = getWindow().peekDecorView();
1901 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001902 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001903 INPUT_METHOD_SERVICE);
1904 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1905 }
1906
Winson Chungb745afb2015-03-02 11:51:23 -08001907 // Reset the apps view
1908 if (!alreadyOnHome && mAppsView != null) {
1909 mAppsView.scrollToTop();
1910 }
1911
Hyunyoung Song3f471442015-04-08 19:01:34 -07001912 // Reset the widgets view
1913 if (!alreadyOnHome && mWidgetsView != null) {
1914 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001915 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001916
Adam Cohen9211d422014-10-07 18:14:53 -07001917 if (mLauncherCallbacks != null) {
1918 mLauncherCallbacks.onHomeIntent();
1919 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 }
Adam Cohened307df2013-10-02 09:37:31 -07001921
Adam Cohen9211d422014-10-07 18:14:53 -07001922 if (mLauncherCallbacks != null) {
1923 mLauncherCallbacks.onNewIntent(intent);
1924 }
Winson15f8b172015-08-19 11:02:39 -07001925
1926 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1927 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1928 // animation.
1929 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001930 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1931 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001932 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1933 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001934
1935 // We use this flag to suppress noisy callbacks above custom content state
1936 // from onResume.
1937 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001938 mWorkspace.post(new Runnable() {
1939 @Override
1940 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001941 if (mWorkspace != null) {
1942 mWorkspace.moveToDefaultScreen(true);
1943 }
Winson15f8b172015-08-19 11:02:39 -07001944 }
1945 });
1946 }
1947 }
1948
1949 if (DEBUG_RESUME_TIME) {
1950 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1951 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001952 }
1953
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001955 public void onRestoreInstanceState(Bundle state) {
1956 super.onRestoreInstanceState(state);
1957 for (int page: mSynchronouslyBoundPages) {
1958 mWorkspace.restoreInstanceStateForChild(page);
1959 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960 }
1961
1962 @Override
1963 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001964 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001965 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1966 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001967 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001968 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969
Michael Jurka883f55b2010-10-21 15:47:14 -07001970 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001971 // We close any open folder since it will not be re-opened, and we need to make sure
1972 // this state is reflected.
1973 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1974 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975
Adam Cohendcd297f2013-06-18 13:13:40 -07001976 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001977 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001978 ContentValues itemValues = new ContentValues();
1979 mPendingAddInfo.writeToValues(itemValues);
1980 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001981 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001982 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 }
1984
Hyunyoung Song3f471442015-04-08 19:01:34 -07001985 // Save the current widgets tray?
1986 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001987
1988 if (mLauncherCallbacks != null) {
1989 mLauncherCallbacks.onSaveInstanceState(outState);
1990 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 }
1992
1993 @Override
1994 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001996
Winson Chunge7a03942011-08-05 15:05:12 -07001997 // Remove all pending runnables
1998 mHandler.removeMessages(ADVANCE_MSG);
1999 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002000 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002001
Winson Chungcd2b0142011-06-08 16:02:26 -07002002 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07002003 // It's possible to receive onDestroy after a new Launcher activity has
2004 // been created. In this case, don't interfere with the new Launcher.
2005 if (mModel.isCurrentCallbacks(this)) {
2006 mModel.stopLoader();
Sunny Goyald365ed62016-02-12 09:44:03 -08002007 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07002008 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002011 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002013 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002015 mAppWidgetHost = null;
2016
2017 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018
2019 TextKeyListener.getInstance().release();
2020
Tony Wickhame2217252016-03-22 16:34:23 -07002021 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
2022 .removeAccessibilityStateChangeListener(this);
2023
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002024 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002025
Michael Jurka2ecf9952012-06-18 12:52:28 -07002026 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002027
2028 if (mLauncherCallbacks != null) {
2029 mLauncherCallbacks.onDestroy();
2030 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032
Adam Cohena9cf38f2011-05-02 15:36:58 -07002033 public DragController getDragController() {
2034 return mDragController;
2035 }
2036
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002037 @Override
2038 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002039 onStartForResult(requestCode);
2040 super.startActivityForResult(intent, requestCode);
2041 }
2042
2043 @Override
2044 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2045 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2046 onStartForResult(requestCode);
2047 try {
2048 super.startIntentSenderForResult(intent, requestCode,
2049 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2050 } catch (IntentSender.SendIntentException e) {
2051 throw new ActivityNotFoundException();
2052 }
2053 }
2054
2055 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002056 if (requestCode >= 0) {
2057 setWaitingForResult(true);
2058 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 }
2060
Winson Chung70d72102011-08-12 11:24:35 -07002061 /**
2062 * Indicates that we want global search for this activity by setting the globalSearch
2063 * argument for {@link #startSearch} to true.
2064 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002066 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002068
Karl Rosaen138a0412009-04-23 19:00:21 -07002069 if (initialQuery == null) {
2070 // Use any text typed in the launcher as the initial query
2071 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002072 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002073 if (appSearchData == null) {
2074 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002075 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 }
Winson Chungadf0c182012-08-23 14:59:07 -07002077 Rect sourceBounds = new Rect();
2078 if (mSearchDropTargetBar != null) {
2079 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2080 }
Romain Guycbb89e42009-06-08 15:52:54 -07002081
Ian Parkinson047036e2014-09-01 15:40:53 +01002082 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002083 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002084 if (clearTextImmediately) {
2085 clearTypedText();
2086 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002087
2088 // We need to show the workspace after starting the search
2089 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002090 }
2091
Ian Parkinson047036e2014-09-01 15:40:53 +01002092 /**
2093 * Start a text search.
2094 *
2095 * @return {@code true} if the search will start immediately, so any further keypresses
2096 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2097 * to buffer keypresses.
2098 */
2099 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002100 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002101 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2102 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2103 sourceBounds);
2104 }
2105
Michael Jurkaa33411c2012-06-14 16:18:21 -07002106 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002107 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002108 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002109 }
2110
2111 /**
2112 * Starts the global search activity. This code is a copied from SearchManager
2113 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002114 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002115 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002116 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002117 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2118 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2119 if (globalSearchActivity == null) {
2120 Log.w(TAG, "No global search activity found.");
2121 return;
2122 }
2123 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2124 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2125 intent.setComponent(globalSearchActivity);
2126 // Make sure that we have a Bundle to put source in
2127 if (appSearchData == null) {
2128 appSearchData = new Bundle();
2129 } else {
2130 appSearchData = new Bundle(appSearchData);
2131 }
Adam Cohen9211d422014-10-07 18:14:53 -07002132 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002133 if (!appSearchData.containsKey("source")) {
2134 appSearchData.putString("source", getPackageName());
2135 }
2136 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2137 if (!TextUtils.isEmpty(initialQuery)) {
2138 intent.putExtra(SearchManager.QUERY, initialQuery);
2139 }
2140 if (selectInitialQuery) {
2141 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2142 }
2143 intent.setSourceBounds(sourceBounds);
2144 try {
2145 startActivity(intent);
2146 } catch (ActivityNotFoundException ex) {
2147 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2148 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002149 }
2150
Yura4f93ec62014-02-04 14:15:21 +00002151 public boolean isOnCustomContent() {
2152 return mWorkspace.isOnOrMovingToCustomContent();
2153 }
2154
Winson Chung70d72102011-08-12 11:24:35 -07002155 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002156 public boolean onPrepareOptionsMenu(Menu menu) {
2157 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002158 if (mLauncherCallbacks != null) {
2159 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2160 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002161 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002162 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002164 @Override
2165 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002166 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002167 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002168 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002169 }
2170
Joe Onorato9c1289c2009-08-17 11:03:03 -04002171 public boolean isWorkspaceLocked() {
2172 return mWorkspaceLoading || mWaitingForResult;
2173 }
2174
Adam Cohen517a7f52014-03-01 12:12:59 -08002175 public boolean isWorkspaceLoading() {
2176 return mWorkspaceLoading;
2177 }
2178
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002179 private void setWorkspaceLoading(boolean value) {
2180 boolean isLocked = isWorkspaceLocked();
2181 mWorkspaceLoading = value;
2182 if (isLocked != isWorkspaceLocked()) {
2183 onWorkspaceLockedChanged();
2184 }
2185 }
2186
2187 private void setWaitingForResult(boolean value) {
2188 boolean isLocked = isWorkspaceLocked();
2189 mWaitingForResult = value;
2190 if (isLocked != isWorkspaceLocked()) {
2191 onWorkspaceLockedChanged();
2192 }
2193 }
2194
Adam Cohen9211d422014-10-07 18:14:53 -07002195 protected void onWorkspaceLockedChanged() {
2196 if (mLauncherCallbacks != null) {
2197 mLauncherCallbacks.onWorkspaceLockedChanged();
2198 }
2199 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002200
Michael Jurka0280c3b2010-09-17 15:00:07 -07002201 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002202 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002203 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002204 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2205 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002206 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002207 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002208
Tony Wickhama0628cc2015-10-14 15:23:04 -07002209 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002210 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002211 if (LOGD) {
2212 Log.d(TAG, "Adding widget from drop");
2213 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002214 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2215 }
2216
Sunny Goyale6b63a32015-01-16 16:14:29 -08002217 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002218 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2219 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002220 if (appWidgetInfo.configure != null) {
2221 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002222 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002223
Bjorn Bringert7984c942009-12-09 15:38:25 +00002224 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002225 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2226 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2227
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002228 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002229 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002230 Runnable onComplete = new Runnable() {
2231 @Override
2232 public void run() {
2233 // Exit spring loaded mode if necessary after adding the widget
2234 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2235 null);
2236 }
2237 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002238 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002239 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002240 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002241 }
2242 }
Romain Guycbb89e42009-06-08 15:52:54 -07002243
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002244 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002245 // Close any folders that may be open.
2246 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002247 mWorkspace.moveToCustomContentScreen(animate);
2248 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002249
2250 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2251 int[] cell, int spanX, int spanY) {
2252 switch (info.itemType) {
2253 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2254 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2255 int span[] = new int[2];
2256 span[0] = spanX;
2257 span[1] = spanY;
2258 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2259 container, screenId, cell, span);
2260 break;
2261 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2262 processShortcutFromDrop(info.componentName, container, screenId, cell);
2263 break;
2264 default:
2265 throw new IllegalStateException("Unknown item type: " + info.itemType);
2266 }
2267 }
2268
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269 /**
2270 * Process a shortcut drop.
2271 *
2272 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002273 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002274 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002275 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002276 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2277 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002278 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002279 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002280 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002281
2282 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 mPendingAddInfo.cellX = cell[0];
2284 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002285 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002286
2287 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2288 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002289 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002290 }
2291
Adam Cohenfbba09b2011-07-18 21:43:05 -07002292 /**
2293 * Process a widget drop.
2294 *
2295 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002296 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002297 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002298 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002299 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2300 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002301 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002302 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002303 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002304 mPendingAddInfo.minSpanX = info.minSpanX;
2305 mPendingAddInfo.minSpanY = info.minSpanY;
2306
Adam Cohenfbba09b2011-07-18 21:43:05 -07002307 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002308 mPendingAddInfo.cellX = cell[0];
2309 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002310 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002311 if (span != null) {
2312 mPendingAddInfo.spanX = span[0];
2313 mPendingAddInfo.spanY = span[1];
2314 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002315
Adam Cohened66b2b2012-01-23 17:28:51 -08002316 AppWidgetHostView hostView = info.boundWidget;
2317 int appWidgetId;
2318 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002319 // In the case where we've prebound the widget, we remove it from the DragLayer
2320 if (LOGD) {
2321 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2322 }
2323 getDragLayer().removeView(hostView);
2324
Adam Cohened66b2b2012-01-23 17:28:51 -08002325 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002326 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002327
2328 // Clear the boundWidget so that it doesn't get destroyed.
2329 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002330 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002331 // In this case, we either need to start an activity to get permission to bind
2332 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002333 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002334 Bundle options = info.bindOptions;
2335
Sunny Goyalffe83f12014-08-14 17:39:34 -07002336 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2337 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002338 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002339 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002340 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002341 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002342 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2343 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2344 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002345 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2346 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002347 // TODO: we need to make sure that this accounts for the options bundle.
2348 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002349 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2350 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002351 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002352 }
2353
Adam Cohendcd297f2013-06-18 13:13:40 -07002354 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002355 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002356 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002357 folderInfo.title = getText(R.string.folder_name);
2358
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002359 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002360 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2361 cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362
2363 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002364 FolderIcon newFolder =
2365 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002366 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002367 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002368 // Force measure the new folder icon
2369 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2370 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002371 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372 }
Romain Guycbb89e42009-06-08 15:52:54 -07002373
Winsonc0b52fe2015-09-09 16:38:15 -07002374 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002375 * Unbinds the view for the specified item, and removes the item and all its children.
2376 *
2377 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002378 * @param itemInfo the {@link ItemInfo} for this view.
2379 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002380 */
Winson2949fb52015-09-24 09:56:11 -07002381 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002382 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002383 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07002384 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
2385 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07002386 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07002387 } else {
2388 mWorkspace.removeWorkspaceItem(v);
2389 }
Winsonc0b52fe2015-09-09 16:38:15 -07002390 if (deleteFromDb) {
2391 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2392 }
2393 } else if (itemInfo instanceof FolderInfo) {
2394 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Winsonc0b52fe2015-09-09 16:38:15 -07002395 mWorkspace.removeWorkspaceItem(v);
2396 if (deleteFromDb) {
2397 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2398 }
2399 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2400 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002401 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002402 removeWidgetToAutoAdvance(widgetInfo.hostView);
2403 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002404 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002405 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002406 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002407
Winsonc0b52fe2015-09-09 16:38:15 -07002408 } else {
2409 return false;
2410 }
2411 return true;
2412 }
2413
2414 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002415 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002416 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002417 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002418 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002419 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002420 // Deleting an app widget ID is a void call but writes to disk before returning
2421 // to the caller...
2422 new AsyncTask<Void, Void, Void>() {
2423 public Void doInBackground(Void ... args) {
2424 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2425 return null;
2426 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002427 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002428 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002429 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002430 }
2431
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 @Override
2433 public boolean dispatchKeyEvent(KeyEvent event) {
2434 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2435 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002437 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002438 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002439 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002440 dumpState();
2441 return true;
2442 }
2443 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002444 }
2445 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2446 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002447 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 return true;
2449 }
2450 }
2451
2452 return super.dispatchKeyEvent(event);
2453 }
2454
Joe Onorato88ec0992009-11-19 13:16:06 -08002455 @Override
2456 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002457 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2458 return;
2459 }
2460
Sunny Goyal45478022015-06-08 16:52:41 -07002461 if (mDragController.isDragging()) {
2462 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002463 return;
2464 }
2465
Winson Chungb745afb2015-03-02 11:51:23 -08002466 if (isAppsViewVisible()) {
2467 showWorkspace(true);
2468 } else if (isWidgetsViewVisible()) {
2469 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002470 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002471 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002472 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002473 Folder openFolder = mWorkspace.getOpenFolder();
2474 if (openFolder.isEditingName()) {
2475 openFolder.dismissEditingName();
2476 } else {
2477 closeFolder();
2478 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002479 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002480 mWorkspace.exitWidgetResizeMode();
2481
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002482 // Back button is a no-op here, but give at least some feedback for the button press
2483 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002484 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002485 }
2486
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002487 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002488 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002489 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002490 @Override
2491 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002492 if (mAppWidgetHost != null) {
2493 mAppWidgetHost.startListening();
2494 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002495
2496 // Recreate the QSB, as the widget has been reset.
2497 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002498 }
2499
2500 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002501 * Launches the intent referred by the clicked shortcut.
2502 *
2503 * @param v The view representing the clicked shortcut.
2504 */
2505 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002506 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2507 // view has detached (it's possible for this to happen if the view is removed mid touch).
2508 if (v.getWindowToken() == null) {
2509 return;
2510 }
2511
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002512 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002513 return;
2514 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002515
Adam Cohen1697b792013-09-17 19:08:21 -07002516 if (v instanceof Workspace) {
2517 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002518 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002519 }
2520 return;
2521 }
2522
2523 if (v instanceof CellLayout) {
2524 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002525 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2526 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002527 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002528 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002529 }
2530
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002531 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002532 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002533 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002534 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002535 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002536 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002537 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002538 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002539 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002540 } else if (tag instanceof AppInfo) {
2541 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002542 } else if (tag instanceof LauncherAppWidgetInfo) {
2543 if (v instanceof PendingAppWidgetHostView) {
2544 onClickPendingWidget((PendingAppWidgetHostView) v);
2545 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002546 }
2547 }
2548
Sunny Goyal70660032015-05-14 00:07:08 -07002549 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002550 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002551 return false;
2552 }
2553
Michael Jurkaaf442092010-06-10 17:01:57 -07002554 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002555 * Event handler for the app widget view which has not fully restored.
2556 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002557 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002558 if (mIsSafeModeEnabled) {
2559 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2560 return;
2561 }
2562
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002563 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002564 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002565 int widgetId = info.appWidgetId;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002566 LauncherAppWidgetProviderInfo appWidgetInfo =
2567 mAppWidgetManager.getLauncherAppWidgetInfo(widgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002568 if (appWidgetInfo != null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002569 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002570 mPendingAddInfo.copyFrom(info);
2571 mPendingAddWidgetId = widgetId;
2572
Sunny Goyalffe83f12014-08-14 17:39:34 -07002573 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2574 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002575 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002576 } else if (info.installProgress < 0) {
2577 // The install has not been queued
2578 final String packageName = info.providerName.getPackageName();
2579 showBrokenAppInstallDialog(packageName,
2580 new DialogInterface.OnClickListener() {
2581 public void onClick(DialogInterface dialog, int id) {
2582 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2583 }
2584 });
2585 } else {
2586 // Download has started.
2587 final String packageName = info.providerName.getPackageName();
2588 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002589 }
2590 }
2591
2592 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002593 * Event handler for the "grid" button that appears on the home screen, which
2594 * enters all apps mode.
2595 *
2596 * @param v The view that was clicked.
2597 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002598 protected void onClickAllAppsButton(View v) {
2599 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002600 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002601 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002602 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002603
2604 if (mLauncherCallbacks != null) {
2605 mLauncherCallbacks.onClickAllAppsButton(v);
2606 }
Winson Chung76648c52015-07-10 14:33:23 -07002607 }
2608 }
2609
2610 protected void onLongClickAllAppsButton(View v) {
2611 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2612 if (!isAppsViewVisible()) {
2613 showAppsView(true /* animated */, false /* resetListToTop */,
2614 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002615 }
2616 }
2617
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002618 private void showBrokenAppInstallDialog(final String packageName,
2619 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002620 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002621 .setTitle(R.string.abandoned_promises_title)
2622 .setMessage(R.string.abandoned_promise_explanation)
2623 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2624 .setNeutralButton(R.string.abandoned_clean_this,
2625 new DialogInterface.OnClickListener() {
2626 public void onClick(DialogInterface dialog, int id) {
2627 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2628 mWorkspace.removeAbandonedPromise(packageName, user);
2629 }
2630 })
2631 .create().show();
2632 return;
2633 }
2634
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002635 /**
2636 * Event handler for an app shortcut click.
2637 *
2638 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2639 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002640 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002641 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2642 Object tag = v.getTag();
2643 if (!(tag instanceof ShortcutInfo)) {
2644 throw new IllegalArgumentException("Input must be a Shortcut");
2645 }
2646
2647 // Open shortcut
2648 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002649
2650 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002651 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2652 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002653 // Launch activity anyway, framework will tell the user why the app is suspended.
2654 } else {
2655 int error = R.string.activity_not_available;
2656 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2657 error = R.string.safemode_shortcut_error;
2658 }
2659 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2660 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002661 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002662 }
2663
Chris Wren40c5ed32014-06-24 18:24:23 -04002664 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002665 if ((v instanceof BubbleTextView)
2666 && shortcut.isPromise()
2667 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002668 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002669 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002670 new DialogInterface.OnClickListener() {
2671 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002672 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002673 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002674 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002675 return;
2676 }
2677
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002678 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002679 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002680
2681 if (mLauncherCallbacks != null) {
2682 mLauncherCallbacks.onClickAppShortcut(v);
2683 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002684 }
2685
Adam Cohen091440a2015-03-18 14:16:05 -07002686 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002687 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002688 final ShortcutInfo shortcut;
2689 final Intent intent;
2690 if (tag instanceof ShortcutInfo) {
2691 shortcut = (ShortcutInfo) tag;
2692 intent = shortcut.intent;
2693 int[] pos = new int[2];
2694 v.getLocationOnScreen(pos);
2695 intent.setSourceBounds(new Rect(pos[0], pos[1],
2696 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002697
Sunny Goyal508da152014-08-14 10:53:27 -07002698 } else if (tag instanceof AppInfo) {
2699 shortcut = null;
2700 intent = ((AppInfo) tag).intent;
2701 } else {
2702 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2703 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002704
2705 boolean success = startActivitySafely(v, intent, tag);
Hyunyoung Songddec1c72016-04-12 18:32:04 -07002706 mUserEventLogger.logLaunch(v, intent);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002707
2708 if (success && v instanceof BubbleTextView) {
2709 mWaitingForResume = (BubbleTextView) v;
2710 mWaitingForResume.setStayPressed(true);
2711 }
2712 }
2713
2714 /**
2715 * Event handler for a folder icon click.
2716 *
2717 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2718 */
2719 protected void onClickFolderIcon(View v) {
2720 if (LOGD) Log.d(TAG, "onClickFolder");
2721 if (!(v instanceof FolderIcon)){
2722 throw new IllegalArgumentException("Input must be a FolderIcon");
2723 }
2724
2725 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002726 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002727 // Open the requested folder
Adam Cohen37b2a492016-04-06 18:36:06 -07002728 openFolder(folderIcon);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002729 }
Adam Cohen9211d422014-10-07 18:14:53 -07002730
2731 if (mLauncherCallbacks != null) {
2732 mLauncherCallbacks.onClickFolderIcon(v);
2733 }
Michael Jurka5130e402011-10-13 04:55:35 -07002734 }
2735
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002736 /**
2737 * Event handler for the (Add) Widgets button that appears after a long press
2738 * on the home screen.
2739 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002740 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002741 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002742 if (mIsSafeModeEnabled) {
2743 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2744 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002745 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002746 if (mLauncherCallbacks != null) {
2747 mLauncherCallbacks.onClickAddWidgetButton(view);
2748 }
Adam Cohen9211d422014-10-07 18:14:53 -07002749 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002750 }
2751
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002752 /**
2753 * Event handler for the wallpaper picker button that appears after a long press
2754 * on the home screen.
2755 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002756 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002757 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002758 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2759 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal30a71612016-04-12 17:57:41 -07002760 // TODO: Start the system wallpaper picker
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002761 }
2762
2763 /**
2764 * Event handler for a click on the settings button that appears after a long press
2765 * on the home screen.
2766 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002767 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002768 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002769 if (mLauncherCallbacks != null) {
2770 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002771 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002772 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002773 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002774 }
2775
Adam Cohen61f560d2013-09-30 15:58:20 -07002776 public View.OnTouchListener getHapticFeedbackTouchListener() {
2777 if (mHapticFeedbackTouchListener == null) {
2778 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002779 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002780 @Override
2781 public boolean onTouch(View v, MotionEvent event) {
2782 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2783 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2784 }
2785 return false;
2786 }
2787 };
2788 }
2789 return mHapticFeedbackTouchListener;
2790 }
2791
Tony Wickhame2217252016-03-22 16:34:23 -07002792 @Override
2793 public void onAccessibilityStateChanged(boolean enabled) {
2794 mDragLayer.onAccessibilityStateChanged(enabled);
2795 }
2796
Adam Cohen9211d422014-10-07 18:14:53 -07002797 public void onDragStarted(View view) {
2798 if (isOnCustomContent()) {
2799 // Custom content screen doesn't participate in drag and drop. If on custom
2800 // content screen, move to default.
2801 moveWorkspaceToDefaultScreen();
2802 }
2803
2804 if (mLauncherCallbacks != null) {
2805 mLauncherCallbacks.onDragStarted(view);
2806 }
2807 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002808
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002809 /**
2810 * Called when the user stops interacting with the launcher.
2811 * This implies that the user is now on the homescreen and is not doing housekeeping.
2812 */
Adam Cohen9211d422014-10-07 18:14:53 -07002813 protected void onInteractionEnd() {
2814 if (mLauncherCallbacks != null) {
2815 mLauncherCallbacks.onInteractionEnd();
2816 }
2817 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002818
2819 /**
2820 * Called when the user starts interacting with the launcher.
2821 * The possible interactions are:
2822 * - open all apps
2823 * - reorder an app shortcut, or a widget
2824 * - open the overview mode.
2825 * This is a good time to stop doing things that only make sense
2826 * when the user is on the homescreen and not doing housekeeping.
2827 */
Adam Cohen9211d422014-10-07 18:14:53 -07002828 protected void onInteractionBegin() {
2829 if (mLauncherCallbacks != null) {
2830 mLauncherCallbacks.onInteractionBegin();
2831 }
2832 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002833
Winson Chungcd99cd32015-04-29 11:03:24 -07002834 /** Updates the interaction state. */
2835 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002836 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002837 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002838 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2839 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002840 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002841 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002842 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002843 onInteractionEnd();
2844 }
2845 }
2846
Winson Chung8f1eff72015-05-28 17:33:40 -07002847 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002848 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002849 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002850 // Only launch using the new animation if the shortcut has not opted out (this is a
2851 // private contract between launcher and may be ignored in the future).
2852 boolean useLaunchAnimation = (v != null) &&
2853 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002854 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2855 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002856
Kenny Guy1317e2d2014-05-08 18:52:50 +01002857 UserHandleCompat user = null;
2858 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2859 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2860 user = userManager.getUserForSerialNumber(serialNumber);
2861 }
2862
2863 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002864 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002865 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002866 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002867 int left = 0, top = 0;
2868 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2869 if (v instanceof TextView) {
2870 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002871 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2872 if (icon != null) {
2873 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002874 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002875 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002876 width = bounds.width();
2877 height = bounds.height();
2878 }
2879 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002880 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2881 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002882 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002883 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002884 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002885 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002886 // On L devices, we use the device default slide-up transition.
2887 // On L MR1 devices, we a custom version of the slide-up transition which
2888 // doesn't have the delay present in the device default.
2889 opts = ActivityOptions.makeCustomAnimation(this,
2890 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002891 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002892 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002893 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002894
2895 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2896 // Could be launching some bookkeeping activity
2897 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002898 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002899 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002900 launcherApps.startActivityForProfile(intent.getComponent(), user,
2901 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002902 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002903 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002904 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002905 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2906 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2907 // corresponding permission. Show the appropriate permission prompt if that
2908 // is the case.
2909 if (intent.getComponent() == null
2910 && Intent.ACTION_CALL.equals(intent.getAction())
2911 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2912 PackageManager.PERMISSION_GRANTED) {
2913 // TODO: Rename sPendingAddItem to a generic name.
2914 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2915 0, (ItemInfo) tag);
2916 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2917 REQUEST_PERMISSION_CALL_PHONE);
2918 return false;
2919 }
2920 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002921 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002922 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002923 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002924 "or use the exported attribute for this activity. "
2925 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002926 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002927 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002928 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002929
Winson Chungbedf9232015-07-10 12:38:30 -07002930 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002931 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002932 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2933 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2934 return false;
2935 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002936 try {
2937 success = startActivity(v, intent, tag);
2938 } catch (ActivityNotFoundException e) {
2939 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2940 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2941 }
2942 return success;
2943 }
2944
Adam Cohen268c4752012-06-06 17:47:33 -07002945 /**
2946 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2947 * in the DragLayer in the exact absolute location of the original FolderIcon.
2948 */
2949 private void copyFolderIconToImage(FolderIcon fi) {
2950 final int width = fi.getMeasuredWidth();
2951 final int height = fi.getMeasuredHeight();
2952
2953 // Lazy load ImageView, Bitmap and Canvas
2954 if (mFolderIconImageView == null) {
2955 mFolderIconImageView = new ImageView(this);
2956 }
2957 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2958 mFolderIconBitmap.getHeight() != height) {
2959 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2960 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2961 }
2962
2963 DragLayer.LayoutParams lp;
2964 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2965 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2966 } else {
2967 lp = new DragLayer.LayoutParams(width, height);
2968 }
2969
Adam Cohen307fe232012-08-16 17:55:58 -07002970 // The layout from which the folder is being opened may be scaled, adjust the starting
2971 // view size by this scale factor.
2972 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002973 lp.customPosition = true;
2974 lp.x = mRectForFolderAnimation.left;
2975 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002976 lp.width = (int) (scale * width);
2977 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002978
2979 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2980 fi.draw(mFolderIconCanvas);
2981 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002982 if (fi.getFolder() != null) {
2983 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2984 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002985 }
Adam Cohen268c4752012-06-06 17:47:33 -07002986 // Just in case this image view is still in the drag layer from a previous animation,
2987 // we remove it and re-add it.
2988 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2989 mDragLayer.removeView(mFolderIconImageView);
2990 }
2991 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002992 if (fi.getFolder() != null) {
2993 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002994 }
Adam Cohen268c4752012-06-06 17:47:33 -07002995 }
2996
Adam Cohen37b2a492016-04-06 18:36:06 -07002997 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002998 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07002999 FolderInfo info = (FolderInfo) fi.getTag();
3000 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3001 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003002 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3003 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003004 }
3005
Adam Cohen268c4752012-06-06 17:47:33 -07003006 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3007 copyFolderIconToImage(fi);
3008 fi.setVisibility(View.INVISIBLE);
3009
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003010 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3011 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003012 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003013 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3014 }
3015 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003016 oa.start();
3017 }
3018
Sunny Goyal935fca12015-10-13 10:19:01 -07003019 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003020 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003021 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003022
Adam Cohen268c4752012-06-06 17:47:33 -07003023 // We remove and re-draw the FolderIcon in-case it has changed
3024 mDragLayer.removeView(mFolderIconImageView);
3025 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08003026
3027 if (cl != null) {
3028 cl.clearFolderLeaveBehind();
3029 }
3030
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003031 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003032 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003033 oa.addListener(new AnimatorListenerAdapter() {
3034 @Override
3035 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003036 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003037 // Remove the ImageView copy of the FolderIcon and make the original visible.
3038 mDragLayer.removeView(mFolderIconImageView);
3039 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003040 }
3041 }
3042 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003043 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003044 if (!animate) {
3045 oa.end();
3046 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003047 }
3048
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003049 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003050 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003051 * is animated relative to the specified View. If the View is null, no animation
3052 * is played.
3053 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003054 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003055 */
Adam Cohen37b2a492016-04-06 18:36:06 -07003056 public void openFolder(FolderIcon folderIcon) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003057
Adam Cohenfb91f302012-06-11 15:45:18 -07003058 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003059 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3060 if (openFolder != null && openFolder != folder) {
3061 // Close any open folder before opening a folder.
3062 closeFolder();
3063 }
3064
Adam Cohena9cf38f2011-05-02 15:36:58 -07003065 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003066
Adam Cohena9cf38f2011-05-02 15:36:58 -07003067 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003068
Sunny Goyalf4066152015-04-15 09:42:19 -07003069 // While the folder is open, the position of the icon cannot change.
3070 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3071
Adam Cohen4554ee12011-08-03 16:13:21 -07003072 // Just verify that the folder hasn't already been added to the DragLayer.
3073 // There was a one-off crash where the folder had a parent already.
3074 if (folder.getParent() == null) {
3075 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003076 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003077 } else {
3078 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3079 folder.getParent() + ").");
3080 }
Adam Cohen37b2a492016-04-06 18:36:06 -07003081 folder.animateOpen();
3082
3083 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003084
3085 // Notify the accessibility manager that this folder "window" has appeared and occluded
3086 // the workspace items
3087 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3088 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003089 }
3090
3091 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003092 closeFolder(true);
3093 }
3094
3095 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003096 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003097 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003098 if (folder.isEditingName()) {
3099 folder.dismissEditingName();
3100 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003101 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003102 }
3103 }
3104
Sunny Goyal935fca12015-10-13 10:19:01 -07003105 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003106 animate &= !Utilities.isPowerSaverOn(this);
3107
Adam Cohen4554ee12011-08-03 16:13:21 -07003108 folder.getInfo().opened = false;
3109
3110 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3111 if (parent != null) {
3112 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003113 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003114 if (fi != null) {
3115 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3116 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003117 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003118 if (animate) {
3119 folder.animateClosed();
3120 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003121 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003122 }
Winson Chung83ca4802013-04-12 15:10:52 -07003123
Sunny Goyal935fca12015-10-13 10:19:01 -07003124 // Notify the accessibility manager that this folder "window" has disappeared and no
3125 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003126 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003127 }
3128
Tony Wickhamdadb3042016-02-24 11:07:00 -08003129 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003130 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003131 if (!isDraggingEnabled()) return false;
3132 if (isWorkspaceLocked()) return false;
3133 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003134
Winson Chung76648c52015-07-10 14:33:23 -07003135 if (v == mAllAppsButton) {
3136 onLongClickAllAppsButton(v);
3137 return true;
3138 }
3139
Adam Cohen1697b792013-09-17 19:08:21 -07003140 if (v instanceof Workspace) {
3141 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003142 if (!mWorkspace.isTouchActive()) {
3143 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003144 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3145 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3146 return true;
3147 } else {
3148 return false;
3149 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003150 } else {
3151 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003152 }
Adam Cohen1697b792013-09-17 19:08:21 -07003153 }
3154
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003155 CellLayout.CellInfo longClickCellInfo = null;
3156 View itemUnderLongClick = null;
3157 if (v.getTag() instanceof ItemInfo) {
3158 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003159 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003160 itemUnderLongClick = longClickCellInfo.cell;
3161 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003162 }
3163
Winson Chung3d503fb2011-07-13 17:25:49 -07003164 // The hotseat touch handling does not go through Workspace, and we always allow long press
3165 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003166 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003167 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003168 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003169 // User long pressed on empty space
3170 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3171 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003172 if (mWorkspace.isInOverviewMode()) {
3173 mWorkspace.startReordering(v);
3174 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003175 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003176 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003177 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003178 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3179 mHotseat.getOrderInHotseat(
3180 longClickCellInfo.cellX,
3181 longClickCellInfo.cellY));
3182 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003183 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003184 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003185 }
3186 }
3187 }
3188 return true;
3189 }
3190
Winson Chung3d503fb2011-07-13 17:25:49 -07003191 boolean isHotseatLayout(View layout) {
3192 return mHotseat != null && layout != null &&
3193 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3194 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003195
Winson Chung3d503fb2011-07-13 17:25:49 -07003196 /**
3197 * Returns the CellLayout of the specified container at the specified screen.
3198 */
Sunny Goyal92820592015-03-02 11:31:35 -08003199 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003200 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3201 if (mHotseat != null) {
3202 return mHotseat.getLayout();
3203 } else {
3204 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003205 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003206 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003207 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003208 }
3209 }
3210
Winson Chungb745afb2015-03-02 11:51:23 -08003211 /**
3212 * For overridden classes.
3213 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003214 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003215 return isAppsViewVisible();
3216 }
3217
3218 public boolean isAppsViewVisible() {
3219 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3220 }
3221
3222 public boolean isWidgetsViewVisible() {
3223 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003224 }
3225
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003226 private void setWorkspaceBackground(int background) {
3227 switch (background) {
3228 case WORKSPACE_BACKGROUND_TRANSPARENT:
3229 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3230 break;
3231 case WORKSPACE_BACKGROUND_BLACK:
3232 getWindow().setBackgroundDrawable(null);
3233 break;
3234 default:
3235 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3236 }
Craig Mautner360310b2012-10-26 15:13:08 -07003237 }
3238
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003239 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003240 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3241 int curflags = getWindow().getAttributes().flags
3242 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3243 if (wpflags != curflags) {
3244 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3245 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003246 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003247 }
3248
Michael Jurkae326f182011-11-21 14:05:46 -08003249 @Override
3250 public void onTrimMemory(int level) {
3251 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003252 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3253 // The widget preview db can result in holding onto over
3254 // 3MB of memory for caching which isn't necessary.
3255 SQLiteDatabase.releaseMemory();
3256
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003257 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003258 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003259 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003260 if (mLauncherCallbacks != null) {
3261 mLauncherCallbacks.onTrimMemory(level);
3262 }
Michael Jurkae326f182011-11-21 14:05:46 -08003263 }
3264
Winson5c6bdbb2015-09-03 11:36:19 -07003265 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003266 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003267 }
3268
Winson5c6bdbb2015-09-03 11:36:19 -07003269 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003270 boolean changed = mState != State.WORKSPACE ||
3271 mWorkspace.getState() != Workspace.State.NORMAL;
3272 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003273 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003274 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003275 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003276
Michael Jurkab3e22d92011-10-31 15:58:33 -07003277 // Set focus to the AppsCustomize button
3278 if (mAllAppsButton != null) {
3279 mAllAppsButton.requestFocus();
3280 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003281 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003282
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003283 // Change the state *after* we've called all the transition code
3284 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003285
Winson Chung5fb63472011-02-02 17:03:37 -08003286 // Resume the auto-advance of widgets
3287 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003288 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003289
Winson Chung0f785722015-04-08 10:27:49 -07003290 if (changed) {
3291 // Send an accessibility event to announce the context change
3292 getWindow().getDecorView()
3293 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003294 }
Winson5c6bdbb2015-09-03 11:36:19 -07003295 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003296 }
3297
Winsone9f27272015-10-13 10:47:51 -07003298 /**
3299 * Shows the overview button.
3300 */
Adam Cohened307df2013-10-02 09:37:31 -07003301 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003302 showOverviewMode(animated, false);
3303 }
3304
3305 /**
3306 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3307 * onto one of the overview panel buttons.
3308 */
3309 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3310 Runnable postAnimRunnable = null;
3311 if (requestButtonFocus) {
3312 postAnimRunnable = new Runnable() {
3313 @Override
3314 public void run() {
3315 // Hitting the menu button when in touch mode does not trigger touch mode to
3316 // be disabled, so if requested, force focus on one of the overview panel
3317 // buttons.
3318 mOverviewPanel.requestFocusFromTouch();
3319 }
3320 };
3321 }
Adam Cohened307df2013-10-02 09:37:31 -07003322 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003323 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003324 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003325 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003326 }
3327
Winson Chungb745afb2015-03-02 11:51:23 -08003328 /**
3329 * Shows the apps view.
3330 */
Winson Chung76648c52015-07-10 14:33:23 -07003331 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3332 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003333 if (resetListToTop) {
3334 mAppsView.scrollToTop();
3335 }
Winson Chung4ac30062015-05-08 17:34:17 -07003336 if (updatePredictedApps) {
3337 tryAndUpdatePredictedApps();
3338 }
Winson Chung76648c52015-07-10 14:33:23 -07003339 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003340 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003341
Winson Chungb745afb2015-03-02 11:51:23 -08003342 /**
3343 * Shows the widgets view.
3344 */
3345 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003346 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003347 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003348 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003349 }
Winson Chung76648c52015-07-10 14:33:23 -07003350 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003351
3352 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003353 @Override
3354 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003355 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003356 }
3357 });
Winson Chungb745afb2015-03-02 11:51:23 -08003358 }
3359
3360 /**
3361 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003362 *
3363 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003364 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003365 // TODO: calling method should use the return value so that when {@code false} is returned
3366 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003367 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003368 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3369 mState != State.WIDGETS_SPRING_LOADED) {
3370 return false;
3371 }
3372 if (toState != State.APPS && toState != State.WIDGETS) {
3373 return false;
3374 }
Winson Chungb745afb2015-03-02 11:51:23 -08003375
3376 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003377 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3378 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003379 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003380 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003381 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003382
Michael Jurkab3e22d92011-10-31 15:58:33 -07003383 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003384 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003385
3386 // Pause the auto-advance of widgets until we are out of AllApps
3387 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003388 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003389 closeFolder();
3390
3391 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003392 getWindow().getDecorView()
3393 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003394 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003395 }
3396
Winson Chungcd99cd32015-04-29 11:03:24 -07003397 /**
3398 * Updates the workspace and interaction state on state change, and return the animation to this
3399 * new state.
3400 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003401 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003402 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003403 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003404 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003405 updateInteraction(fromState, toState);
3406 return anim;
3407 }
3408
Jun Mukaif0033da2015-08-04 18:34:30 -07003409 public void onLauncherClingShown() {
3410 // When a launcher cling appears, it should cover the underlying layers, so their focus
3411 // should be blocked.
3412 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3413 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3414 }
3415 }
3416
3417 public void onLauncherClingDismissed() {
3418 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3419 }
3420
Hyunyoung Song3f471442015-04-08 19:01:34 -07003421 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003422 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003423 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003424 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003425 }
Winson Chungb745afb2015-03-02 11:51:23 -08003426
Winson Chung006ee262015-08-03 14:40:11 -07003427 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003428 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003429 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003430
3431 if (isAppsViewVisible()) {
3432 mState = State.APPS_SPRING_LOADED;
3433 } else if (isWidgetsViewVisible()) {
3434 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003435 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003436 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003437 } else {
3438 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003439 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003440 }
Adam Cohen7777d962011-08-18 18:58:38 -07003441
Hyunyoung Song3f471442015-04-08 19:01:34 -07003442 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003443 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003444 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003445
Winson Chunge7a03942011-08-05 15:05:12 -07003446 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003447 @Override
3448 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003449 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003450 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3451 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003452 // Before we show workspace, hide all apps again because
3453 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3454 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003455 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003456 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003457 } else {
3458 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003459 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003460 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003461 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003462 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003463
Tony Wickhame0c33232016-02-08 11:37:04 -08003464 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003465 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3466 || mState == State.WIDGETS_SPRING_LOADED;
3467 }
3468
Michael Jurkad3ef3062010-11-23 16:23:58 -08003469 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003470 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003471 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003472 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003473 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003474 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003475 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3476 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003477 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003478 }
3479
Winson Chung4ac30062015-05-08 17:34:17 -07003480 /**
3481 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3482 * resumed.
3483 */
3484 private void tryAndUpdatePredictedApps() {
3485 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003486 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003487 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003488 mAppsView.setPredictedApps(apps);
Hyunyoung Songddec1c72016-04-12 18:32:04 -07003489 mUserEventLogger.setPredictedApps(apps);
Winson Chung4ac30062015-05-08 17:34:17 -07003490 }
3491 }
3492 }
3493
Michael Jurkab3e22d92011-10-31 15:58:33 -07003494 void lockAllApps() {
3495 // TODO
3496 }
3497
3498 void unlockAllApps() {
3499 // TODO
3500 }
3501
Winsonf768d932015-09-25 16:12:35 -07003502 public boolean launcherCallbacksProvidesSearch() {
3503 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3504 }
3505
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003506 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003507 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003508 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003509 }
3510
Adam Cohen24ce0b32014-01-14 16:18:14 -08003511 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003512 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3513 if (searchProvider == null) {
3514 return null;
3515 }
3516
3517 Bundle opts = new Bundle();
3518 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003519 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003520
Tony Wickham3a3517f2015-10-06 11:27:04 -07003521 // Determine the min and max dimensions of the widget.
3522 LauncherAppState app = LauncherAppState.getInstance();
3523 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3524 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3525 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003526 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3527 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003528 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003529 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003530 int minWidth = maxWidth;
3531 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003532 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3533 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3534 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3535 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3536 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003537 }
3538 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3539 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3540 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3541 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003542 if (LOGD) {
3543 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3544 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3545 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003546
Tony Wickham775455c2015-10-16 09:49:32 -07003547 if (mLauncherCallbacks != null) {
3548 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3549 }
3550
Sunny Goyalf7258242015-10-19 16:59:07 -07003551 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003552 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003553 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003554 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003555 || (widgetInfo == null)
3556 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003557 // A valid widget is not already bound.
3558 if (widgetId > -1) {
3559 mAppWidgetHost.deleteAppWidgetId(widgetId);
3560 widgetId = -1;
3561 }
3562
3563 // Try to bind a new widget
3564 widgetId = mAppWidgetHost.allocateAppWidgetId();
3565
3566 if (!AppWidgetManagerCompat.getInstance(this)
3567 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3568 mAppWidgetHost.deleteAppWidgetId(widgetId);
3569 widgetId = -1;
3570 }
3571
Sunny Goyalf7258242015-10-19 16:59:07 -07003572 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003573 .putInt(QSB_WIDGET_ID, widgetId)
3574 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003575 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003576 }
3577
Sunny Goyal8d595092015-07-06 12:22:14 -07003578 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003579 if (widgetId != -1) {
3580 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003581 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003582 mQsb.updateAppWidgetOptions(opts);
3583 mQsb.setPadding(0, 0, 0, 0);
3584 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003585 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003586 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003587 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003588 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003589 }
3590
Sunny Goyal22235bc2015-04-03 09:23:43 -07003591 private void reinflateQSBIfNecessary() {
3592 if (mQsb instanceof LauncherAppWidgetHostView &&
3593 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3594 mSearchDropTargetBar.removeView(mQsb);
3595 mQsb = null;
3596 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3597 }
3598 }
3599
Michael Jurkad7c28052012-04-27 15:43:36 -07003600 @Override
3601 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003602 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003603 final List<CharSequence> text = event.getText();
3604 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003605 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003606 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003607 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003608 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003609 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003610 } else if (mWorkspace != null) {
3611 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003612 } else {
3613 text.add(getString(R.string.all_apps_home_button_label));
3614 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003615 return result;
3616 }
3617
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003618 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003619 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003620 */
Adam Cohen091440a2015-03-18 14:16:05 -07003621 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003622 @Override
3623 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003624 closeSystemDialogs();
3625 }
3626 }
3627
3628 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003629 * If the activity is currently paused, signal that we need to run the passed Runnable
3630 * in onResume.
3631 *
3632 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003633 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3634 * wrong when we're not running, and if the activity comes back to what the configuration was
3635 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003636 *
3637 * Implementation of the method from LauncherModel.Callbacks.
3638 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003639 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003640 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003641 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003642 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003643 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003644 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003645 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003646 }
3647 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003648 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003649 return true;
3650 } else {
3651 return false;
3652 }
3653 }
3654
Michael Jurkac402cd92013-05-20 15:49:32 +02003655 private boolean waitUntilResume(Runnable run) {
3656 return waitUntilResume(run, false);
3657 }
3658
Michael Jurka1e2f4652013-07-08 18:03:46 -07003659 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003660 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003661 }
3662
Michael Jurka7607c2f2013-04-03 14:33:19 -07003663 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003664 * If the activity is currently paused, signal that we need to re-run the loader
3665 * in onResume.
3666 *
3667 * This needs to be called from incoming places where resources might have been loaded
3668 * while we are paused. That is becaues the Configuration might be wrong
3669 * when we're not running, and if it comes back to what it was when we
3670 * were paused, we are not restarted.
3671 *
3672 * Implementation of the method from LauncherModel.Callbacks.
3673 *
3674 * @return true if we are currently paused. The caller might be able to
3675 * skip some work in that case since we will come back again.
3676 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003677 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003678 public boolean setLoadOnResume() {
3679 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003680 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003681 mOnResumeNeedsLoad = true;
3682 return true;
3683 } else {
3684 return false;
3685 }
3686 }
3687
3688 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003689 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003690 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003691 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04003692 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003693 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003694 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003695 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003696 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003697 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003698 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003699
Joe Onorato9c1289c2009-08-17 11:03:03 -04003700 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003701 * Clear any pending bind callbacks. This is called when is loader is planning to
3702 * perform a full rebind from scratch.
3703 */
3704 @Override
3705 public void clearPendingBinds() {
3706 mBindOnResumeCallbacks.clear();
3707 if (mPendingExecutor != null) {
3708 mPendingExecutor.markCompleted();
3709 mPendingExecutor = null;
3710 }
3711 }
3712
3713 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003714 * Refreshes the shortcuts shown on the workspace.
3715 *
3716 * Implementation of the method from LauncherModel.Callbacks.
3717 */
3718 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003719 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003720
Winson Chungd64d1762013-08-20 14:37:16 -07003721 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003722 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003723 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003724
Michael Jurka05bf644e2011-11-30 20:28:53 -08003725 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003726 if (mHotseat != null) {
3727 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003728 }
3729 }
3730
Adam Cohendcd297f2013-06-18 13:13:40 -07003731 @Override
3732 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003733 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003734
Adam Cohen5084cba2013-09-03 12:01:16 -07003735 // If there are no screens, we need to have an empty screen
3736 if (orderedScreenIds.size() == 0) {
3737 mWorkspace.addExtraEmptyScreen();
3738 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003739
3740 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003741 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003742 if (hasCustomContentToLeft()) {
3743 mWorkspace.createCustomContentContainer();
3744 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003745 }
Winson Chung64359a52013-07-08 17:17:08 -07003746 }
3747
3748 @Override
3749 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003750 int count = orderedScreenIds.size();
3751 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003752 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003753 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003754 }
3755
Winson Chungd64d1762013-08-20 14:37:16 -07003756 public void bindAppsAdded(final ArrayList<Long> newScreens,
3757 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003758 final ArrayList<ItemInfo> addAnimated,
3759 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003760 Runnable r = new Runnable() {
3761 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003762 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003763 }
3764 };
3765 if (waitUntilResume(r)) {
3766 return;
3767 }
3768
Winson Chungd64d1762013-08-20 14:37:16 -07003769 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003770 if (newScreens != null) {
3771 bindAddScreens(newScreens);
3772 }
Winson Chungd64d1762013-08-20 14:37:16 -07003773
3774 // We add the items without animation on non-visible pages, and with
3775 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003776 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003777 bindItems(addNotAnimated, 0,
3778 addNotAnimated.size(), false);
3779 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003780 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003781 bindItems(addAnimated, 0,
3782 addAnimated.size(), true);
3783 }
Winson Chungc58497e2013-09-03 17:48:37 -07003784
Winson Chung87412982013-10-03 18:34:14 -07003785 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003786 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003787
Winson Chungb745afb2015-03-02 11:51:23 -08003788 if (addedApps != null && mAppsView != null) {
3789 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003790 }
Winson Chungd64d1762013-08-20 14:37:16 -07003791 }
3792
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003793 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003794 * Bind the items start-end from the list.
3795 *
3796 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003797 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003798 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003799 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3800 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003801 Runnable r = new Runnable() {
3802 public void run() {
3803 bindItems(shortcuts, start, end, forceAnimateIcons);
3804 }
3805 };
3806 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003807 return;
3808 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003809
Winson Chungf0c6ae02012-03-21 16:10:31 -07003810 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003811 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3812 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003813 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003814 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003815 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003816 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003818
3819 // Short circuit if we are loading dock items for a configuration which has no dock
3820 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3821 mHotseat == null) {
3822 continue;
3823 }
3824
Sunny Goyal639e9062015-08-19 19:17:06 -07003825 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003826 switch (item.itemType) {
3827 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3828 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003829 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003830 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003831
Winson Chung64359a52013-07-08 17:17:08 -07003832 /*
3833 * TODO: FIX collision case
3834 */
Winson Chungce376632013-07-11 16:12:41 -07003835 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3836 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3837 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003838 View v = cl.getChildAt(item.cellX, item.cellY);
3839 Object tag = v.getTag();
3840 String desc = "Collision while binding workspace item: " + item
3841 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003842 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003843 throw (new RuntimeException(desc));
3844 } else {
3845 Log.d(TAG, desc);
3846 }
Winson Chungce376632013-07-11 16:12:41 -07003847 }
Winson Chung64359a52013-07-08 17:17:08 -07003848 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003849 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003850 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003851 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003852 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003853 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003855 default:
3856 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003857 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003858
3859 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3860 item.cellY, 1, 1);
3861 if (animateIcons) {
3862 // Animate all the applications up now
3863 view.setAlpha(0f);
3864 view.setScaleX(0f);
3865 view.setScaleY(0f);
3866 bounceAnims.add(createNewAppBounceAnimation(view, i));
3867 newShortcutsScreenId = item.screenId;
3868 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003869 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003870
Winson Chung997a9232013-07-24 15:33:46 -07003871 if (animateIcons) {
3872 // Animate to the correct page
3873 if (newShortcutsScreenId > -1) {
3874 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003875 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003876 final Runnable startBounceAnimRunnable = new Runnable() {
3877 public void run() {
3878 anim.playTogether(bounceAnims);
3879 anim.start();
3880 }
3881 };
Winson Chung997a9232013-07-24 15:33:46 -07003882 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003883 // We post the animation slightly delayed to prevent slowdowns
3884 // when we are loading right after we return to launcher.
3885 mWorkspace.postDelayed(new Runnable() {
3886 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003887 if (mWorkspace != null) {
3888 mWorkspace.snapToPage(newScreenIndex);
3889 mWorkspace.postDelayed(startBounceAnimRunnable,
3890 NEW_APPS_ANIMATION_DELAY);
3891 }
Winson Chung94d67682013-09-25 16:29:40 -07003892 }
3893 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003894 } else {
3895 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003896 }
3897 }
Winson Chung64359a52013-07-08 17:17:08 -07003898 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003899 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003900 }
3901
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003902 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3903 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3904 view.updateIcon(mIconCache);
3905 item.hostView = view;
3906 item.hostView.updateAppWidget(null);
3907 item.hostView.setOnClickListener(this);
3908 addAppWidgetToWorkspace(item, null, false);
3909 mWorkspace.requestLayout();
3910 }
3911
Joe Onorato9c1289c2009-08-17 11:03:03 -04003912 /**
3913 * Add the views for a widget to the workspace.
3914 *
3915 * Implementation of the method from LauncherModel.Callbacks.
3916 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003917 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003918 Runnable r = new Runnable() {
3919 public void run() {
3920 bindAppWidget(item);
3921 }
3922 };
3923 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003924 return;
3925 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003926
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003927 if (mIsSafeModeEnabled) {
3928 bindSafeModeWidget(item);
3929 return;
3930 }
3931
Daniel Sandler843e8602010-06-07 14:59:01 -04003932 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3933 if (DEBUG_WIDGETS) {
3934 Log.d(TAG, "bindAppWidget: " + item);
3935 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003936
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003937 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003938
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003939 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3940 // If the provider is not ready, bind as a pending widget.
3941 appWidgetInfo = null;
3942 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3943 // The widget id is not valid. Try to find the widget based on the provider info.
3944 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3945 } else {
3946 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3947 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003948
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003949 // If the provider is ready, but the width is not yet restored, try to restore it.
3950 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3951 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003952 if (appWidgetInfo == null) {
3953 if (DEBUG_WIDGETS) {
3954 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3955 + " belongs to component " + item.providerName
3956 + ", as the povider is null");
3957 }
3958 LauncherModel.deleteItemFromDatabase(this, item);
3959 return;
3960 }
Sunny Goyalff572272014-07-23 13:58:07 -07003961
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003962 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003963 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003964 // Note: This assumes that the id remap broadcast is received before this step.
3965 // If that is not the case, the id remap will be ignored and user may see the
3966 // click to setup view.
Sunny Goyal16466f12016-03-10 05:34:30 -08003967 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003968 pendingInfo.spanX = item.spanX;
3969 pendingInfo.spanY = item.spanY;
3970 pendingInfo.minSpanX = item.minSpanX;
3971 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08003972 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07003973
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003974 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
3975 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
3976 newWidgetId, appWidgetInfo, options);
3977
3978 // TODO consider showing a permission dialog when the widget is clicked.
3979 if (!success) {
3980 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
3981 if (DEBUG_WIDGETS) {
3982 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3983 + " belongs to component " + item.providerName
3984 + ", as the launcher is unable to bing a new widget id");
3985 }
3986 LauncherModel.deleteItemFromDatabase(this, item);
3987 return;
Sunny Goyalff572272014-07-23 13:58:07 -07003988 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003989
3990 item.appWidgetId = newWidgetId;
3991
3992 // If the widget has a configure activity, it is still needs to set it up, otherwise
3993 // the widget is ready to go.
3994 item.restoreStatus = (appWidgetInfo.configure == null)
3995 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
3996 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
3997
3998 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003999 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004000 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004001 // The widget was marked as UI not ready, but there is no configure activity to
4002 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004003 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4004 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004005 }
Sunny Goyalff572272014-07-23 13:58:07 -07004006 }
4007
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004008 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004009 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004010 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4011 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004012 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004013
Sunny Goyal56c73602015-09-25 12:55:01 -07004014 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004015 if (appWidgetInfo == null) {
4016 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07004017 deleteWidgetInfo(item);
4018 return;
4019 }
4020
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004021 item.hostView = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004022 item.minSpanX = appWidgetInfo.minSpanX;
4023 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004024 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004025 } else {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004026 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4027 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004028 view.updateIcon(mIconCache);
4029 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004030 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004031 item.hostView.setOnClickListener(this);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004032 addAppWidgetToWorkspace(item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004033 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004034 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004035
Daniel Sandler843e8602010-06-07 14:59:01 -04004036 if (DEBUG_WIDGETS) {
4037 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4038 + (SystemClock.uptimeMillis()-start) + "ms");
4039 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004040 }
4041
Sunny Goyalff572272014-07-23 13:58:07 -07004042 /**
4043 * Restores a pending widget.
4044 *
4045 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07004046 */
4047 private void completeRestoreAppWidget(final int appWidgetId) {
4048 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4049 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4050 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4051 return;
4052 }
4053
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004054 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004055 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4056
4057 mWorkspace.reinflateWidgetsIfNecessary();
4058 LauncherModel.updateItemInDatabase(this, info);
4059 }
4060
Adam Cohen1462de32012-07-24 22:34:36 -07004061 public void onPageBoundSynchronously(int page) {
4062 mSynchronouslyBoundPages.add(page);
4063 }
4064
Sunny Goyal527c7d32015-08-28 15:19:36 -07004065 @Override
4066 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4067 if (mPendingExecutor != null) {
4068 mPendingExecutor.markCompleted();
4069 }
4070 mPendingExecutor = executor;
4071 executor.attachTo(this);
4072 }
4073
4074 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4075 if (mPendingExecutor == executor) {
4076 mPendingExecutor = null;
4077 }
4078 }
4079
Joe Onorato9c1289c2009-08-17 11:03:03 -04004080 /**
4081 * Callback saying that there aren't any more items to bind.
4082 *
4083 * Implementation of the method from LauncherModel.Callbacks.
4084 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004085 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004086 Runnable r = new Runnable() {
4087 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004088 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004089 }
4090 };
4091 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004092 return;
4093 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004094 if (mSavedState != null) {
4095 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004096 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004097 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004098
Joe Onorato9c1289c2009-08-17 11:03:03 -04004099 mSavedState = null;
4100 }
4101
Adam Cohen1462de32012-07-24 22:34:36 -07004102 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004103
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004104 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004105 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004106
4107 // If we received the result of any pending adds while the loader was running (e.g. the
4108 // widget configuration forced an orientation change), process them now.
4109 if (sPendingAddItem != null) {
4110 final long screenId = completeAdd(sPendingAddItem);
4111
4112 // TODO: this moves the user to the page where the pending item was added. Ideally,
4113 // the screen would be guaranteed to exist after bind, and the page would be set through
4114 // the workspace restore process.
4115 mWorkspace.post(new Runnable() {
4116 @Override
4117 public void run() {
4118 mWorkspace.snapToScreenId(screenId);
4119 }
4120 });
4121 sPendingAddItem = null;
4122 }
4123
Sunny Goyal756adbc2015-04-16 15:20:51 -07004124 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004125
4126 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004127 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004128 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004129 }
4130
Adam Cohen3ed316a2014-07-23 18:21:20 -07004131 private void sendLoadingCompleteBroadcastIfNecessary() {
4132 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4133 String permission =
4134 getResources().getString(R.string.receive_first_load_broadcast_permission);
4135 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4136 sendBroadcast(intent, permission);
4137 SharedPreferences.Editor editor = mSharedPrefs.edit();
4138 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4139 editor.apply();
4140 }
4141 }
4142
Winson Chunga0b7e862013-09-05 16:03:15 -07004143 public boolean isAllAppsButtonRank(int rank) {
4144 if (mHotseat != null) {
4145 return mHotseat.isAllAppsButtonRank(rank);
4146 }
4147 return false;
4148 }
4149
Winson Chunga2413752012-04-03 14:22:34 -07004150 private boolean canRunNewAppsAnimation() {
4151 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004152 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4153 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004154 }
4155
Winson Chungc9168342013-06-26 14:54:55 -07004156 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004157 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004158 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4159 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004160 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004161 return bounceAnim;
4162 }
4163
Adam Cohen27772732013-11-11 14:00:56 +00004164 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004165 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004166 }
4167
Tony Wickham3a3517f2015-10-06 11:27:04 -07004168 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004169 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004170 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004171 }
4172
Tony Wickham55616cd2015-09-23 14:55:17 -07004173 public int getSearchBarHeight() {
4174 if (mLauncherCallbacks != null) {
4175 return mLauncherCallbacks.getSearchBarHeight();
4176 }
4177 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4178 }
4179
Winson Chung88fa7412015-08-03 14:25:28 -07004180 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004181 if (mSearchDropTargetBar == null) {
4182 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004183 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004184 if (mQsb != null) {
4185 mSearchDropTargetBar.removeView(mQsb);
4186 mQsb = null;
4187 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004188 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004189 }
4190
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004191 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004192 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4193 * multiple calls to bind the same list.)
4194 */
4195 @Thunk ArrayList<AppInfo> mTmpAppsList;
4196 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4197 public void run() {
4198 bindAllApplications(mTmpAppsList);
4199 mTmpAppsList = null;
4200 }
4201 };
4202
4203 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004204 * Add the icons for all apps.
4205 *
4206 * Implementation of the method from LauncherModel.Callbacks.
4207 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004208 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004209 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4210 mTmpAppsList = apps;
4211 return;
4212 }
4213
Winson Chungb745afb2015-03-02 11:51:23 -08004214 if (mAppsView != null) {
4215 mAppsView.setApps(apps);
4216 }
Adam Cohen9211d422014-10-07 18:14:53 -07004217 if (mLauncherCallbacks != null) {
4218 mLauncherCallbacks.bindAllApplications(apps);
4219 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004220 }
4221
4222 /**
4223 * A package was updated.
4224 *
4225 * Implementation of the method from LauncherModel.Callbacks.
4226 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004227 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004228 Runnable r = new Runnable() {
4229 public void run() {
4230 bindAppsUpdated(apps);
4231 }
4232 };
4233 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004234 return;
4235 }
4236
Winson Chungb745afb2015-03-02 11:51:23 -08004237 if (mAppsView != null) {
4238 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004239 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004240 }
4241
Sunny Goyal4390ace2014-10-13 11:33:11 -07004242 @Override
4243 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4244 Runnable r = new Runnable() {
4245 public void run() {
4246 bindWidgetsRestored(widgets);
4247 }
4248 };
4249 if (waitUntilResume(r)) {
4250 return;
4251 }
4252 mWorkspace.widgetsRestored(widgets);
4253 }
4254
Joe Onorato9c1289c2009-08-17 11:03:03 -04004255 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004256 * Some shortcuts were updated in the background.
4257 *
4258 * Implementation of the method from LauncherModel.Callbacks.
4259 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004260 @Override
4261 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4262 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004263 Runnable r = new Runnable() {
4264 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004265 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004266 }
4267 };
4268 if (waitUntilResume(r)) {
4269 return;
4270 }
4271
Sunny Goyal4390ace2014-10-13 11:33:11 -07004272 if (!updated.isEmpty()) {
4273 mWorkspace.updateShortcuts(updated);
4274 }
4275
4276 if (!removed.isEmpty()) {
4277 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4278 for (ShortcutInfo si : removed) {
4279 removedComponents.add(si.getTargetComponent());
4280 }
4281 mWorkspace.removeItemsByComponentName(removedComponents, user);
4282 // Notify the drag controller
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004283 mDragController.onAppsRemoved(new HashSet<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004284 }
4285 }
4286
4287 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004288 * Update the state of a package, typically related to install state.
4289 *
4290 * Implementation of the method from LauncherModel.Callbacks.
4291 */
Sunny Goyale755d462014-07-22 13:48:29 -07004292 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004293 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4294 Runnable r = new Runnable() {
4295 public void run() {
4296 bindRestoreItemsChange(updates);
4297 }
4298 };
4299 if (waitUntilResume(r)) {
4300 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004301 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004302
Sunny Goyal756adbc2015-04-16 15:20:51 -07004303 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004304 }
4305
4306 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004307 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07004308 * in addition to specific applications to remove, the reason being that
4309 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004310 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07004311 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004312 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004313 @Override
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004314 public void bindWorkspaceComponentsRemoved(
4315 final HashSet<String> packageNames, final HashSet<ComponentName> components,
4316 final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004317 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004318 public void run() {
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004319 bindWorkspaceComponentsRemoved(packageNames, components, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004320 }
Winson Chungd64d1762013-08-20 14:37:16 -07004321 };
4322 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004323 return;
4324 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004325 if (!packageNames.isEmpty()) {
4326 mWorkspace.removeItemsByPackageName(packageNames, user);
4327 }
4328 if (!components.isEmpty()) {
4329 mWorkspace.removeItemsByComponentName(components, user);
4330 }
4331 // Notify the drag controller
4332 mDragController.onAppsRemoved(packageNames, components);
Winson Chung83892cc2013-05-01 16:53:33 -07004333
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004334 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004335
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004336 @Override
4337 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
4338 Runnable r = new Runnable() {
4339 public void run() {
4340 bindAppInfosRemoved(appInfos);
4341 }
4342 };
4343 if (waitUntilResume(r)) {
4344 return;
Joe Onorato36115782010-06-17 13:28:48 -04004345 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004346
Winson Chungdf95eb12013-10-16 14:57:07 -07004347 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004348 if (mAppsView != null) {
4349 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004350 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004351 }
Joe Onoratobe386092009-11-17 17:32:16 -08004352
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004353 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004354 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004355 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004356 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004357 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004358
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004359 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004360 public void bindWidgetsModel(WidgetsModel model) {
4361 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004362 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004363 return;
4364 }
4365
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004366 if (mWidgetsView != null && model != null) {
4367 mWidgetsView.addWidgets(model);
4368 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004369 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004370 }
4371
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004372 @Override
4373 public void notifyWidgetProvidersChanged() {
4374 if (mWorkspace.getState().shouldUpdateWidget) {
4375 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4376 }
4377 }
4378
Winson Chung400438b2011-01-16 17:53:48 -08004379 private int mapConfigurationOriActivityInfoOri(int configOri) {
4380 final Display d = getWindowManager().getDefaultDisplay();
4381 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4382 switch (d.getRotation()) {
4383 case Surface.ROTATION_0:
4384 case Surface.ROTATION_180:
4385 // We are currently in the same basic orientation as the natural orientation
4386 naturalOri = configOri;
4387 break;
4388 case Surface.ROTATION_90:
4389 case Surface.ROTATION_270:
4390 // We are currently in the other basic orientation to the natural orientation
4391 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4392 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4393 break;
4394 }
4395
4396 int[] oriMap = {
4397 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4398 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4399 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4400 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4401 };
4402 // Since the map starts at portrait, we need to offset if this device's natural orientation
4403 // is landscape.
4404 int indexOffset = 0;
4405 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4406 indexOffset = 1;
4407 }
4408 return oriMap[(d.getRotation() + indexOffset) % 4];
4409 }
Adam Cohen446e9402011-09-15 18:21:21 -07004410
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004411 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004412 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004413 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004414 if (Utilities.ATLEAST_JB_MR2) {
4415 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4416 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004417 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4418 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004419 }
Winson Chung4b919f82012-05-01 10:44:08 -07004420 }
4421 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004422
Winson Chung4b919f82012-05-01 10:44:08 -07004423 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004424 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004425 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004426 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004427 } else {
4428 mHandler.postDelayed(new Runnable() {
4429 public void run() {
4430 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4431 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004432 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004433 }
Winson Chung4b919f82012-05-01 10:44:08 -07004434 }
Winson Chung400438b2011-01-16 17:53:48 -08004435 }
4436
Winson Chunge43a1e72014-01-15 10:33:02 -08004437 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004438 if (mLauncherCallbacks != null) {
4439 return mLauncherCallbacks.isLauncherPreinstalled();
4440 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004441 PackageManager pm = getPackageManager();
4442 try {
4443 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4444 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4445 return true;
4446 } else {
4447 return false;
4448 }
4449 } catch (NameNotFoundException e) {
4450 e.printStackTrace();
4451 return false;
4452 }
4453 }
4454
Adam Cohenea90f832014-05-21 15:03:34 -07004455 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004456 * To be overridden by subclasses to indicate that there is an activity to launch
4457 * before showing the standard launcher experience.
4458 */
4459 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004460 if (mLauncherCallbacks != null) {
4461 return mLauncherCallbacks.hasFirstRunActivity();
4462 }
Adam Cohen432609a2014-03-13 17:03:22 -07004463 return false;
4464 }
4465
4466 /**
4467 * To be overridden by subclasses to launch any first run activity
4468 */
4469 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004470 if (mLauncherCallbacks != null) {
4471 return mLauncherCallbacks.getFirstRunActivity();
4472 }
Adam Cohen432609a2014-03-13 17:03:22 -07004473 return null;
4474 }
4475
Winson Chunga6945242014-01-08 14:04:34 -08004476 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004477 return !ActivityManager.isRunningInTestHarness() &&
4478 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004479 }
4480
Adam Cohen4a9423d2014-03-28 14:22:31 -07004481 protected boolean hasRunFirstRunActivity() {
4482 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4483 }
4484
Adam Cohen432609a2014-03-13 17:03:22 -07004485 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004486 if (shouldRunFirstRunActivity() &&
4487 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004488 Intent firstRunIntent = getFirstRunActivity();
4489 if (firstRunIntent != null) {
4490 startActivity(firstRunIntent);
4491 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004492 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004493 }
4494 }
Adam Cohen432609a2014-03-13 17:03:22 -07004495 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004496 }
4497
4498 private void markFirstRunActivityShown() {
4499 SharedPreferences.Editor editor = mSharedPrefs.edit();
4500 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4501 editor.apply();
4502 }
4503
Adam Cohen432609a2014-03-13 17:03:22 -07004504 /**
4505 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4506 * screen that must be displayed and dismissed.
4507 */
4508 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004509 if (mLauncherCallbacks != null) {
4510 return mLauncherCallbacks.hasDismissableIntroScreen();
4511 }
Adam Cohen432609a2014-03-13 17:03:22 -07004512 return false;
4513 }
4514
4515 /**
4516 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4517 */
4518 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004519 if (mLauncherCallbacks != null) {
4520 return mLauncherCallbacks.getIntroScreen();
4521 }
Adam Cohen432609a2014-03-13 17:03:22 -07004522 return null;
4523 }
4524
4525 /**
4526 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4527 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4528 */
4529 private boolean shouldShowIntroScreen() {
4530 return hasDismissableIntroScreen() &&
4531 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4532 }
4533
4534 protected void showIntroScreen() {
4535 View introScreen = getIntroScreen();
4536 changeWallpaperVisiblity(false);
4537 if (introScreen != null) {
4538 mDragLayer.showOverlayView(introScreen);
4539 }
4540 }
4541
4542 public void dismissIntroScreen() {
4543 markIntroScreenDismissed();
4544 if (showFirstRunActivity()) {
4545 // We delay hiding the intro view until the first run activity is showing. This
4546 // avoids a blip.
4547 mWorkspace.postDelayed(new Runnable() {
4548 @Override
4549 public void run() {
4550 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004551 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004552 }
4553 }, ACTIVITY_START_DELAY);
4554 } else {
4555 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004556 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004557 }
4558 changeWallpaperVisiblity(true);
4559 }
4560
4561 private void markIntroScreenDismissed() {
4562 SharedPreferences.Editor editor = mSharedPrefs.edit();
4563 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4564 editor.apply();
4565 }
4566
Adam Cohen091440a2015-03-18 14:16:05 -07004567 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004568 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4569 // on the device, then we always show the first run cling experience (or if there is no
4570 // launcher2). Otherwise, we prompt the user upon started for migration
4571 LauncherClings launcherClings = new LauncherClings(this);
4572 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004573 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004574 if (mModel.canMigrateFromOldLauncherDb(this)) {
4575 launcherClings.showMigrationCling();
4576 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004577 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004578 }
4579 }
4580 }
4581
Winson Chunga6945242014-01-08 14:04:34 -08004582 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004583 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4584 if (mHotseat != null) mHotseat.setAlpha(1f);
4585 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004586 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4587 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004588 }
4589
4590 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004591 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4592 if (mHotseat != null) mHotseat.setAlpha(0f);
4593 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004594 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4595 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004596 }
4597
Winson Chung5ffd51d2015-06-25 11:36:50 -07004598 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004599 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004600 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004601 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004602 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004603 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004604 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4605 if (userHandle != null) {
4606 user = UserHandleCompat.fromUser(userHandle);
4607 }
4608 }
4609 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004610 }
4611
4612 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004613 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004614 if (user == null) {
4615 user = UserHandleCompat.myUserHandle();
4616 }
4617
4618 // Called from search suggestion, add the profile extra to the intent to ensure that we
4619 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004620 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004621 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004622 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004623 return null;
4624 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004625 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004626 }
4627
Winson Chung5ffd51d2015-06-25 11:36:50 -07004628 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004629 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4630 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004631 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004632 UserHandleCompat.myUserHandle());
4633 }
4634
Winson Chung5ffd51d2015-06-25 11:36:50 -07004635 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004636 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4637 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004638 mWorkspace.onExternalDragStartedWithItem(dragView);
4639 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004640 }
4641
Winson Chung5ffd51d2015-06-25 11:36:50 -07004642 protected void moveWorkspaceToDefaultScreen() {
4643 mWorkspace.moveToDefaultScreen(false);
4644 }
4645
Anjali Koppalf5d29132014-02-28 13:33:27 -08004646 @Override
4647 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004648 if (mLauncherCallbacks != null) {
4649 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4650 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004651 }
4652
Winson Chung80baf5a2010-08-09 16:03:15 -07004653 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004654 * Returns a FastBitmapDrawable with the icon, accurately sized.
4655 */
4656 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4657 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4658 d.setFilterBitmap(true);
4659 resizeIconDrawable(d);
4660 return d;
4661 }
4662
4663 /**
4664 * Resizes an icon drawable to the correct icon size.
4665 */
Winson5fbe0742015-09-30 15:33:00 -07004666 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004667 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004668 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004669 }
4670
4671 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004672 * Prints out out state for debugging.
4673 */
4674 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004675 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004676 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004677 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4678 Log.d(TAG, "mRestoring=" + mRestoring);
4679 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Joe Onoratobe386092009-11-17 17:32:16 -08004680 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004681 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004682
Daniel Sandler325dc232013-06-05 22:57:57 -04004683 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004684 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004685
4686 @Override
4687 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4688 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004689 // Dump workspace
4690 writer.println(prefix + "Workspace Items");
4691 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4692 writer.println(prefix + " Homescreen " + i);
4693
4694 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4695 for (int j = 0; j < layout.getChildCount(); j++) {
4696 Object tag = layout.getChildAt(j).getTag();
4697 if (tag != null) {
4698 writer.println(prefix + " " + tag.toString());
4699 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004700 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004701 }
Sunny Goyala1365452015-10-01 15:46:24 -07004702
4703 writer.println(prefix + " Hotseat");
4704 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4705 for (int j = 0; j < layout.getChildCount(); j++) {
4706 Object tag = layout.getChildAt(j).getTag();
4707 if (tag != null) {
4708 writer.println(prefix + " " + tag.toString());
4709 }
4710 }
4711
4712 synchronized (sDumpLogs) {
4713 writer.println();
4714 writer.println(prefix + "Debug logs");
4715 for (String log : sDumpLogs) {
4716 writer.println(prefix + " " + log);
4717 }
4718 }
4719
Adam Cohen9211d422014-10-07 18:14:53 -07004720 if (mLauncherCallbacks != null) {
4721 mLauncherCallbacks.dump(prefix, fd, writer, args);
4722 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004723 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004724
Sunny Goyala1365452015-10-01 15:46:24 -07004725 public static void addDumpLog(String tag, String log) {
4726 Log.d(tag, log);
4727 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004728 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004729 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004730 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004731 }
4732
Adam Cohen59400422014-03-05 18:07:04 -08004733 public static CustomAppWidget getCustomAppWidget(String name) {
4734 return sCustomAppWidgets.get(name);
4735 }
4736
4737 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4738 return sCustomAppWidgets;
4739 }
4740
Sunny Goyal29538332016-02-18 09:10:19 -08004741 public static List<View> getFolderContents(View icon) {
4742 if (icon instanceof FolderIcon) {
4743 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4744 } else {
4745 return Collections.EMPTY_LIST;
4746 }
4747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004748}
Michael Jurka2763be32011-02-24 11:19:57 -08004749
Dan Sandlerd5024042014-01-09 15:01:33 -05004750interface DebugIntents {
4751 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4752 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004753}