blob: d2d07cc5a8fc6f8039a4e19ce4619d4587b0442b [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;
Romain Guy6fefcf12009-06-11 13:07:43 -0700151
Dan Sandlerd5024042014-01-09 15:01:33 -0500152 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
153
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700155 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700156 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700157 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158
Michael Jurka8b805b12012-04-18 14:23:14 -0700159 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700160 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700161
Sunny Goyal28c6b962015-10-12 11:42:05 -0700162 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
163
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700164 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
165 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
166 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
167
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700168 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
169
Mathew Inwood876a8462013-06-14 14:12:41 +0100170 /**
171 * IntentStarter uses request codes starting with this. This must be greater than all activity
172 * request codes used internally.
173 */
174 protected static final int REQUEST_LAST = 100;
175
Michael Jurka0a457bf2012-11-19 14:05:05 -0800176 // To turn on these properties, type
177 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800178 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179
Winson Chung2672ff92012-05-04 16:22:30 -0700180 // The Intent extra that defines whether to ignore the launch animation
181 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400182 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 // Type: int
185 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700186 // Type: int
187 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700188 // Type: Content Values / parcelable
189 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700190 // Type: parcelable
191 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000192 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800193 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
Adam Cohen432609a2014-03-13 17:03:22 -0700195 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800196 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
197
Adam Cohen3ed316a2014-07-23 18:21:20 -0700198 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
199 static final String ACTION_FIRST_LOAD_COMPLETE =
200 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
201
Sunny Goyal594d76d2014-11-06 10:12:54 -0800202 private static final String QSB_WIDGET_ID = "qsb_widget_id";
203 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
204
Winson Chunga6945242014-01-08 14:04:34 -0800205 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
206
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700208 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
209 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700210
Adam Cohen091440a2015-03-18 14:16:05 -0700211 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700212 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700213
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700214 private boolean mIsSafeModeEnabled;
215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800217 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700218 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700219 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
Winson Chunga2413752012-04-03 14:22:34 -0700221 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700222 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
223 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700225
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800226 private final BroadcastReceiver mCloseSystemDialogsReceiver
227 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800228
Adam Cohen091440a2015-03-18 14:16:05 -0700229 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700230 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800231 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700232 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800233 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700234
235 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Sunny Goyalffe83f12014-08-14 17:39:34 -0700237 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700238 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700239
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700240 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800241 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800242 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700243
Michael Jurka0280c3b2010-09-17 15:00:07 -0700244 private int[] mTmpAddItemCellCoordinates = new int[2];
245
Sunny Goyal316490e2015-06-02 09:38:28 -0700246 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800247 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700248
Michael Jurka838a4ca2011-02-07 13:33:06 -0800249 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700250 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700251
Winson Chungc51db6a2011-10-05 11:44:49 -0700252 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700253 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700254
255 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700256 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700257
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700258 // Main container view and the model for the widget tray screen.
259 @Thunk WidgetsContainerView mWidgetsView;
260 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700261
Sunny Goyal594d76d2014-11-06 10:12:54 -0800262 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700265 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
266 // scroll issues (because the workspace may not have been measured yet) and extra work.
267 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
268 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269
270 private SpannableStringBuilder mDefaultKeySsb = null;
271
Adam Cohen091440a2015-03-18 14:16:05 -0700272 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400273
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800274 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 private boolean mRestoring;
276 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700277 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278
Michael Jurka1e2f4652013-07-08 18:03:46 -0700279 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700280 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700281 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700282
Joe Onorato9c1289c2009-08-17 11:03:03 -0400283 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800284 private IconCache mIconCache;
Tony Wickham827cef22016-03-17 15:39:39 -0700285 private ExtractedColors mExtractedColors;
Adam Cohen091440a2015-03-18 14:16:05 -0700286 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800287 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700288 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800289 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290
Sunny Goyal639e9062015-08-19 19:17:06 -0700291 private LauncherClings mClings;
292
Adam Cohen61f560d2013-09-30 15:58:20 -0700293 private View.OnTouchListener mHapticFeedbackTouchListener;
294
Adam Cohended9f8d2010-11-03 13:25:16 -0700295 // Related to the auto-advancing of widgets
296 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700297 private static final int ADVANCE_INTERVAL = 20000;
298 private static final int ADVANCE_STAGGER = 250;
299
300 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700301 private long mAutoAdvanceSentTime;
302 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700303 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700304
Winson Chung400438b2011-01-16 17:53:48 -0800305 // Determines how long to wait after a rotation before restoring the screen orientation to
306 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700307 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800308
Adam Cohen091440a2015-03-18 14:16:05 -0700309 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700310
Adam Cohen1462de32012-07-24 22:34:36 -0700311 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700312 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700313
Sunny Goyala1365452015-10-01 15:46:24 -0700314 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
315 private static final Date sDateStamp = new Date();
316 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700317 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700318
Winson Chung46353de2012-02-16 14:05:10 -0800319 // We only want to get the SharedPreferences once since it does an FS stat each time we get
320 // it from the context.
321 private SharedPreferences mSharedPrefs;
322
Winson Chungf0c6ae02012-03-21 16:10:31 -0700323 // Holds the page that we need to animate to, and the icon views that we need to animate up
324 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700325 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700326 private Bitmap mFolderIconBitmap;
327 private Canvas mFolderIconCanvas;
328 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700329
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700330 private DeviceProfile mDeviceProfile;
331
Adam Cohen4b66bf32015-09-18 12:15:19 -0700332 private boolean mMoveToDefaultScreenFromNewIntent;
333
Winson Chung13eb5272015-05-11 16:30:13 -0700334 // This is set to the view that launched the activity that navigated the user away from
335 // launcher. Since there is no callback for when the activity has finished launching, enable
336 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800337 private BubbleTextView mWaitingForResume;
338
Adam Cohen59400422014-03-05 18:07:04 -0800339 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
340 new HashMap<String, CustomAppWidget>();
341
Adam Cohen59400422014-03-05 18:07:04 -0800342 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700343 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
344 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800345 }
346 }
347
Adam Cohen091440a2015-03-18 14:16:05 -0700348 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700349 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700350 if (mWorkspace != null) {
351 mWorkspace.buildPageHardwareLayers();
352 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700353 }
354 };
355
Adam Cohendb364c32014-05-20 14:23:40 -0700356 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800357
Adam Cohen091440a2015-03-18 14:16:05 -0700358 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800359 int requestCode;
360 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700361 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700362 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800363 int cellX;
364 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700365 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800366 }
367
Daniel Sandlerff02d492013-08-05 02:12:05 -0400368 private Stats mStats;
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
Daniel Sandlerff02d492013-08-05 02:12:05 -0400428 mStats = new Stats(this);
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800429 initLogger();
Daniel Sandlerff02d492013-08-05 02:12:05 -0400430
Sunny Goyalffe83f12014-08-14 17:39:34 -0700431 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700432
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700433 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
434 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700435
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700436 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
437 // this also ensures that any synchronous binding below doesn't re-trigger another
438 // LauncherModel load.
439 mPaused = false;
440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200442 android.os.Debug.startMethodTracing(
443 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 }
445
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700447
Tony Wickhameef44322015-10-20 13:24:36 -0700448 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
449 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700451 mDeviceProfile.layout(this);
Tony Wickham827cef22016-03-17 15:39:39 -0700452 mExtractedColors = new ExtractedColors();
453 loadExtractedColorsAndColorItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454
Tony Wickhame2217252016-03-22 16:34:23 -0700455 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
456 .addAccessibilityStateChangeListener(this);
457
Joe Onorato7c312c12009-08-13 21:36:53 -0700458 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 mSavedState = savedInstanceState;
461 restoreState(mSavedState);
462
463 if (PROFILE_STARTUP) {
464 android.os.Debug.stopMethodTracing();
465 }
466
467 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700468 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 // If the user leaves launcher, then we should just load items asynchronously when
470 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700471 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 } else {
473 // We only load the page synchronously if the user rotates (or triggers a
474 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700475 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800477 }
478
479 // For handling default keys
480 mDefaultKeySsb = new SpannableStringBuilder();
481 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800482
483 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
484 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800485
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800486 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700487 // In case we are on a device with locked rotation, we should look at preferences to check
488 // if the user has specifically allowed rotation.
489 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700490 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700491 }
492
493 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
494 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400495 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700496
Adam Cohen9211d422014-10-07 18:14:53 -0700497 if (mLauncherCallbacks != null) {
498 mLauncherCallbacks.onCreate(savedInstanceState);
499 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700500
501 if (shouldShowIntroScreen()) {
502 showIntroScreen();
503 } else {
504 showFirstRunActivity();
505 showFirstRunClings();
506 }
Adam Cohen9211d422014-10-07 18:14:53 -0700507 }
508
Sunny Goyal7779d622015-06-11 16:18:39 -0700509 @Override
510 public void onSettingsChanged(String settings, boolean value) {
511 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
512 mRotationEnabled = value;
513 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
514 mUpdateOrientationRunnable.run();
515 }
516 }
517 }
518
Tony Wickham827cef22016-03-17 15:39:39 -0700519 @Override
520 public void onExtractedColorsChanged() {
521 loadExtractedColorsAndColorItems();
522 }
523
524 private void loadExtractedColorsAndColorItems() {
525 if (mExtractedColors != null) {
526 mExtractedColors.load(this);
527 // TODO: pass mExtractedColors to interested items such as hotseat.
Tony Wickham827cef22016-03-17 15:39:39 -0700528 }
529 }
530
Adam Cohen9211d422014-10-07 18:14:53 -0700531 private LauncherCallbacks mLauncherCallbacks;
532
533 public void onPostCreate(Bundle savedInstanceState) {
534 super.onPostCreate(savedInstanceState);
535 if (mLauncherCallbacks != null) {
536 mLauncherCallbacks.onPostCreate(savedInstanceState);
537 }
538 }
539
Sunny Goyal32554d12015-12-03 15:31:25 -0800540 /**
541 * Call this after onCreate to set or clear overlay.
542 */
543 public void setLauncherOverlay(LauncherOverlay overlay) {
544 if (overlay != null) {
545 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
546 }
547 mWorkspace.setLauncherOverlay(overlay);
548 }
549
Adam Cohen9211d422014-10-07 18:14:53 -0700550 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
551 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700552 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700553 private boolean mWorkspaceImportanceStored = false;
554 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700555 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800556 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700557 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
558
559 @Override
560 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700561 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700562 return;
563 }
564 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700565 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700566 if (mWorkspace != null) {
567 mWorkspaceImportanceForAccessibility =
568 mWorkspace.getImportantForAccessibility();
569 mWorkspace.setImportantForAccessibility(
570 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
571 mWorkspaceImportanceStored = true;
572 }
573 if (mHotseat != null) {
574 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
575 mHotseat.setImportantForAccessibility(
576 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
577 mHotseatImportanceStored = true;
578 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700579 }
580
581 @Override
582 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700583 if (mWorkspaceImportanceStored && mWorkspace != null) {
584 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
585 }
586 if (mHotseatImportanceStored && mHotseat != null) {
587 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
588 }
589 mWorkspaceImportanceStored = false;
590 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700591 }
592 });
Adam Cohen9211d422014-10-07 18:14:53 -0700593 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700594 }
595
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700596 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700597 public void onLauncherProviderChange() {
598 if (mLauncherCallbacks != null) {
599 mLauncherCallbacks.onLauncherProviderChange();
600 }
601 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700602
Adam Cohen9211d422014-10-07 18:14:53 -0700603 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700604 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700605 if (mLauncherCallbacks != null) {
606 return mLauncherCallbacks.hasCustomContentToLeft();
607 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700608 return false;
609 }
610
Dave Hawkeya8881582013-09-17 15:55:33 -0600611 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500612 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600613 * {@link #addToCustomContentPage}. This will only be invoked if
614 * {@link #hasCustomContentToLeft()} is {@code true}.
615 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500616 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700617 if (mLauncherCallbacks != null) {
618 mLauncherCallbacks.populateCustomContentContainer();
619 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600620 }
621
622 /**
623 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
624 * ensure the custom content page is added or removed if necessary.
625 */
626 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600627 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600628 // Not bound yet, wait for bindScreens to be called.
629 return;
630 }
631
632 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
633 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500634 mWorkspace.createCustomContentContainer();
635 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600636 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
637 mWorkspace.removeCustomContentPage();
638 }
639 }
640
Anton Hanssona2f665f2013-09-26 12:18:32 +0100641 public Stats getStats() {
642 return mStats;
643 }
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800644
645 /**
646 * Logger object is a singleton and does not have to be coupled with the foreground activity.
647 * Since most user event logging is done on the UI, the object is retrieved from the
648 * callback for convenience.
649 */
650 private void initLogger() {
651 if (mLauncherCallbacks != null) {
652 mUserEventLogger = mLauncherCallbacks.getLogger();
653 }
654 if (mUserEventLogger == null) {
655 mUserEventLogger = new UserEventLogger() {
656 @Override
657 public void processEvent(LauncherLogProto.LauncherEvent ev) {
658 if (ev.action.touch == LauncherLogProto.Action.TAP && ev.srcTarget.itemType == LauncherLogProto.APP_ICON) {
659 Log.d(TAG, String.format(Locale.US, "action:%s target:%s\n\telapsed container %d ms session %d ms",
660 LoggerUtils.getActionStr(ev.action),
661 LoggerUtils.getTargetStr(ev.srcTarget),
662 ev.elapsedContainerMillis,
663 ev.elapsedSessionMillis));
664 }
665 }
666 };
667 }
668 }
669
670 public UserEventLogger getLogger() {
671 return mUserEventLogger;
672 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100673
Hyunyoung Song3f471442015-04-08 19:01:34 -0700674 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700675 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
676 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700677 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700678 }
679
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000680 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700681 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
682 // This cast is safe as long as the id < 0x00FFFFFF
683 // Since we jail all the dynamically generated views, there should be no clashes
684 // with any other views.
685 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000686 }
687
688 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700689 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
690 * a configuration step, this allows the proper animations to run after other transitions.
691 */
Adam Cohendb364c32014-05-20 14:23:40 -0700692 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700693 long screenId = args.screenId;
694 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
695 // When the screen id represents an actual screen (as opposed to a rank) we make sure
696 // that the drop page actually exists.
697 screenId = ensurePendingDropLayoutExists(args.screenId);
698 }
Adam Cohendb364c32014-05-20 14:23:40 -0700699
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800700 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800701 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700702 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700703 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700704 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800705 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700706 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700707 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700708 case REQUEST_RECONFIGURE_APPWIDGET:
709 completeRestoreAppWidget(args.appWidgetId);
710 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800711 }
Michael Jurka27614d22012-04-02 06:40:22 -0700712 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
713 // if you turned the screen off and then back while in All Apps, Launcher would not
714 // return to the workspace. Clearing mAddInfo.container here fixes this issue
715 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700716 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800717 }
718
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800719 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700720 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700721 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700722 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700723 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800724 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700725
Adam Cohenad4e15c2013-10-17 16:21:35 -0700726 Runnable exitSpringLoaded = new Runnable() {
727 @Override
728 public void run() {
729 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
730 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
731 }
732 };
733
Michael Jurka8b805b12012-04-18 14:23:14 -0700734 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700735 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700736 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700737 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
738 if (resultCode == RESULT_CANCELED) {
739 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700740 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700741 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700742 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800743 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700744 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700745
746 // When the user has granted permission to bind widgets, we should check to see if
747 // we can inflate the default search bar widget.
748 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700749 }
750 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200751 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
752 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700753 // User could have free-scrolled between pages before picking a wallpaper; make sure
754 // we move to the closest one now.
755 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700756 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200757 }
758 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700759 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200760
Adam Cohened66b2b2012-01-23 17:28:51 -0800761 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700762 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700763
Adam Cohendb364c32014-05-20 14:23:40 -0700764 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800765 // We have special handling for widgets
766 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800767 final int appWidgetId;
768 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
769 : -1;
770 if (widgetId < 0) {
771 appWidgetId = pendingAddWidgetId;
772 } else {
773 appWidgetId = widgetId;
774 }
775
Adam Cohenad4e15c2013-10-17 16:21:35 -0700776 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800777 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700778 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
779 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 result = RESULT_CANCELED;
781 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700782 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700783 @Override
784 public void run() {
785 exitSpringLoadedDragModeDelayed(false, 0, null);
786 }
787 };
Adam Cohendb364c32014-05-20 14:23:40 -0700788 if (workspaceLocked) {
789 // No need to remove the empty screen if we're mid-binding, as the
790 // the bind will not add the empty screen.
791 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
792 } else {
793 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
794 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
795 }
Winson Chung5aaab772012-04-27 15:24:02 -0700796 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700797 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700798 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
799 // When the screen id represents an actual screen (as opposed to a rank)
800 // we make sure that the drop page actually exists.
801 mPendingAddInfo.screenId =
802 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
803 }
Adam Cohendb364c32014-05-20 14:23:40 -0700804 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
805
806 dropLayout.setDropPending(true);
807 final Runnable onComplete = new Runnable() {
808 @Override
809 public void run() {
810 completeTwoStageWidgetDrop(resultCode, appWidgetId);
811 dropLayout.setDropPending(false);
812 }
813 };
814 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
815 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
816 } else {
817 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
818 mPendingAddInfo);
819 sPendingAddItem = args;
820 }
Winson Chung5aaab772012-04-27 15:24:02 -0700821 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800822 return;
823 }
824
Sunny Goyalff572272014-07-23 13:58:07 -0700825 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
826 if (resultCode == RESULT_OK) {
827 // Update the widget view.
828 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
829 pendingAddWidgetId, mPendingAddInfo);
830 if (workspaceLocked) {
831 sPendingAddItem = args;
832 } else {
833 completeAdd(args);
834 }
835 }
836 // Leave the widget in the pending state if the user canceled the configure.
837 return;
838 }
839
Sunny Goyalaad90582015-07-09 14:22:50 -0700840 if (requestCode == REQUEST_CREATE_SHORTCUT) {
841 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
842 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
843 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
844 mPendingAddInfo);
845 if (isWorkspaceLocked()) {
846 sPendingAddItem = args;
847 } else {
848 completeAdd(args);
849 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
850 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
851 }
852 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700853 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
854 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800857 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800858
859 }
860
861 @Override
862 protected void onActivityResult(
863 final int requestCode, final int resultCode, final Intent data) {
864 handleActivityResult(requestCode, resultCode, data);
865 if (mLauncherCallbacks != null) {
866 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
867 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800868 }
869
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600870 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700871 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600872 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700873 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
874 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
875 View v = null;
876 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
877 if (layout != null) {
878 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
879 }
880 Intent intent = sPendingAddItem.intent;
881 sPendingAddItem = null;
882 if (grantResults.length > 0
883 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
884 startActivity(v, intent, null);
885 } else {
886 // TODO: Show a snack bar with link to settings
887 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
888 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
889 }
890 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600891 if (mLauncherCallbacks != null) {
892 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
893 grantResults);
894 }
895 }
896
Adam Cohendb364c32014-05-20 14:23:40 -0700897 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
898 appWidgetId, ItemInfo info) {
899 PendingAddArguments args = new PendingAddArguments();
900 args.requestCode = requestCode;
901 args.intent = data;
902 args.container = info.container;
903 args.screenId = info.screenId;
904 args.cellX = info.cellX;
905 args.cellY = info.cellY;
906 args.appWidgetId = appWidgetId;
907 return args;
908 }
909
910 /**
911 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
912 *
913 * @param screenId the screen id to check
914 * @return the new screen, or screenId if it exists
915 */
916 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800917 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700918 if (dropLayout == null) {
919 // it's possible that the add screen was removed because it was
920 // empty and a re-bind occurred
921 mWorkspace.addExtraEmptyScreen();
922 return mWorkspace.commitExtraEmptyScreen();
923 } else {
924 return screenId;
925 }
926 }
927
Adam Cohen091440a2015-03-18 14:16:05 -0700928 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800929 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 Runnable onCompleteRunnable = null;
931 int animationType = 0;
932
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700933 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800934 if (resultCode == RESULT_OK) {
935 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
936 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700937 mPendingAddWidgetInfo);
938 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800939 onCompleteRunnable = new Runnable() {
940 @Override
941 public void run() {
942 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700943 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700944 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
945 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800946 }
947 };
948 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800949 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800950 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800951 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700952 if (mDragLayer.getAnimatedView() != null) {
953 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
954 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
955 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700956 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700957 // The animated view may be null in the case of a rotation during widget configuration
958 onCompleteRunnable.run();
959 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 }
961
962 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700963 protected void onStop() {
964 super.onStop();
965 FirstFrameAnimatorHelper.setIsVisible(false);
Sunny Goyal23ac9cb2016-04-07 12:14:37 -0700966 if (Utilities.isNycOrAbove()) {
967 mAppWidgetHost.stopListening();
968 }
Adam Cohen9211d422014-10-07 18:14:53 -0700969
970 if (mLauncherCallbacks != null) {
971 mLauncherCallbacks.onStop();
972 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700973 }
974
975 @Override
976 protected void onStart() {
977 super.onStart();
978 FirstFrameAnimatorHelper.setIsVisible(true);
Sunny Goyal23ac9cb2016-04-07 12:14:37 -0700979 if (Utilities.isNycOrAbove()) {
980 mAppWidgetHost.startListening();
981 }
Adam Cohen9211d422014-10-07 18:14:53 -0700982
983 if (mLauncherCallbacks != null) {
984 mLauncherCallbacks.onStart();
985 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700986 }
987
988 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200990 long startTime = 0;
991 if (DEBUG_RESUME_TIME) {
992 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400993 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200994 }
Adam Cohen9211d422014-10-07 18:14:53 -0700995
996 if (mLauncherCallbacks != null) {
997 mLauncherCallbacks.preOnResume();
998 }
999
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001000 super.onResume();
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -08001001 mUserEventLogger.resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001002
Winson Chung4a2afa32012-07-19 14:53:05 -07001003 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001004 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001005 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001006 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001007 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001008 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001009 // view after launching an app, as they may be depending on the UI to be static to
1010 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001011 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07001012 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08001013 } else if (mOnResumeState == State.WIDGETS) {
1014 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001015 }
1016 mOnResumeState = State.NONE;
1017
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001018 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001019 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1020 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001021
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001022 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001023 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001024 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -07001025 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onorato9c1289c2009-08-17 11:03:03 -04001026 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001027 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001029 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001030 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1031 // execute them here
1032 long startTimeCallbacks = 0;
1033 if (DEBUG_RESUME_TIME) {
1034 startTimeCallbacks = System.currentTimeMillis();
1035 }
1036
Michael Jurka1e2f4652013-07-08 18:03:46 -07001037 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1038 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001039 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001040 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001041 if (DEBUG_RESUME_TIME) {
1042 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1043 (System.currentTimeMillis() - startTimeCallbacks));
1044 }
Michael Jurka447bf842013-05-15 14:52:15 +02001045 }
Michael Jurka54554252013-08-01 12:52:23 +02001046 if (mOnResumeCallbacks.size() > 0) {
1047 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1048 mOnResumeCallbacks.get(i).run();
1049 }
1050 mOnResumeCallbacks.clear();
1051 }
Winson Chunge4e50662012-01-23 14:45:13 -08001052
1053 // Reset the pressed state of icons that were locked in the press state while activities
1054 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001055 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001056 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001057 mWaitingForResume.setStayPressed(false);
1058 }
Winson Chung82963d52013-10-09 11:20:57 -07001059
Adam Cohen06dff352012-06-01 17:17:08 -07001060 // It is possible that widgets can receive updates while launcher is not in the foreground.
1061 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1062 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1063 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001064 if (!isWorkspaceLoading()) {
1065 getWorkspace().reinflateWidgetsIfNecessary();
1066 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001067 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001068
Michael Jurka447bf842013-05-15 14:52:15 +02001069 if (DEBUG_RESUME_TIME) {
1070 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1071 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001072
Adam Cohen4b66bf32015-09-18 12:15:19 -07001073 // We want to suppress callbacks about CustomContent being shown if we have just received
1074 // onNewIntent while the user was present within launcher. In that case, we post a call
1075 // to move the user to the main screen (which will occur after onResume). We don't want to
1076 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1077 // suppress here.
1078 if (mWorkspace.getCustomContentCallbacks() != null
1079 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001080 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001081 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001082 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1083 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001084 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001085 }
1086 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001087 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001088 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001089 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001090
Sunny Goyal756adbc2015-04-16 15:20:51 -07001091 if (!isWorkspaceLoading()) {
1092 // Process any items that were added while Launcher was away.
1093 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1094 }
Adam Cohen9211d422014-10-07 18:14:53 -07001095
1096 if (mLauncherCallbacks != null) {
1097 mLauncherCallbacks.onResume();
1098 }
Adam Cohen06dff352012-06-01 17:17:08 -07001099 }
1100
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001102 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001103 // Ensure that items added to Launcher are queued until Launcher returns
1104 InstallShortcutReceiver.enableInstallQueue();
1105
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001106 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001107 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001108 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001109 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001110
1111 // We call onHide() aggressively. The custom content callbacks should be able to
1112 // debounce excess onHide calls.
1113 if (mWorkspace.getCustomContentCallbacks() != null) {
1114 mWorkspace.getCustomContentCallbacks().onHide();
1115 }
Romain Guycbb89e42009-06-08 15:52:54 -07001116
Adam Cohen9211d422014-10-07 18:14:53 -07001117 if (mLauncherCallbacks != null) {
1118 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001119 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001120 }
1121
1122 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001123 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1124 // by a onResume or by scrolling otherwise.
1125 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001126
1127 // Custom content is completely hidden
1128 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001129
1130 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1131 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001132
1133 // Indicates whether the user is allowed to scroll away from the custom content.
1134 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001135 }
1136
Adam Cohenc2d6e892014-10-16 09:49:24 -07001137 public interface LauncherOverlay {
1138
1139 /**
1140 * Touch interaction leading to overscroll has begun
1141 */
1142 public void onScrollInteractionBegin();
1143
1144 /**
1145 * Touch interaction related to overscroll has ended
1146 */
1147 public void onScrollInteractionEnd();
1148
1149 /**
1150 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1151 * screen (or in the case of RTL, the rightmost screen).
1152 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001153 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001154
1155 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001156 * Called when the launcher is ready to use the overlay
1157 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001158 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001159 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001160 }
1161
Jun Mukai8af0cd82015-05-12 12:32:12 -07001162 public interface LauncherSearchCallbacks {
1163 /**
1164 * Called when the search overlay is shown.
1165 */
1166 public void onSearchOverlayOpened();
1167
1168 /**
1169 * Called when the search overlay is dismissed.
1170 */
1171 public void onSearchOverlayClosed();
1172 }
1173
Adam Cohenc2d6e892014-10-16 09:49:24 -07001174 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001175 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001176 }
1177
1178 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1179
Sunny Goyalc86df472016-02-25 09:19:38 -08001180 public void onScrollChanged(float progress) {
1181 if (mWorkspace != null) {
1182 mWorkspace.onOverlayScrollChanged(progress);
1183 }
1184 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001185 }
1186
Jorim Jaggid017f882014-01-14 17:08:48 -08001187 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001188 if (mLauncherCallbacks != null) {
1189 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001190 } else {
1191 // On devices with a locked orientation, we will at least have the allow rotation
1192 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001193 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001194 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001195 }
1196
Adam Cohen9211d422014-10-07 18:14:53 -07001197 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001198 CustomContentCallbacks callbacks, String description) {
1199 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001200 }
1201
Adam Cohenedb40762013-07-18 16:45:45 -07001202 // The custom content needs to offset its content to account for the QSB
1203 public int getTopOffsetForCustomContent() {
1204 return mWorkspace.getPaddingTop();
1205 }
1206
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001207 @Override
1208 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001209 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001210 if (mModel.isCurrentCallbacks(this)) {
1211 mModel.stopLoader();
1212 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001213 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1214
Romain Guy13c2e7b2010-03-10 19:45:00 -08001215 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001216 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001217
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001218 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001219 @Override
1220 public void onWindowFocusChanged(boolean hasFocus) {
1221 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001222 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001223
1224 if (mLauncherCallbacks != null) {
1225 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1226 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001227 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001228
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 private boolean acceptFilter() {
1230 final InputMethodManager inputManager = (InputMethodManager)
1231 getSystemService(Context.INPUT_METHOD_SERVICE);
1232 return !inputManager.isFullscreenMode();
1233 }
1234
1235 @Override
1236 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001237 final int uniChar = event.getUnicodeChar();
1238 final boolean handled = super.onKeyDown(keyCode, event);
1239 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1240 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1242 keyCode, event);
1243 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001244 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001245 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001246 // showSearchDialog()
1247 // If there are multiple keystrokes before the search dialog takes focus,
1248 // onSearchRequested() will be called for every keystroke,
1249 // but it is idempotent, so it's fine.
1250 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252 }
1253
Joe Onorato8a9625e2010-01-28 15:55:35 -08001254 // Eat the long press event so the keyboard doesn't come up.
1255 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1256 return true;
1257 }
1258
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 return handled;
1260 }
1261
Winson46163472015-09-22 17:31:56 -07001262 @Override
1263 public boolean onKeyUp(int keyCode, KeyEvent event) {
1264 if (keyCode == KeyEvent.KEYCODE_MENU) {
1265 // Ignore the menu key if we are currently dragging or are on the custom content screen
1266 if (!isOnCustomContent() && !mDragController.isDragging()) {
1267 // Close any open folders
1268 closeFolder();
1269
1270 // Stop resizing any widgets
1271 mWorkspace.exitWidgetResizeMode();
1272
1273 // Show the overview mode if we are on the workspace
1274 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1275 !mWorkspace.isSwitchingState()) {
1276 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001277 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001278 }
1279 }
1280 return true;
1281 }
1282 return super.onKeyUp(keyCode, event);
1283 }
1284
Karl Rosaen138a0412009-04-23 19:00:21 -07001285 private String getTypedText() {
1286 return mDefaultKeySsb.toString();
1287 }
1288
1289 private void clearTypedText() {
1290 mDefaultKeySsb.clear();
1291 mDefaultKeySsb.clearSpans();
1292 Selection.setSelection(mDefaultKeySsb, 0);
1293 }
1294
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001295 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001296 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1297 * State
1298 */
1299 private static State intToState(int stateOrdinal) {
1300 State state = State.WORKSPACE;
1301 final State[] stateValues = State.values();
1302 for (int i = 0; i < stateValues.length; i++) {
1303 if (stateValues[i].ordinal() == stateOrdinal) {
1304 state = stateValues[i];
1305 break;
1306 }
1307 }
1308 return state;
1309 }
1310
1311 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312 * Restores the previous state, if it exists.
1313 *
1314 * @param savedState The previous state.
1315 */
1316 private void restoreState(Bundle savedState) {
1317 if (savedState == null) {
1318 return;
1319 }
1320
Michael Jurka883f55b2010-10-21 15:47:14 -07001321 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001322 if (state == State.APPS || state == State.WIDGETS) {
1323 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001324 }
1325
Adam Cohen21cd0022013-10-09 18:57:02 -07001326 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1327 PagedView.INVALID_RESTORE_PAGE);
1328 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001329 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330 }
1331
Sunny Goyal756cd262015-08-20 12:33:21 -07001332 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1333 if (itemValues != null) {
1334 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001335 AppWidgetProviderInfo info = savedState.getParcelable(
1336 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001337 mPendingAddWidgetInfo = info == null ?
1338 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1339
Adam Cohen4637b5a2013-11-04 18:21:24 -08001340 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001341 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001342 mRestoring = true;
1343 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 }
1345
1346 /**
1347 * Finds all the views we need and configure them properly.
1348 */
1349 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001350 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001351
Craig Mautner360310b2012-10-26 15:13:08 -07001352 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001353 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001354 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1355 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001356 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001357 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001358
Sunny Goyal784f9c32016-03-23 16:56:54 -07001359 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1360 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1361 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
Craig Mautner360310b2012-10-26 15:13:08 -07001362 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363
Winson Chung4c98d922011-05-31 16:50:48 -07001364 // Setup the drag layer
1365 mDragLayer.setup(this, dragController);
1366
Winson Chung3d503fb2011-07-13 17:25:49 -07001367 // Setup the hotseat
1368 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1369 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001370 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001371 }
1372
Winsone9f27272015-10-13 10:47:51 -07001373 // Setup the overview panel
1374 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001375
Winson Chung4c98d922011-05-31 16:50:48 -07001376 // Setup the workspace
1377 mWorkspace.setHapticFeedbackEnabled(false);
1378 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001379 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001380 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001381
Tony Wickham34d2c912015-09-11 09:27:58 -07001382 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001383 mSearchDropTargetBar = (SearchDropTargetBar)
1384 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001385 // Get the app info bar
1386 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1387 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001388
Winson Chungef7f8742015-06-04 17:18:17 -07001389 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001390 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001391 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001392 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1393 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1394 } else {
1395 mAppsView.setSearchBarController(new DefaultAppSearchController());
1396 }
Craig Mautner360310b2012-10-26 15:13:08 -07001397
Winson Chung3d503fb2011-07-13 17:25:49 -07001398 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001399 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001400 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001401 dragController.setMoveTarget(mWorkspace);
1402 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001403 if (mSearchDropTargetBar != null) {
1404 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001405 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001406 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001407 if (mAppInfoDropTargetBar != null) {
1408 mAppInfoDropTargetBar.setup(this, dragController);
1409 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001410
Sunny Goyal322d5562015-06-25 19:35:49 -07001411 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1412 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001413 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 }
1415
Winsone9f27272015-10-13 10:47:51 -07001416 private void setupOverviewPanel() {
1417 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1418
1419 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1420 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1421 @Override
1422 public boolean onLongClick(View v) {
1423 return v.performClick();
1424 }
1425 };
1426
1427 // Bind wallpaper button actions
1428 View wallpaperButton = findViewById(R.id.wallpaper_button);
1429 wallpaperButton.setOnClickListener(new OnClickListener() {
1430 @Override
1431 public void onClick(View view) {
1432 if (!mWorkspace.isSwitchingState()) {
1433 onClickWallpaperPicker(view);
1434 }
1435 }
1436 });
1437 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1438 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1439
1440 // Bind widget button actions
1441 mWidgetsButton = findViewById(R.id.widget_button);
1442 mWidgetsButton.setOnClickListener(new OnClickListener() {
1443 @Override
1444 public void onClick(View view) {
1445 if (!mWorkspace.isSwitchingState()) {
1446 onClickAddWidgetButton(view);
1447 }
1448 }
1449 });
1450 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1451 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1452
1453 // Bind settings actions
1454 View settingsButton = findViewById(R.id.settings_button);
1455 boolean hasSettings = hasSettings();
1456 if (hasSettings) {
1457 settingsButton.setOnClickListener(new OnClickListener() {
1458 @Override
1459 public void onClick(View view) {
1460 if (!mWorkspace.isSwitchingState()) {
1461 onClickSettingsButton(view);
1462 }
1463 }
1464 });
1465 settingsButton.setOnLongClickListener(performClickOnLongClick);
1466 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1467 } else {
1468 settingsButton.setVisibility(View.GONE);
1469 }
1470
1471 mOverviewPanel.setAlpha(0f);
1472 }
1473
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001475 * Sets the all apps button. This method is called from {@link Hotseat}.
1476 */
1477 public void setAllAppsButton(View allAppsButton) {
1478 mAllAppsButton = allAppsButton;
1479 }
1480
1481 public View getAllAppsButton() {
1482 return mAllAppsButton;
1483 }
1484
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001485 public View getWidgetsButton() {
1486 return mWidgetsButton;
1487 }
1488
Anjali Koppal5ad44842014-03-10 20:34:39 -07001489 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490 * Creates a view representing a shortcut.
1491 *
1492 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001494 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001495 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 }
1497
1498 /**
1499 * Creates a view representing a shortcut inflated from the specified resource.
1500 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 * @param parent The group the shortcut belongs to.
1502 * @param info The data structure describing the shortcut.
1503 *
1504 * @return A View inflated from layoutResId.
1505 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001506 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001507 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001508 parent, false);
1509 favorite.applyFromShortcutInfo(info, mIconCache);
1510 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001512 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 return favorite;
1514 }
1515
1516 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 * Add a shortcut to the workspace.
1518 *
1519 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001521 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001522 int cellY) {
1523 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001524 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001525
Sunny Goyal5c97f512015-05-19 16:03:28 -07001526 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001527 if (info == null) {
1528 return;
1529 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001530 final View view = createShortcut(info);
1531
Sunny Goyal5c97f512015-05-19 16:03:28 -07001532 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001533 // First we check if we already know the exact location where we want to add this item.
1534 if (cellX >= 0 && cellY >= 0) {
1535 cellXY[0] = cellX;
1536 cellXY[1] = cellY;
1537 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001538
1539 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001540 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001541 true, null,null)) {
1542 return;
1543 }
1544 DragObject dragObject = new DragObject();
1545 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001546 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1547 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001548 return;
1549 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001550 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001551 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001552 }
1553
1554 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001555 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001556 return;
1557 }
1558
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001559 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
1561 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001562 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001563 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564 }
1565 }
1566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001568 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001570 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 */
Adam Cohen091440a2015-03-18 14:16:05 -07001572 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001573 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1574
1575 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001576 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001577 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001578 }
Romain Guycbb89e42009-06-08 15:52:54 -07001579
Adam Cohen59400422014-03-05 18:07:04 -08001580 if (appWidgetInfo.isCustomWidget) {
1581 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001582 }
1583
Adam Cohen59400422014-03-05 18:07:04 -08001584 LauncherAppWidgetInfo launcherInfo;
1585 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1586 launcherInfo.spanX = info.spanX;
1587 launcherInfo.spanY = info.spanY;
1588 launcherInfo.minSpanX = info.minSpanX;
1589 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001590 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001591
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001593 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594
1595 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001596 if (hostView == null) {
1597 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001598 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1599 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001600 } else {
1601 // The AppWidgetHostView has already been inflated and instantiated
1602 launcherInfo.hostView = hostView;
1603 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001604 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001605 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001607 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 }
Romain Guycbb89e42009-06-08 15:52:54 -07001609
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001610 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1611 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1612 item.hostView.setTag(item);
1613 item.onBindAppWidget(this);
1614
1615 item.hostView.setFocusable(true);
1616 item.hostView.setOnFocusChangeListener(mFocusHandler);
1617
1618 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1619 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1620
1621 if (!item.isCustomWidget()) {
1622 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1623 }
1624 }
1625
Adam Cohended9f8d2010-11-03 13:25:16 -07001626 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1627 @Override
1628 public void onReceive(Context context, Intent intent) {
1629 final String action = intent.getAction();
1630 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1631 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001632 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001633 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001634
Winson Chungc100e8e2011-08-09 16:02:43 -07001635 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001636 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001637 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001638 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001639 if (!showWorkspace(false)) {
1640 // If we are already on the workspace, then manually reset all apps
1641 mAppsView.reset();
1642 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001643 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001644 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1645 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001646 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001647 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1648 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001649 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001650 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1651 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1652 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001653 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001654 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1655 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001656 }
1657 }
1658 };
1659
1660 @Override
1661 public void onAttachedToWindow() {
1662 super.onAttachedToWindow();
1663
1664 // Listen for broadcasts related to user-presence
1665 final IntentFilter filter = new IntentFilter();
1666 filter.addAction(Intent.ACTION_SCREEN_OFF);
1667 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001668 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001669 if (ENABLE_DEBUG_INTENTS) {
1670 filter.addAction(DebugIntents.DELETE_DATABASE);
1671 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1672 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001673 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001674 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001675 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001676 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001677
1678 if (mLauncherCallbacks != null) {
1679 mLauncherCallbacks.onAttachedToWindow();
1680 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001681 }
1682
1683 @Override
1684 public void onDetachedFromWindow() {
1685 super.onDetachedFromWindow();
1686 mVisible = false;
1687
Adam Cohend113e0c2010-11-11 10:48:05 -08001688 if (mAttached) {
1689 unregisterReceiver(mReceiver);
1690 mAttached = false;
1691 }
Winson Chungb745afb2015-03-02 11:51:23 -08001692 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001693
1694 if (mLauncherCallbacks != null) {
1695 mLauncherCallbacks.onDetachedFromWindow();
1696 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001697 }
1698
1699 public void onWindowVisibilityChanged(int visibility) {
1700 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001701 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001702 // The following code used to be in onResume, but it turns out onResume is called when
1703 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1704 // is a more appropriate event to handle
1705 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001706 if (!mWorkspaceLoading) {
1707 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001708 // We want to let Launcher draw itself at least once before we force it to build
1709 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001710 // apps is nice and speedy.
1711 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001712 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001713 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001714 if (mStarted) return;
1715 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001716 // We delay the layer building a bit in order to give
1717 // other message processing a time to run. In particular
1718 // this avoids a delay in hiding the IME if it was
1719 // currently shown, because doing that may involve
1720 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001721 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001722 final ViewTreeObserver.OnDrawListener listener = this;
1723 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001724 public void run() {
1725 if (mWorkspace != null &&
1726 mWorkspace.getViewTreeObserver() != null) {
1727 mWorkspace.getViewTreeObserver().
1728 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001729 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001730 }
1731 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001732 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001733 }
1734 });
1735 }
1736 clearTypedText();
1737 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001738 }
1739
Adam Cohen091440a2015-03-18 14:16:05 -07001740 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001741 mHandler.removeMessages(ADVANCE_MSG);
1742 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1743 mHandler.sendMessageDelayed(msg, delay);
1744 mAutoAdvanceSentTime = System.currentTimeMillis();
1745 }
1746
Adam Cohen091440a2015-03-18 14:16:05 -07001747 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001748 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1749 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1750 mAutoAdvanceRunning = autoAdvanceRunning;
1751 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001752 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001753 sendAdvanceMessage(delay);
1754 } else {
1755 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001756 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001757 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1758 }
1759 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001760 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 }
1762 }
1763 }
1764
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001765 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1766
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001768 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001769 if (msg.what == ADVANCE_MSG) {
1770 int i = 0;
1771 for (View key: mWidgetsToAdvance.keySet()) {
1772 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001773 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001774 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001775 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001776 public void run() {
1777 ((Advanceable) v).advance();
1778 }
1779 }, delay);
1780 }
1781 i++;
1782 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001783 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001784 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001785 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001787 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001788
Winsonc0b52fe2015-09-09 16:38:15 -07001789 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001790 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001791 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1792 if (v instanceof Advanceable) {
1793 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001794 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001795 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001796 }
1797 }
1798
Winsonc0b52fe2015-09-09 16:38:15 -07001799 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001800 if (mWidgetsToAdvance.containsKey(hostView)) {
1801 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001802 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001803 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001804 }
1805
Hyunyoung Song3f471442015-04-08 19:01:34 -07001806 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001807 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1808 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001809 }
1810
Winson Chunga6945242014-01-08 14:04:34 -08001811 public DragLayer getDragLayer() {
1812 return mDragLayer;
1813 }
1814
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001815 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001816 return mAppsView;
1817 }
1818
Hyunyoung Song3f471442015-04-08 19:01:34 -07001819 public WidgetsContainerView getWidgetsView() {
1820 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001821 }
1822
Winson Chunga6945242014-01-08 14:04:34 -08001823 public Workspace getWorkspace() {
1824 return mWorkspace;
1825 }
1826
1827 public Hotseat getHotseat() {
1828 return mHotseat;
1829 }
1830
Jorim Jaggid017f882014-01-14 17:08:48 -08001831 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001832 return mOverviewPanel;
1833 }
1834
Winson Chung006ee262015-08-03 14:40:11 -07001835 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001836 return mSearchDropTargetBar;
1837 }
1838
Tony Wickham34d2c912015-09-11 09:27:58 -07001839 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1840 return mAppInfoDropTargetBar;
1841 }
1842
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001843 public LauncherAppWidgetHost getAppWidgetHost() {
1844 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
Romain Guycbb89e42009-06-08 15:52:54 -07001846
Winson Chunga9abd0e2010-10-27 17:18:37 -07001847 public LauncherModel getModel() {
1848 return mModel;
1849 }
1850
Winson Chunga6945242014-01-08 14:04:34 -08001851 protected SharedPreferences getSharedPrefs() {
1852 return mSharedPrefs;
1853 }
1854
Adam Cohen2e6da152015-05-06 11:42:25 -07001855 public DeviceProfile getDeviceProfile() {
1856 return mDeviceProfile;
1857 }
1858
Bjorn Bringertc459e522013-06-07 19:36:01 +01001859 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001860 getWindow().closeAllPanels();
1861
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001862 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001863 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001864 }
1865
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001866 @Override
1867 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001868 long startTime = 0;
1869 if (DEBUG_RESUME_TIME) {
1870 startTime = System.currentTimeMillis();
1871 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 super.onNewIntent(intent);
1873
1874 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001875 Folder openFolder = mWorkspace.getOpenFolder();
1876 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1877 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1878 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1879 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1880 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001881 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001882 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001883
Adam Cohen6fecd412013-10-02 17:41:50 -07001884 if (mWorkspace == null) {
1885 // Can be cases where mWorkspace is null, this prevents a NPE
1886 return;
1887 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001888 // In all these cases, only animate if we're already on home
1889 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001890
Sunny Goyal935fca12015-10-13 10:19:01 -07001891 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001892 exitSpringLoadedDragMode();
1893
1894 // If we are already on home, then just animate back to the workspace,
1895 // otherwise, just wait until onResume to set the state back to Workspace
1896 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001897 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001898 } else {
1899 mOnResumeState = State.WORKSPACE;
1900 }
1901
1902 final View v = getWindow().peekDecorView();
1903 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001904 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001905 INPUT_METHOD_SERVICE);
1906 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1907 }
1908
Winson Chungb745afb2015-03-02 11:51:23 -08001909 // Reset the apps view
1910 if (!alreadyOnHome && mAppsView != null) {
1911 mAppsView.scrollToTop();
1912 }
1913
Hyunyoung Song3f471442015-04-08 19:01:34 -07001914 // Reset the widgets view
1915 if (!alreadyOnHome && mWidgetsView != null) {
1916 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001917 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001918
Adam Cohen9211d422014-10-07 18:14:53 -07001919 if (mLauncherCallbacks != null) {
1920 mLauncherCallbacks.onHomeIntent();
1921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 }
Adam Cohened307df2013-10-02 09:37:31 -07001923
Adam Cohen9211d422014-10-07 18:14:53 -07001924 if (mLauncherCallbacks != null) {
1925 mLauncherCallbacks.onNewIntent(intent);
1926 }
Winson15f8b172015-08-19 11:02:39 -07001927
1928 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1929 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1930 // animation.
1931 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001932 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1933 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001934 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1935 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001936
1937 // We use this flag to suppress noisy callbacks above custom content state
1938 // from onResume.
1939 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001940 mWorkspace.post(new Runnable() {
1941 @Override
1942 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001943 if (mWorkspace != null) {
1944 mWorkspace.moveToDefaultScreen(true);
1945 }
Winson15f8b172015-08-19 11:02:39 -07001946 }
1947 });
1948 }
1949 }
1950
1951 if (DEBUG_RESUME_TIME) {
1952 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1953 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001954 }
1955
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001957 public void onRestoreInstanceState(Bundle state) {
1958 super.onRestoreInstanceState(state);
1959 for (int page: mSynchronouslyBoundPages) {
1960 mWorkspace.restoreInstanceStateForChild(page);
1961 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
1963
1964 @Override
1965 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001966 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001967 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1968 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001969 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001970 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971
Michael Jurka883f55b2010-10-21 15:47:14 -07001972 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001973 // We close any open folder since it will not be re-opened, and we need to make sure
1974 // this state is reflected.
1975 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1976 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977
Adam Cohendcd297f2013-06-18 13:13:40 -07001978 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001979 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001980 ContentValues itemValues = new ContentValues();
1981 mPendingAddInfo.writeToValues(itemValues);
1982 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001983 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001984 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001985 }
1986
Hyunyoung Song3f471442015-04-08 19:01:34 -07001987 // Save the current widgets tray?
1988 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001989
1990 if (mLauncherCallbacks != null) {
1991 mLauncherCallbacks.onSaveInstanceState(outState);
1992 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 }
1994
1995 @Override
1996 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001998
Winson Chunge7a03942011-08-05 15:05:12 -07001999 // Remove all pending runnables
2000 mHandler.removeMessages(ADVANCE_MSG);
2001 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002002 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002003
Winson Chungcd2b0142011-06-08 16:02:26 -07002004 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07002005 // It's possible to receive onDestroy after a new Launcher activity has
2006 // been created. In this case, don't interfere with the new Launcher.
2007 if (mModel.isCurrentCallbacks(this)) {
2008 mModel.stopLoader();
Sunny Goyald365ed62016-02-12 09:44:03 -08002009 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07002010 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002013 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002015 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002016 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002017 mAppWidgetHost = null;
2018
2019 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020
2021 TextKeyListener.getInstance().release();
2022
Tony Wickhame2217252016-03-22 16:34:23 -07002023 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
2024 .removeAccessibilityStateChangeListener(this);
2025
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002026 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002027
Michael Jurka2ecf9952012-06-18 12:52:28 -07002028 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002029
2030 if (mLauncherCallbacks != null) {
2031 mLauncherCallbacks.onDestroy();
2032 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 }
2034
Adam Cohena9cf38f2011-05-02 15:36:58 -07002035 public DragController getDragController() {
2036 return mDragController;
2037 }
2038
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 @Override
2040 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002041 onStartForResult(requestCode);
2042 super.startActivityForResult(intent, requestCode);
2043 }
2044
2045 @Override
2046 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2047 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2048 onStartForResult(requestCode);
2049 try {
2050 super.startIntentSenderForResult(intent, requestCode,
2051 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2052 } catch (IntentSender.SendIntentException e) {
2053 throw new ActivityNotFoundException();
2054 }
2055 }
2056
2057 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002058 if (requestCode >= 0) {
2059 setWaitingForResult(true);
2060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 }
2062
Winson Chung70d72102011-08-12 11:24:35 -07002063 /**
2064 * Indicates that we want global search for this activity by setting the globalSearch
2065 * argument for {@link #startSearch} to true.
2066 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002068 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002070
Karl Rosaen138a0412009-04-23 19:00:21 -07002071 if (initialQuery == null) {
2072 // Use any text typed in the launcher as the initial query
2073 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002074 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 if (appSearchData == null) {
2076 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002077 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002078 }
Winson Chungadf0c182012-08-23 14:59:07 -07002079 Rect sourceBounds = new Rect();
2080 if (mSearchDropTargetBar != null) {
2081 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2082 }
Romain Guycbb89e42009-06-08 15:52:54 -07002083
Ian Parkinson047036e2014-09-01 15:40:53 +01002084 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002085 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002086 if (clearTextImmediately) {
2087 clearTypedText();
2088 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002089
2090 // We need to show the workspace after starting the search
2091 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002092 }
2093
Ian Parkinson047036e2014-09-01 15:40:53 +01002094 /**
2095 * Start a text search.
2096 *
2097 * @return {@code true} if the search will start immediately, so any further keypresses
2098 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2099 * to buffer keypresses.
2100 */
2101 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002102 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002103 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2104 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2105 sourceBounds);
2106 }
2107
Michael Jurkaa33411c2012-06-14 16:18:21 -07002108 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002109 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002110 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002111 }
2112
2113 /**
2114 * Starts the global search activity. This code is a copied from SearchManager
2115 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002116 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002117 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002118 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002119 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2120 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2121 if (globalSearchActivity == null) {
2122 Log.w(TAG, "No global search activity found.");
2123 return;
2124 }
2125 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2127 intent.setComponent(globalSearchActivity);
2128 // Make sure that we have a Bundle to put source in
2129 if (appSearchData == null) {
2130 appSearchData = new Bundle();
2131 } else {
2132 appSearchData = new Bundle(appSearchData);
2133 }
Adam Cohen9211d422014-10-07 18:14:53 -07002134 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002135 if (!appSearchData.containsKey("source")) {
2136 appSearchData.putString("source", getPackageName());
2137 }
2138 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2139 if (!TextUtils.isEmpty(initialQuery)) {
2140 intent.putExtra(SearchManager.QUERY, initialQuery);
2141 }
2142 if (selectInitialQuery) {
2143 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2144 }
2145 intent.setSourceBounds(sourceBounds);
2146 try {
2147 startActivity(intent);
2148 } catch (ActivityNotFoundException ex) {
2149 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2150 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 }
2152
Yura4f93ec62014-02-04 14:15:21 +00002153 public boolean isOnCustomContent() {
2154 return mWorkspace.isOnOrMovingToCustomContent();
2155 }
2156
Winson Chung70d72102011-08-12 11:24:35 -07002157 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002158 public boolean onPrepareOptionsMenu(Menu menu) {
2159 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002160 if (mLauncherCallbacks != null) {
2161 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2162 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002163 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002164 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002166 @Override
2167 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002168 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002169 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002170 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002171 }
2172
Joe Onorato9c1289c2009-08-17 11:03:03 -04002173 public boolean isWorkspaceLocked() {
2174 return mWorkspaceLoading || mWaitingForResult;
2175 }
2176
Adam Cohen517a7f52014-03-01 12:12:59 -08002177 public boolean isWorkspaceLoading() {
2178 return mWorkspaceLoading;
2179 }
2180
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002181 private void setWorkspaceLoading(boolean value) {
2182 boolean isLocked = isWorkspaceLocked();
2183 mWorkspaceLoading = value;
2184 if (isLocked != isWorkspaceLocked()) {
2185 onWorkspaceLockedChanged();
2186 }
2187 }
2188
2189 private void setWaitingForResult(boolean value) {
2190 boolean isLocked = isWorkspaceLocked();
2191 mWaitingForResult = value;
2192 if (isLocked != isWorkspaceLocked()) {
2193 onWorkspaceLockedChanged();
2194 }
2195 }
2196
Adam Cohen9211d422014-10-07 18:14:53 -07002197 protected void onWorkspaceLockedChanged() {
2198 if (mLauncherCallbacks != null) {
2199 mLauncherCallbacks.onWorkspaceLockedChanged();
2200 }
2201 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002202
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002204 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002205 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002206 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2207 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002208 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002209 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002210
Tony Wickhama0628cc2015-10-14 15:23:04 -07002211 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002212 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002213 if (LOGD) {
2214 Log.d(TAG, "Adding widget from drop");
2215 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002216 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2217 }
2218
Sunny Goyale6b63a32015-01-16 16:14:29 -08002219 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002220 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2221 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002222 if (appWidgetInfo.configure != null) {
2223 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002224 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002225
Bjorn Bringert7984c942009-12-09 15:38:25 +00002226 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002227 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2228 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2229
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002230 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002231 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002232 Runnable onComplete = new Runnable() {
2233 @Override
2234 public void run() {
2235 // Exit spring loaded mode if necessary after adding the widget
2236 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2237 null);
2238 }
2239 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002240 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002241 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002242 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002243 }
2244 }
Romain Guycbb89e42009-06-08 15:52:54 -07002245
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002246 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002247 // Close any folders that may be open.
2248 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002249 mWorkspace.moveToCustomContentScreen(animate);
2250 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002251
2252 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2253 int[] cell, int spanX, int spanY) {
2254 switch (info.itemType) {
2255 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2256 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2257 int span[] = new int[2];
2258 span[0] = spanX;
2259 span[1] = spanY;
2260 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2261 container, screenId, cell, span);
2262 break;
2263 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2264 processShortcutFromDrop(info.componentName, container, screenId, cell);
2265 break;
2266 default:
2267 throw new IllegalStateException("Unknown item type: " + info.itemType);
2268 }
2269 }
2270
Adam Cohenfbba09b2011-07-18 21:43:05 -07002271 /**
2272 * Process a shortcut drop.
2273 *
2274 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002275 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002276 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002277 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002278 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2279 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002280 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002282 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002283
2284 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002285 mPendingAddInfo.cellX = cell[0];
2286 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002287 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002288
2289 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2290 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002291 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002292 }
2293
Adam Cohenfbba09b2011-07-18 21:43:05 -07002294 /**
2295 * Process a widget drop.
2296 *
2297 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002298 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002299 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002300 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002301 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2302 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002303 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002305 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002306 mPendingAddInfo.minSpanX = info.minSpanX;
2307 mPendingAddInfo.minSpanY = info.minSpanY;
2308
Adam Cohenfbba09b2011-07-18 21:43:05 -07002309 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 mPendingAddInfo.cellX = cell[0];
2311 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002312 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002313 if (span != null) {
2314 mPendingAddInfo.spanX = span[0];
2315 mPendingAddInfo.spanY = span[1];
2316 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002317
Adam Cohened66b2b2012-01-23 17:28:51 -08002318 AppWidgetHostView hostView = info.boundWidget;
2319 int appWidgetId;
2320 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002321 // In the case where we've prebound the widget, we remove it from the DragLayer
2322 if (LOGD) {
2323 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2324 }
2325 getDragLayer().removeView(hostView);
2326
Adam Cohened66b2b2012-01-23 17:28:51 -08002327 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002328 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002329
2330 // Clear the boundWidget so that it doesn't get destroyed.
2331 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002332 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002333 // In this case, we either need to start an activity to get permission to bind
2334 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002335 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002336 Bundle options = info.bindOptions;
2337
Sunny Goyalffe83f12014-08-14 17:39:34 -07002338 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2339 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002340 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002341 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002342 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002343 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002344 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2345 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2346 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002347 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2348 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002349 // TODO: we need to make sure that this accounts for the options bundle.
2350 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002351 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2352 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002353 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002354 }
2355
Adam Cohendcd297f2013-06-18 13:13:40 -07002356 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002357 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002358 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002359 folderInfo.title = getText(R.string.folder_name);
2360
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002361 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002362 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2363 cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002364
2365 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002366 FolderIcon newFolder =
2367 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002368 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002369 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002370 // Force measure the new folder icon
2371 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2372 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002373 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 }
Romain Guycbb89e42009-06-08 15:52:54 -07002375
Winsonc0b52fe2015-09-09 16:38:15 -07002376 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002377 * Unbinds the view for the specified item, and removes the item and all its children.
2378 *
2379 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002380 * @param itemInfo the {@link ItemInfo} for this view.
2381 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002382 */
Winson2949fb52015-09-24 09:56:11 -07002383 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002384 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002385 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07002386 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
2387 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07002388 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07002389 } else {
2390 mWorkspace.removeWorkspaceItem(v);
2391 }
Winsonc0b52fe2015-09-09 16:38:15 -07002392 if (deleteFromDb) {
2393 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2394 }
2395 } else if (itemInfo instanceof FolderInfo) {
2396 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Winsonc0b52fe2015-09-09 16:38:15 -07002397 mWorkspace.removeWorkspaceItem(v);
2398 if (deleteFromDb) {
2399 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2400 }
2401 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2402 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002403 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002404 removeWidgetToAutoAdvance(widgetInfo.hostView);
2405 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002406 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002407 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002408 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002409
Winsonc0b52fe2015-09-09 16:38:15 -07002410 } else {
2411 return false;
2412 }
2413 return true;
2414 }
2415
2416 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002417 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002418 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002419 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002420 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002421 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002422 // Deleting an app widget ID is a void call but writes to disk before returning
2423 // to the caller...
2424 new AsyncTask<Void, Void, Void>() {
2425 public Void doInBackground(Void ... args) {
2426 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2427 return null;
2428 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002429 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002430 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002431 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002432 }
2433
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002434 @Override
2435 public boolean dispatchKeyEvent(KeyEvent event) {
2436 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2437 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002438 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002439 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002440 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002441 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002442 dumpState();
2443 return true;
2444 }
2445 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002446 }
2447 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2448 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002449 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002450 return true;
2451 }
2452 }
2453
2454 return super.dispatchKeyEvent(event);
2455 }
2456
Joe Onorato88ec0992009-11-19 13:16:06 -08002457 @Override
2458 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002459 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2460 return;
2461 }
2462
Sunny Goyal45478022015-06-08 16:52:41 -07002463 if (mDragController.isDragging()) {
2464 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002465 return;
2466 }
2467
Winson Chungb745afb2015-03-02 11:51:23 -08002468 if (isAppsViewVisible()) {
2469 showWorkspace(true);
2470 } else if (isWidgetsViewVisible()) {
2471 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002472 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002473 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002474 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002475 Folder openFolder = mWorkspace.getOpenFolder();
2476 if (openFolder.isEditingName()) {
2477 openFolder.dismissEditingName();
2478 } else {
2479 closeFolder();
2480 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002481 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002482 mWorkspace.exitWidgetResizeMode();
2483
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002484 // Back button is a no-op here, but give at least some feedback for the button press
2485 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002486 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002487 }
2488
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002489 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002490 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002491 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002492 @Override
2493 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002494 if (mAppWidgetHost != null) {
2495 mAppWidgetHost.startListening();
2496 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002497
2498 // Recreate the QSB, as the widget has been reset.
2499 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002500 }
2501
2502 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002503 * Launches the intent referred by the clicked shortcut.
2504 *
2505 * @param v The view representing the clicked shortcut.
2506 */
2507 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002508 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2509 // view has detached (it's possible for this to happen if the view is removed mid touch).
2510 if (v.getWindowToken() == null) {
2511 return;
2512 }
2513
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002514 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002515 return;
2516 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002517
Adam Cohen1697b792013-09-17 19:08:21 -07002518 if (v instanceof Workspace) {
2519 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002520 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002521 }
2522 return;
2523 }
2524
2525 if (v instanceof CellLayout) {
2526 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002527 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2528 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002529 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002530 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002531 }
2532
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002533 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002534 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002535 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002536 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002537 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002538 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002539 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002540 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002541 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002542 } else if (tag instanceof AppInfo) {
2543 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002544 } else if (tag instanceof LauncherAppWidgetInfo) {
2545 if (v instanceof PendingAppWidgetHostView) {
2546 onClickPendingWidget((PendingAppWidgetHostView) v);
2547 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002548 }
2549 }
2550
Sunny Goyal70660032015-05-14 00:07:08 -07002551 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002552 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002553 return false;
2554 }
2555
Michael Jurkaaf442092010-06-10 17:01:57 -07002556 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002557 * Event handler for the app widget view which has not fully restored.
2558 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002559 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002560 if (mIsSafeModeEnabled) {
2561 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2562 return;
2563 }
2564
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002565 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002566 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002567 int widgetId = info.appWidgetId;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002568 LauncherAppWidgetProviderInfo appWidgetInfo =
2569 mAppWidgetManager.getLauncherAppWidgetInfo(widgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002570 if (appWidgetInfo != null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002571 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002572 mPendingAddInfo.copyFrom(info);
2573 mPendingAddWidgetId = widgetId;
2574
Sunny Goyalffe83f12014-08-14 17:39:34 -07002575 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2576 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002577 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002578 } else if (info.installProgress < 0) {
2579 // The install has not been queued
2580 final String packageName = info.providerName.getPackageName();
2581 showBrokenAppInstallDialog(packageName,
2582 new DialogInterface.OnClickListener() {
2583 public void onClick(DialogInterface dialog, int id) {
2584 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2585 }
2586 });
2587 } else {
2588 // Download has started.
2589 final String packageName = info.providerName.getPackageName();
2590 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002591 }
2592 }
2593
2594 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002595 * Event handler for the "grid" button that appears on the home screen, which
2596 * enters all apps mode.
2597 *
2598 * @param v The view that was clicked.
2599 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002600 protected void onClickAllAppsButton(View v) {
2601 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002602 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002603 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002604 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002605
2606 if (mLauncherCallbacks != null) {
2607 mLauncherCallbacks.onClickAllAppsButton(v);
2608 }
Winson Chung76648c52015-07-10 14:33:23 -07002609 }
2610 }
2611
2612 protected void onLongClickAllAppsButton(View v) {
2613 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2614 if (!isAppsViewVisible()) {
2615 showAppsView(true /* animated */, false /* resetListToTop */,
2616 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 }
2618 }
2619
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002620 private void showBrokenAppInstallDialog(final String packageName,
2621 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002622 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002623 .setTitle(R.string.abandoned_promises_title)
2624 .setMessage(R.string.abandoned_promise_explanation)
2625 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2626 .setNeutralButton(R.string.abandoned_clean_this,
2627 new DialogInterface.OnClickListener() {
2628 public void onClick(DialogInterface dialog, int id) {
2629 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2630 mWorkspace.removeAbandonedPromise(packageName, user);
2631 }
2632 })
2633 .create().show();
2634 return;
2635 }
2636
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002637 /**
2638 * Event handler for an app shortcut click.
2639 *
2640 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2641 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002642 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002643 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2644 Object tag = v.getTag();
2645 if (!(tag instanceof ShortcutInfo)) {
2646 throw new IllegalArgumentException("Input must be a Shortcut");
2647 }
2648
2649 // Open shortcut
2650 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002651
2652 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002653 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2654 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002655 // Launch activity anyway, framework will tell the user why the app is suspended.
2656 } else {
2657 int error = R.string.activity_not_available;
2658 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2659 error = R.string.safemode_shortcut_error;
2660 }
2661 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2662 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002663 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002664 }
2665
Chris Wren40c5ed32014-06-24 18:24:23 -04002666 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002667 if ((v instanceof BubbleTextView)
2668 && shortcut.isPromise()
2669 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002670 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002671 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002672 new DialogInterface.OnClickListener() {
2673 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002674 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002675 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002676 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002677 return;
2678 }
2679
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002680 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002681 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002682
2683 if (mLauncherCallbacks != null) {
2684 mLauncherCallbacks.onClickAppShortcut(v);
2685 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002686 }
2687
Adam Cohen091440a2015-03-18 14:16:05 -07002688 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002689 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002690 final ShortcutInfo shortcut;
2691 final Intent intent;
2692 if (tag instanceof ShortcutInfo) {
2693 shortcut = (ShortcutInfo) tag;
2694 intent = shortcut.intent;
2695 int[] pos = new int[2];
2696 v.getLocationOnScreen(pos);
2697 intent.setSourceBounds(new Rect(pos[0], pos[1],
2698 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002699
Sunny Goyal508da152014-08-14 10:53:27 -07002700 } else if (tag instanceof AppInfo) {
2701 shortcut = null;
2702 intent = ((AppInfo) tag).intent;
2703 } else {
2704 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2705 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002706
2707 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002708 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002709
2710 if (success && v instanceof BubbleTextView) {
2711 mWaitingForResume = (BubbleTextView) v;
2712 mWaitingForResume.setStayPressed(true);
2713 }
2714 }
2715
2716 /**
2717 * Event handler for a folder icon click.
2718 *
2719 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2720 */
2721 protected void onClickFolderIcon(View v) {
2722 if (LOGD) Log.d(TAG, "onClickFolder");
2723 if (!(v instanceof FolderIcon)){
2724 throw new IllegalArgumentException("Input must be a FolderIcon");
2725 }
2726
2727 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002728 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002729 // Open the requested folder
Adam Cohen37b2a492016-04-06 18:36:06 -07002730 openFolder(folderIcon);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002731 }
Adam Cohen9211d422014-10-07 18:14:53 -07002732
2733 if (mLauncherCallbacks != null) {
2734 mLauncherCallbacks.onClickFolderIcon(v);
2735 }
Michael Jurka5130e402011-10-13 04:55:35 -07002736 }
2737
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002738 /**
2739 * Event handler for the (Add) Widgets button that appears after a long press
2740 * on the home screen.
2741 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002742 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002743 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002744 if (mIsSafeModeEnabled) {
2745 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2746 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002747 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002748 if (mLauncherCallbacks != null) {
2749 mLauncherCallbacks.onClickAddWidgetButton(view);
2750 }
Adam Cohen9211d422014-10-07 18:14:53 -07002751 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002752 }
2753
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002754 /**
2755 * Event handler for the wallpaper picker button that appears after a long press
2756 * on the home screen.
2757 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002758 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002759 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002760 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2761 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal30a71612016-04-12 17:57:41 -07002762 // TODO: Start the system wallpaper picker
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002763 }
2764
2765 /**
2766 * Event handler for a click on the settings button that appears after a long press
2767 * on the home screen.
2768 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002769 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002770 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002771 if (mLauncherCallbacks != null) {
2772 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002773 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002774 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002775 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002776 }
2777
Adam Cohen61f560d2013-09-30 15:58:20 -07002778 public View.OnTouchListener getHapticFeedbackTouchListener() {
2779 if (mHapticFeedbackTouchListener == null) {
2780 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002781 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002782 @Override
2783 public boolean onTouch(View v, MotionEvent event) {
2784 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2785 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2786 }
2787 return false;
2788 }
2789 };
2790 }
2791 return mHapticFeedbackTouchListener;
2792 }
2793
Tony Wickhame2217252016-03-22 16:34:23 -07002794 @Override
2795 public void onAccessibilityStateChanged(boolean enabled) {
2796 mDragLayer.onAccessibilityStateChanged(enabled);
2797 }
2798
Adam Cohen9211d422014-10-07 18:14:53 -07002799 public void onDragStarted(View view) {
2800 if (isOnCustomContent()) {
2801 // Custom content screen doesn't participate in drag and drop. If on custom
2802 // content screen, move to default.
2803 moveWorkspaceToDefaultScreen();
2804 }
2805
2806 if (mLauncherCallbacks != null) {
2807 mLauncherCallbacks.onDragStarted(view);
2808 }
2809 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002810
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002811 /**
2812 * Called when the user stops interacting with the launcher.
2813 * This implies that the user is now on the homescreen and is not doing housekeeping.
2814 */
Adam Cohen9211d422014-10-07 18:14:53 -07002815 protected void onInteractionEnd() {
2816 if (mLauncherCallbacks != null) {
2817 mLauncherCallbacks.onInteractionEnd();
2818 }
2819 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002820
2821 /**
2822 * Called when the user starts interacting with the launcher.
2823 * The possible interactions are:
2824 * - open all apps
2825 * - reorder an app shortcut, or a widget
2826 * - open the overview mode.
2827 * This is a good time to stop doing things that only make sense
2828 * when the user is on the homescreen and not doing housekeeping.
2829 */
Adam Cohen9211d422014-10-07 18:14:53 -07002830 protected void onInteractionBegin() {
2831 if (mLauncherCallbacks != null) {
2832 mLauncherCallbacks.onInteractionBegin();
2833 }
2834 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002835
Winson Chungcd99cd32015-04-29 11:03:24 -07002836 /** Updates the interaction state. */
2837 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002838 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002839 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002840 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2841 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002842 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002843 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002844 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002845 onInteractionEnd();
2846 }
2847 }
2848
Winson Chung8f1eff72015-05-28 17:33:40 -07002849 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002850 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002851 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002852 // Only launch using the new animation if the shortcut has not opted out (this is a
2853 // private contract between launcher and may be ignored in the future).
2854 boolean useLaunchAnimation = (v != null) &&
2855 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002856 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2857 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002858
Kenny Guy1317e2d2014-05-08 18:52:50 +01002859 UserHandleCompat user = null;
2860 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2861 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2862 user = userManager.getUserForSerialNumber(serialNumber);
2863 }
2864
2865 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002866 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002867 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002868 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002869 int left = 0, top = 0;
2870 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2871 if (v instanceof TextView) {
2872 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002873 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2874 if (icon != null) {
2875 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002876 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002877 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002878 width = bounds.width();
2879 height = bounds.height();
2880 }
2881 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002882 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2883 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002884 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002885 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002886 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002887 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002888 // On L devices, we use the device default slide-up transition.
2889 // On L MR1 devices, we a custom version of the slide-up transition which
2890 // doesn't have the delay present in the device default.
2891 opts = ActivityOptions.makeCustomAnimation(this,
2892 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002893 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002894 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002895 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002896
2897 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2898 // Could be launching some bookkeeping activity
2899 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002900 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002901 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002902 launcherApps.startActivityForProfile(intent.getComponent(), user,
2903 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002904 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002905 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002906 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002907 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2908 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2909 // corresponding permission. Show the appropriate permission prompt if that
2910 // is the case.
2911 if (intent.getComponent() == null
2912 && Intent.ACTION_CALL.equals(intent.getAction())
2913 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2914 PackageManager.PERMISSION_GRANTED) {
2915 // TODO: Rename sPendingAddItem to a generic name.
2916 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2917 0, (ItemInfo) tag);
2918 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2919 REQUEST_PERMISSION_CALL_PHONE);
2920 return false;
2921 }
2922 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002923 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002924 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002925 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002926 "or use the exported attribute for this activity. "
2927 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002928 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002929 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002930 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002931
Winson Chungbedf9232015-07-10 12:38:30 -07002932 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002933 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002934 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2935 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2936 return false;
2937 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002938 try {
2939 success = startActivity(v, intent, tag);
2940 } catch (ActivityNotFoundException e) {
2941 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2942 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2943 }
2944 return success;
2945 }
2946
Adam Cohen268c4752012-06-06 17:47:33 -07002947 /**
2948 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2949 * in the DragLayer in the exact absolute location of the original FolderIcon.
2950 */
2951 private void copyFolderIconToImage(FolderIcon fi) {
2952 final int width = fi.getMeasuredWidth();
2953 final int height = fi.getMeasuredHeight();
2954
2955 // Lazy load ImageView, Bitmap and Canvas
2956 if (mFolderIconImageView == null) {
2957 mFolderIconImageView = new ImageView(this);
2958 }
2959 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2960 mFolderIconBitmap.getHeight() != height) {
2961 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2962 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2963 }
2964
2965 DragLayer.LayoutParams lp;
2966 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2967 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2968 } else {
2969 lp = new DragLayer.LayoutParams(width, height);
2970 }
2971
Adam Cohen307fe232012-08-16 17:55:58 -07002972 // The layout from which the folder is being opened may be scaled, adjust the starting
2973 // view size by this scale factor.
2974 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002975 lp.customPosition = true;
2976 lp.x = mRectForFolderAnimation.left;
2977 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002978 lp.width = (int) (scale * width);
2979 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002980
2981 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2982 fi.draw(mFolderIconCanvas);
2983 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002984 if (fi.getFolder() != null) {
2985 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2986 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002987 }
Adam Cohen268c4752012-06-06 17:47:33 -07002988 // Just in case this image view is still in the drag layer from a previous animation,
2989 // we remove it and re-add it.
2990 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2991 mDragLayer.removeView(mFolderIconImageView);
2992 }
2993 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002994 if (fi.getFolder() != null) {
2995 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002996 }
Adam Cohen268c4752012-06-06 17:47:33 -07002997 }
2998
Adam Cohen37b2a492016-04-06 18:36:06 -07002999 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003000 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003001 FolderInfo info = (FolderInfo) fi.getTag();
3002 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3003 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003004 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3005 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003006 }
3007
Adam Cohen268c4752012-06-06 17:47:33 -07003008 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3009 copyFolderIconToImage(fi);
3010 fi.setVisibility(View.INVISIBLE);
3011
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003012 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3013 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003014 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003015 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3016 }
3017 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003018 oa.start();
3019 }
3020
Sunny Goyal935fca12015-10-13 10:19:01 -07003021 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003022 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003023 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003024
Adam Cohen268c4752012-06-06 17:47:33 -07003025 // We remove and re-draw the FolderIcon in-case it has changed
3026 mDragLayer.removeView(mFolderIconImageView);
3027 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08003028
3029 if (cl != null) {
3030 cl.clearFolderLeaveBehind();
3031 }
3032
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003033 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003034 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003035 oa.addListener(new AnimatorListenerAdapter() {
3036 @Override
3037 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003038 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003039 // Remove the ImageView copy of the FolderIcon and make the original visible.
3040 mDragLayer.removeView(mFolderIconImageView);
3041 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003042 }
3043 }
3044 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003045 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003046 if (!animate) {
3047 oa.end();
3048 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003049 }
3050
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003051 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003052 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003053 * is animated relative to the specified View. If the View is null, no animation
3054 * is played.
3055 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003056 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003057 */
Adam Cohen37b2a492016-04-06 18:36:06 -07003058 public void openFolder(FolderIcon folderIcon) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003059
Adam Cohenfb91f302012-06-11 15:45:18 -07003060 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003061 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3062 if (openFolder != null && openFolder != folder) {
3063 // Close any open folder before opening a folder.
3064 closeFolder();
3065 }
3066
Adam Cohena9cf38f2011-05-02 15:36:58 -07003067 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003068
Adam Cohena9cf38f2011-05-02 15:36:58 -07003069 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003070
Sunny Goyalf4066152015-04-15 09:42:19 -07003071 // While the folder is open, the position of the icon cannot change.
3072 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3073
Adam Cohen4554ee12011-08-03 16:13:21 -07003074 // Just verify that the folder hasn't already been added to the DragLayer.
3075 // There was a one-off crash where the folder had a parent already.
3076 if (folder.getParent() == null) {
3077 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003078 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003079 } else {
3080 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3081 folder.getParent() + ").");
3082 }
Adam Cohen37b2a492016-04-06 18:36:06 -07003083 folder.animateOpen();
3084
3085 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003086
3087 // Notify the accessibility manager that this folder "window" has appeared and occluded
3088 // the workspace items
3089 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3090 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003091 }
3092
3093 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003094 closeFolder(true);
3095 }
3096
3097 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003098 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003099 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003100 if (folder.isEditingName()) {
3101 folder.dismissEditingName();
3102 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003103 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003104 }
3105 }
3106
Sunny Goyal935fca12015-10-13 10:19:01 -07003107 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003108 animate &= !Utilities.isPowerSaverOn(this);
3109
Adam Cohen4554ee12011-08-03 16:13:21 -07003110 folder.getInfo().opened = false;
3111
3112 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3113 if (parent != null) {
3114 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003115 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003116 if (fi != null) {
3117 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3118 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003119 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003120 if (animate) {
3121 folder.animateClosed();
3122 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003123 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003124 }
Winson Chung83ca4802013-04-12 15:10:52 -07003125
Sunny Goyal935fca12015-10-13 10:19:01 -07003126 // Notify the accessibility manager that this folder "window" has disappeared and no
3127 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003128 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003129 }
3130
Tony Wickhamdadb3042016-02-24 11:07:00 -08003131 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003132 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003133 if (!isDraggingEnabled()) return false;
3134 if (isWorkspaceLocked()) return false;
3135 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003136
Winson Chung76648c52015-07-10 14:33:23 -07003137 if (v == mAllAppsButton) {
3138 onLongClickAllAppsButton(v);
3139 return true;
3140 }
3141
Adam Cohen1697b792013-09-17 19:08:21 -07003142 if (v instanceof Workspace) {
3143 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003144 if (!mWorkspace.isTouchActive()) {
3145 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003146 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3147 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3148 return true;
3149 } else {
3150 return false;
3151 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003152 } else {
3153 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003154 }
Adam Cohen1697b792013-09-17 19:08:21 -07003155 }
3156
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003157 CellLayout.CellInfo longClickCellInfo = null;
3158 View itemUnderLongClick = null;
3159 if (v.getTag() instanceof ItemInfo) {
3160 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003161 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003162 itemUnderLongClick = longClickCellInfo.cell;
3163 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003164 }
3165
Winson Chung3d503fb2011-07-13 17:25:49 -07003166 // The hotseat touch handling does not go through Workspace, and we always allow long press
3167 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003168 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003169 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003170 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003171 // User long pressed on empty space
3172 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3173 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003174 if (mWorkspace.isInOverviewMode()) {
3175 mWorkspace.startReordering(v);
3176 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003177 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003178 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003179 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003180 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3181 mHotseat.getOrderInHotseat(
3182 longClickCellInfo.cellX,
3183 longClickCellInfo.cellY));
3184 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003185 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003186 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003187 }
3188 }
3189 }
3190 return true;
3191 }
3192
Winson Chung3d503fb2011-07-13 17:25:49 -07003193 boolean isHotseatLayout(View layout) {
3194 return mHotseat != null && layout != null &&
3195 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3196 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003197
Winson Chung3d503fb2011-07-13 17:25:49 -07003198 /**
3199 * Returns the CellLayout of the specified container at the specified screen.
3200 */
Sunny Goyal92820592015-03-02 11:31:35 -08003201 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003202 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3203 if (mHotseat != null) {
3204 return mHotseat.getLayout();
3205 } else {
3206 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003207 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003208 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003209 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003210 }
3211 }
3212
Winson Chungb745afb2015-03-02 11:51:23 -08003213 /**
3214 * For overridden classes.
3215 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003216 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003217 return isAppsViewVisible();
3218 }
3219
3220 public boolean isAppsViewVisible() {
3221 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3222 }
3223
3224 public boolean isWidgetsViewVisible() {
3225 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003226 }
3227
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003228 private void setWorkspaceBackground(int background) {
3229 switch (background) {
3230 case WORKSPACE_BACKGROUND_TRANSPARENT:
3231 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3232 break;
3233 case WORKSPACE_BACKGROUND_BLACK:
3234 getWindow().setBackgroundDrawable(null);
3235 break;
3236 default:
3237 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3238 }
Craig Mautner360310b2012-10-26 15:13:08 -07003239 }
3240
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003241 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003242 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3243 int curflags = getWindow().getAttributes().flags
3244 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3245 if (wpflags != curflags) {
3246 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3247 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003248 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003249 }
3250
Michael Jurkae326f182011-11-21 14:05:46 -08003251 @Override
3252 public void onTrimMemory(int level) {
3253 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003254 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3255 // The widget preview db can result in holding onto over
3256 // 3MB of memory for caching which isn't necessary.
3257 SQLiteDatabase.releaseMemory();
3258
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003259 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003260 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003261 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003262 if (mLauncherCallbacks != null) {
3263 mLauncherCallbacks.onTrimMemory(level);
3264 }
Michael Jurkae326f182011-11-21 14:05:46 -08003265 }
3266
Winson5c6bdbb2015-09-03 11:36:19 -07003267 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003268 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003269 }
3270
Winson5c6bdbb2015-09-03 11:36:19 -07003271 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003272 boolean changed = mState != State.WORKSPACE ||
3273 mWorkspace.getState() != Workspace.State.NORMAL;
3274 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003275 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003276 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003277 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003278
Michael Jurkab3e22d92011-10-31 15:58:33 -07003279 // Set focus to the AppsCustomize button
3280 if (mAllAppsButton != null) {
3281 mAllAppsButton.requestFocus();
3282 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003283 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003284
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003285 // Change the state *after* we've called all the transition code
3286 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003287
Winson Chung5fb63472011-02-02 17:03:37 -08003288 // Resume the auto-advance of widgets
3289 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003290 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003291
Winson Chung0f785722015-04-08 10:27:49 -07003292 if (changed) {
3293 // Send an accessibility event to announce the context change
3294 getWindow().getDecorView()
3295 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003296 }
Winson5c6bdbb2015-09-03 11:36:19 -07003297 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003298 }
3299
Winsone9f27272015-10-13 10:47:51 -07003300 /**
3301 * Shows the overview button.
3302 */
Adam Cohened307df2013-10-02 09:37:31 -07003303 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003304 showOverviewMode(animated, false);
3305 }
3306
3307 /**
3308 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3309 * onto one of the overview panel buttons.
3310 */
3311 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3312 Runnable postAnimRunnable = null;
3313 if (requestButtonFocus) {
3314 postAnimRunnable = new Runnable() {
3315 @Override
3316 public void run() {
3317 // Hitting the menu button when in touch mode does not trigger touch mode to
3318 // be disabled, so if requested, force focus on one of the overview panel
3319 // buttons.
3320 mOverviewPanel.requestFocusFromTouch();
3321 }
3322 };
3323 }
Adam Cohened307df2013-10-02 09:37:31 -07003324 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003325 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003326 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003327 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003328 }
3329
Winson Chungb745afb2015-03-02 11:51:23 -08003330 /**
3331 * Shows the apps view.
3332 */
Winson Chung76648c52015-07-10 14:33:23 -07003333 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3334 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003335 if (resetListToTop) {
3336 mAppsView.scrollToTop();
3337 }
Winson Chung4ac30062015-05-08 17:34:17 -07003338 if (updatePredictedApps) {
3339 tryAndUpdatePredictedApps();
3340 }
Winson Chung76648c52015-07-10 14:33:23 -07003341 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003342 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003343
Winson Chungb745afb2015-03-02 11:51:23 -08003344 /**
3345 * Shows the widgets view.
3346 */
3347 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003348 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003349 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003350 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003351 }
Winson Chung76648c52015-07-10 14:33:23 -07003352 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003353
3354 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003355 @Override
3356 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003357 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003358 }
3359 });
Winson Chungb745afb2015-03-02 11:51:23 -08003360 }
3361
3362 /**
3363 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003364 *
3365 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003366 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003367 // TODO: calling method should use the return value so that when {@code false} is returned
3368 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003369 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003370 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3371 mState != State.WIDGETS_SPRING_LOADED) {
3372 return false;
3373 }
3374 if (toState != State.APPS && toState != State.WIDGETS) {
3375 return false;
3376 }
Winson Chungb745afb2015-03-02 11:51:23 -08003377
3378 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003379 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3380 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003381 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003382 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003383 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003384
Michael Jurkab3e22d92011-10-31 15:58:33 -07003385 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003386 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003387
3388 // Pause the auto-advance of widgets until we are out of AllApps
3389 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003390 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003391 closeFolder();
3392
3393 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003394 getWindow().getDecorView()
3395 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003396 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003397 }
3398
Winson Chungcd99cd32015-04-29 11:03:24 -07003399 /**
3400 * Updates the workspace and interaction state on state change, and return the animation to this
3401 * new state.
3402 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003403 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003404 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003405 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003406 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003407 updateInteraction(fromState, toState);
3408 return anim;
3409 }
3410
Jun Mukaif0033da2015-08-04 18:34:30 -07003411 public void onLauncherClingShown() {
3412 // When a launcher cling appears, it should cover the underlying layers, so their focus
3413 // should be blocked.
3414 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3415 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3416 }
3417 }
3418
3419 public void onLauncherClingDismissed() {
3420 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3421 }
3422
Hyunyoung Song3f471442015-04-08 19:01:34 -07003423 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003424 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003425 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003426 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003427 }
Winson Chungb745afb2015-03-02 11:51:23 -08003428
Winson Chung006ee262015-08-03 14:40:11 -07003429 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003430 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003431 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003432
3433 if (isAppsViewVisible()) {
3434 mState = State.APPS_SPRING_LOADED;
3435 } else if (isWidgetsViewVisible()) {
3436 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003437 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003438 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003439 } else {
3440 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003441 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003442 }
Adam Cohen7777d962011-08-18 18:58:38 -07003443
Hyunyoung Song3f471442015-04-08 19:01:34 -07003444 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003445 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003446 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003447
Winson Chunge7a03942011-08-05 15:05:12 -07003448 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003449 @Override
3450 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003451 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003452 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3453 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003454 // Before we show workspace, hide all apps again because
3455 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3456 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003457 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003458 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003459 } else {
3460 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003461 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003462 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003463 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003464 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003465
Tony Wickhame0c33232016-02-08 11:37:04 -08003466 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003467 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3468 || mState == State.WIDGETS_SPRING_LOADED;
3469 }
3470
Michael Jurkad3ef3062010-11-23 16:23:58 -08003471 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003472 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003473 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003474 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003475 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003476 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003477 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3478 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003479 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003480 }
3481
Winson Chung4ac30062015-05-08 17:34:17 -07003482 /**
3483 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3484 * resumed.
3485 */
3486 private void tryAndUpdatePredictedApps() {
3487 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003488 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003489 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003490 mAppsView.setPredictedApps(apps);
3491 }
3492 }
3493 }
3494
Michael Jurkab3e22d92011-10-31 15:58:33 -07003495 void lockAllApps() {
3496 // TODO
3497 }
3498
3499 void unlockAllApps() {
3500 // TODO
3501 }
3502
Winsonf768d932015-09-25 16:12:35 -07003503 public boolean launcherCallbacksProvidesSearch() {
3504 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3505 }
3506
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003507 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003508 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003509 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003510 }
3511
Adam Cohen24ce0b32014-01-14 16:18:14 -08003512 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003513 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3514 if (searchProvider == null) {
3515 return null;
3516 }
3517
3518 Bundle opts = new Bundle();
3519 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003520 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003521
Tony Wickham3a3517f2015-10-06 11:27:04 -07003522 // Determine the min and max dimensions of the widget.
3523 LauncherAppState app = LauncherAppState.getInstance();
3524 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3525 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3526 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003527 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3528 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003529 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003530 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003531 int minWidth = maxWidth;
3532 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003533 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3534 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3535 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3536 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3537 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003538 }
3539 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3540 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3541 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3542 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003543 if (LOGD) {
3544 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3545 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3546 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003547
Tony Wickham775455c2015-10-16 09:49:32 -07003548 if (mLauncherCallbacks != null) {
3549 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3550 }
3551
Sunny Goyalf7258242015-10-19 16:59:07 -07003552 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003553 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003554 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003555 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003556 || (widgetInfo == null)
3557 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003558 // A valid widget is not already bound.
3559 if (widgetId > -1) {
3560 mAppWidgetHost.deleteAppWidgetId(widgetId);
3561 widgetId = -1;
3562 }
3563
3564 // Try to bind a new widget
3565 widgetId = mAppWidgetHost.allocateAppWidgetId();
3566
3567 if (!AppWidgetManagerCompat.getInstance(this)
3568 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3569 mAppWidgetHost.deleteAppWidgetId(widgetId);
3570 widgetId = -1;
3571 }
3572
Sunny Goyalf7258242015-10-19 16:59:07 -07003573 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003574 .putInt(QSB_WIDGET_ID, widgetId)
3575 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003576 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003577 }
3578
Sunny Goyal8d595092015-07-06 12:22:14 -07003579 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003580 if (widgetId != -1) {
3581 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003582 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003583 mQsb.updateAppWidgetOptions(opts);
3584 mQsb.setPadding(0, 0, 0, 0);
3585 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003586 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003587 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003588 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003589 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003590 }
3591
Sunny Goyal22235bc2015-04-03 09:23:43 -07003592 private void reinflateQSBIfNecessary() {
3593 if (mQsb instanceof LauncherAppWidgetHostView &&
3594 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3595 mSearchDropTargetBar.removeView(mQsb);
3596 mQsb = null;
3597 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3598 }
3599 }
3600
Michael Jurkad7c28052012-04-27 15:43:36 -07003601 @Override
3602 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003603 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003604 final List<CharSequence> text = event.getText();
3605 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003606 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003607 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003608 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003609 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003610 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003611 } else if (mWorkspace != null) {
3612 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003613 } else {
3614 text.add(getString(R.string.all_apps_home_button_label));
3615 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003616 return result;
3617 }
3618
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003619 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003620 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003621 */
Adam Cohen091440a2015-03-18 14:16:05 -07003622 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003623 @Override
3624 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003625 closeSystemDialogs();
3626 }
3627 }
3628
3629 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003630 * If the activity is currently paused, signal that we need to run the passed Runnable
3631 * in onResume.
3632 *
3633 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003634 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3635 * wrong when we're not running, and if the activity comes back to what the configuration was
3636 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003637 *
3638 * Implementation of the method from LauncherModel.Callbacks.
3639 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003640 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003641 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003642 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003643 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003644 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003645 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003646 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003647 }
3648 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003649 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003650 return true;
3651 } else {
3652 return false;
3653 }
3654 }
3655
Michael Jurkac402cd92013-05-20 15:49:32 +02003656 private boolean waitUntilResume(Runnable run) {
3657 return waitUntilResume(run, false);
3658 }
3659
Michael Jurka1e2f4652013-07-08 18:03:46 -07003660 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003661 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003662 }
3663
Michael Jurka7607c2f2013-04-03 14:33:19 -07003664 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003665 * If the activity is currently paused, signal that we need to re-run the loader
3666 * in onResume.
3667 *
3668 * This needs to be called from incoming places where resources might have been loaded
3669 * while we are paused. That is becaues the Configuration might be wrong
3670 * when we're not running, and if it comes back to what it was when we
3671 * were paused, we are not restarted.
3672 *
3673 * Implementation of the method from LauncherModel.Callbacks.
3674 *
3675 * @return true if we are currently paused. The caller might be able to
3676 * skip some work in that case since we will come back again.
3677 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003678 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003679 public boolean setLoadOnResume() {
3680 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003681 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003682 mOnResumeNeedsLoad = true;
3683 return true;
3684 } else {
3685 return false;
3686 }
3687 }
3688
3689 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003690 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003691 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003692 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04003693 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003694 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003695 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003696 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003697 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003698 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003699 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003700
Joe Onorato9c1289c2009-08-17 11:03:03 -04003701 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003702 * Clear any pending bind callbacks. This is called when is loader is planning to
3703 * perform a full rebind from scratch.
3704 */
3705 @Override
3706 public void clearPendingBinds() {
3707 mBindOnResumeCallbacks.clear();
3708 if (mPendingExecutor != null) {
3709 mPendingExecutor.markCompleted();
3710 mPendingExecutor = null;
3711 }
3712 }
3713
3714 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003715 * Refreshes the shortcuts shown on the workspace.
3716 *
3717 * Implementation of the method from LauncherModel.Callbacks.
3718 */
3719 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003720 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003721
Winson Chungd64d1762013-08-20 14:37:16 -07003722 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003723 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003724 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003725
Michael Jurka05bf644e2011-11-30 20:28:53 -08003726 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003727 if (mHotseat != null) {
3728 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003729 }
3730 }
3731
Adam Cohendcd297f2013-06-18 13:13:40 -07003732 @Override
3733 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003734 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003735
Adam Cohen5084cba2013-09-03 12:01:16 -07003736 // If there are no screens, we need to have an empty screen
3737 if (orderedScreenIds.size() == 0) {
3738 mWorkspace.addExtraEmptyScreen();
3739 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003740
3741 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003742 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003743 if (hasCustomContentToLeft()) {
3744 mWorkspace.createCustomContentContainer();
3745 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003746 }
Winson Chung64359a52013-07-08 17:17:08 -07003747 }
3748
3749 @Override
3750 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003751 int count = orderedScreenIds.size();
3752 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003753 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003754 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003755 }
3756
Winson Chungd64d1762013-08-20 14:37:16 -07003757 public void bindAppsAdded(final ArrayList<Long> newScreens,
3758 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003759 final ArrayList<ItemInfo> addAnimated,
3760 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003761 Runnable r = new Runnable() {
3762 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003763 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003764 }
3765 };
3766 if (waitUntilResume(r)) {
3767 return;
3768 }
3769
Winson Chungd64d1762013-08-20 14:37:16 -07003770 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003771 if (newScreens != null) {
3772 bindAddScreens(newScreens);
3773 }
Winson Chungd64d1762013-08-20 14:37:16 -07003774
3775 // We add the items without animation on non-visible pages, and with
3776 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003777 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003778 bindItems(addNotAnimated, 0,
3779 addNotAnimated.size(), false);
3780 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003781 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003782 bindItems(addAnimated, 0,
3783 addAnimated.size(), true);
3784 }
Winson Chungc58497e2013-09-03 17:48:37 -07003785
Winson Chung87412982013-10-03 18:34:14 -07003786 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003787 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003788
Winson Chungb745afb2015-03-02 11:51:23 -08003789 if (addedApps != null && mAppsView != null) {
3790 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003791 }
Winson Chungd64d1762013-08-20 14:37:16 -07003792 }
3793
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003794 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003795 * Bind the items start-end from the list.
3796 *
3797 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003798 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003799 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003800 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3801 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003802 Runnable r = new Runnable() {
3803 public void run() {
3804 bindItems(shortcuts, start, end, forceAnimateIcons);
3805 }
3806 };
3807 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003808 return;
3809 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003810
Winson Chungf0c6ae02012-03-21 16:10:31 -07003811 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003812 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3813 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003814 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003815 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003816 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003817 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003819
3820 // Short circuit if we are loading dock items for a configuration which has no dock
3821 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3822 mHotseat == null) {
3823 continue;
3824 }
3825
Sunny Goyal639e9062015-08-19 19:17:06 -07003826 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003827 switch (item.itemType) {
3828 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3829 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003830 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003831 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003832
Winson Chung64359a52013-07-08 17:17:08 -07003833 /*
3834 * TODO: FIX collision case
3835 */
Winson Chungce376632013-07-11 16:12:41 -07003836 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3837 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3838 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003839 View v = cl.getChildAt(item.cellX, item.cellY);
3840 Object tag = v.getTag();
3841 String desc = "Collision while binding workspace item: " + item
3842 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003843 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003844 throw (new RuntimeException(desc));
3845 } else {
3846 Log.d(TAG, desc);
3847 }
Winson Chungce376632013-07-11 16:12:41 -07003848 }
Winson Chung64359a52013-07-08 17:17:08 -07003849 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003850 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003851 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003852 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003853 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003854 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003855 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003856 default:
3857 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003858 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003859
3860 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3861 item.cellY, 1, 1);
3862 if (animateIcons) {
3863 // Animate all the applications up now
3864 view.setAlpha(0f);
3865 view.setScaleX(0f);
3866 view.setScaleY(0f);
3867 bounceAnims.add(createNewAppBounceAnimation(view, i));
3868 newShortcutsScreenId = item.screenId;
3869 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003870 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003871
Winson Chung997a9232013-07-24 15:33:46 -07003872 if (animateIcons) {
3873 // Animate to the correct page
3874 if (newShortcutsScreenId > -1) {
3875 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003876 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003877 final Runnable startBounceAnimRunnable = new Runnable() {
3878 public void run() {
3879 anim.playTogether(bounceAnims);
3880 anim.start();
3881 }
3882 };
Winson Chung997a9232013-07-24 15:33:46 -07003883 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003884 // We post the animation slightly delayed to prevent slowdowns
3885 // when we are loading right after we return to launcher.
3886 mWorkspace.postDelayed(new Runnable() {
3887 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003888 if (mWorkspace != null) {
3889 mWorkspace.snapToPage(newScreenIndex);
3890 mWorkspace.postDelayed(startBounceAnimRunnable,
3891 NEW_APPS_ANIMATION_DELAY);
3892 }
Winson Chung94d67682013-09-25 16:29:40 -07003893 }
3894 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003895 } else {
3896 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003897 }
3898 }
Winson Chung64359a52013-07-08 17:17:08 -07003899 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003900 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003901 }
3902
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003903 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3904 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3905 view.updateIcon(mIconCache);
3906 item.hostView = view;
3907 item.hostView.updateAppWidget(null);
3908 item.hostView.setOnClickListener(this);
3909 addAppWidgetToWorkspace(item, null, false);
3910 mWorkspace.requestLayout();
3911 }
3912
Joe Onorato9c1289c2009-08-17 11:03:03 -04003913 /**
3914 * Add the views for a widget to the workspace.
3915 *
3916 * Implementation of the method from LauncherModel.Callbacks.
3917 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003918 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003919 Runnable r = new Runnable() {
3920 public void run() {
3921 bindAppWidget(item);
3922 }
3923 };
3924 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003925 return;
3926 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003927
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003928 if (mIsSafeModeEnabled) {
3929 bindSafeModeWidget(item);
3930 return;
3931 }
3932
Daniel Sandler843e8602010-06-07 14:59:01 -04003933 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3934 if (DEBUG_WIDGETS) {
3935 Log.d(TAG, "bindAppWidget: " + item);
3936 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003937
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003938 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003939
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003940 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3941 // If the provider is not ready, bind as a pending widget.
3942 appWidgetInfo = null;
3943 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3944 // The widget id is not valid. Try to find the widget based on the provider info.
3945 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3946 } else {
3947 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3948 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003949
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003950 // If the provider is ready, but the width is not yet restored, try to restore it.
3951 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3952 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003953 if (appWidgetInfo == null) {
3954 if (DEBUG_WIDGETS) {
3955 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3956 + " belongs to component " + item.providerName
3957 + ", as the povider is null");
3958 }
3959 LauncherModel.deleteItemFromDatabase(this, item);
3960 return;
3961 }
Sunny Goyalff572272014-07-23 13:58:07 -07003962
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003963 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003964 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003965 // Note: This assumes that the id remap broadcast is received before this step.
3966 // If that is not the case, the id remap will be ignored and user may see the
3967 // click to setup view.
Sunny Goyal16466f12016-03-10 05:34:30 -08003968 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003969 pendingInfo.spanX = item.spanX;
3970 pendingInfo.spanY = item.spanY;
3971 pendingInfo.minSpanX = item.minSpanX;
3972 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08003973 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07003974
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003975 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
3976 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
3977 newWidgetId, appWidgetInfo, options);
3978
3979 // TODO consider showing a permission dialog when the widget is clicked.
3980 if (!success) {
3981 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
3982 if (DEBUG_WIDGETS) {
3983 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3984 + " belongs to component " + item.providerName
3985 + ", as the launcher is unable to bing a new widget id");
3986 }
3987 LauncherModel.deleteItemFromDatabase(this, item);
3988 return;
Sunny Goyalff572272014-07-23 13:58:07 -07003989 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003990
3991 item.appWidgetId = newWidgetId;
3992
3993 // If the widget has a configure activity, it is still needs to set it up, otherwise
3994 // the widget is ready to go.
3995 item.restoreStatus = (appWidgetInfo.configure == null)
3996 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
3997 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
3998
3999 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004000 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004001 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004002 // The widget was marked as UI not ready, but there is no configure activity to
4003 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004004 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4005 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004006 }
Sunny Goyalff572272014-07-23 13:58:07 -07004007 }
4008
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004009 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004010 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004011 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4012 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004013 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004014
Sunny Goyal56c73602015-09-25 12:55:01 -07004015 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004016 if (appWidgetInfo == null) {
4017 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07004018 deleteWidgetInfo(item);
4019 return;
4020 }
4021
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004022 item.hostView = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004023 item.minSpanX = appWidgetInfo.minSpanX;
4024 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004025 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004026 } else {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004027 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4028 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004029 view.updateIcon(mIconCache);
4030 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004031 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004032 item.hostView.setOnClickListener(this);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004033 addAppWidgetToWorkspace(item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004034 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004035 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004036
Daniel Sandler843e8602010-06-07 14:59:01 -04004037 if (DEBUG_WIDGETS) {
4038 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4039 + (SystemClock.uptimeMillis()-start) + "ms");
4040 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004041 }
4042
Sunny Goyalff572272014-07-23 13:58:07 -07004043 /**
4044 * Restores a pending widget.
4045 *
4046 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07004047 */
4048 private void completeRestoreAppWidget(final int appWidgetId) {
4049 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4050 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4051 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4052 return;
4053 }
4054
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004055 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004056 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4057
4058 mWorkspace.reinflateWidgetsIfNecessary();
4059 LauncherModel.updateItemInDatabase(this, info);
4060 }
4061
Adam Cohen1462de32012-07-24 22:34:36 -07004062 public void onPageBoundSynchronously(int page) {
4063 mSynchronouslyBoundPages.add(page);
4064 }
4065
Sunny Goyal527c7d32015-08-28 15:19:36 -07004066 @Override
4067 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4068 if (mPendingExecutor != null) {
4069 mPendingExecutor.markCompleted();
4070 }
4071 mPendingExecutor = executor;
4072 executor.attachTo(this);
4073 }
4074
4075 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4076 if (mPendingExecutor == executor) {
4077 mPendingExecutor = null;
4078 }
4079 }
4080
Joe Onorato9c1289c2009-08-17 11:03:03 -04004081 /**
4082 * Callback saying that there aren't any more items to bind.
4083 *
4084 * Implementation of the method from LauncherModel.Callbacks.
4085 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004086 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004087 Runnable r = new Runnable() {
4088 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004089 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004090 }
4091 };
4092 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004093 return;
4094 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004095 if (mSavedState != null) {
4096 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004097 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004098 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004099
Joe Onorato9c1289c2009-08-17 11:03:03 -04004100 mSavedState = null;
4101 }
4102
Adam Cohen1462de32012-07-24 22:34:36 -07004103 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004104
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004105 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004106 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004107
4108 // If we received the result of any pending adds while the loader was running (e.g. the
4109 // widget configuration forced an orientation change), process them now.
4110 if (sPendingAddItem != null) {
4111 final long screenId = completeAdd(sPendingAddItem);
4112
4113 // TODO: this moves the user to the page where the pending item was added. Ideally,
4114 // the screen would be guaranteed to exist after bind, and the page would be set through
4115 // the workspace restore process.
4116 mWorkspace.post(new Runnable() {
4117 @Override
4118 public void run() {
4119 mWorkspace.snapToScreenId(screenId);
4120 }
4121 });
4122 sPendingAddItem = null;
4123 }
4124
Sunny Goyal756adbc2015-04-16 15:20:51 -07004125 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004126
4127 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004128 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004129 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004130 }
4131
Adam Cohen3ed316a2014-07-23 18:21:20 -07004132 private void sendLoadingCompleteBroadcastIfNecessary() {
4133 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4134 String permission =
4135 getResources().getString(R.string.receive_first_load_broadcast_permission);
4136 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4137 sendBroadcast(intent, permission);
4138 SharedPreferences.Editor editor = mSharedPrefs.edit();
4139 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4140 editor.apply();
4141 }
4142 }
4143
Winson Chunga0b7e862013-09-05 16:03:15 -07004144 public boolean isAllAppsButtonRank(int rank) {
4145 if (mHotseat != null) {
4146 return mHotseat.isAllAppsButtonRank(rank);
4147 }
4148 return false;
4149 }
4150
Winson Chunga2413752012-04-03 14:22:34 -07004151 private boolean canRunNewAppsAnimation() {
4152 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004153 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4154 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004155 }
4156
Winson Chungc9168342013-06-26 14:54:55 -07004157 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004158 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004159 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4160 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004161 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004162 return bounceAnim;
4163 }
4164
Adam Cohen27772732013-11-11 14:00:56 +00004165 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004166 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004167 }
4168
Tony Wickham3a3517f2015-10-06 11:27:04 -07004169 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004170 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004171 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004172 }
4173
Tony Wickham55616cd2015-09-23 14:55:17 -07004174 public int getSearchBarHeight() {
4175 if (mLauncherCallbacks != null) {
4176 return mLauncherCallbacks.getSearchBarHeight();
4177 }
4178 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4179 }
4180
Winson Chung88fa7412015-08-03 14:25:28 -07004181 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004182 if (mSearchDropTargetBar == null) {
4183 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004184 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004185 if (mQsb != null) {
4186 mSearchDropTargetBar.removeView(mQsb);
4187 mQsb = null;
4188 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004189 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004190 }
4191
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004192 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004193 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4194 * multiple calls to bind the same list.)
4195 */
4196 @Thunk ArrayList<AppInfo> mTmpAppsList;
4197 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4198 public void run() {
4199 bindAllApplications(mTmpAppsList);
4200 mTmpAppsList = null;
4201 }
4202 };
4203
4204 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004205 * Add the icons for all apps.
4206 *
4207 * Implementation of the method from LauncherModel.Callbacks.
4208 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004209 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004210 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4211 mTmpAppsList = apps;
4212 return;
4213 }
4214
Winson Chungb745afb2015-03-02 11:51:23 -08004215 if (mAppsView != null) {
4216 mAppsView.setApps(apps);
4217 }
Adam Cohen9211d422014-10-07 18:14:53 -07004218 if (mLauncherCallbacks != null) {
4219 mLauncherCallbacks.bindAllApplications(apps);
4220 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004221 }
4222
4223 /**
4224 * A package was updated.
4225 *
4226 * Implementation of the method from LauncherModel.Callbacks.
4227 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004228 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004229 Runnable r = new Runnable() {
4230 public void run() {
4231 bindAppsUpdated(apps);
4232 }
4233 };
4234 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004235 return;
4236 }
4237
Winson Chungb745afb2015-03-02 11:51:23 -08004238 if (mAppsView != null) {
4239 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004240 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004241 }
4242
Sunny Goyal4390ace2014-10-13 11:33:11 -07004243 @Override
4244 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4245 Runnable r = new Runnable() {
4246 public void run() {
4247 bindWidgetsRestored(widgets);
4248 }
4249 };
4250 if (waitUntilResume(r)) {
4251 return;
4252 }
4253 mWorkspace.widgetsRestored(widgets);
4254 }
4255
Joe Onorato9c1289c2009-08-17 11:03:03 -04004256 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004257 * Some shortcuts were updated in the background.
4258 *
4259 * Implementation of the method from LauncherModel.Callbacks.
4260 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004261 @Override
4262 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4263 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004264 Runnable r = new Runnable() {
4265 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004266 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004267 }
4268 };
4269 if (waitUntilResume(r)) {
4270 return;
4271 }
4272
Sunny Goyal4390ace2014-10-13 11:33:11 -07004273 if (!updated.isEmpty()) {
4274 mWorkspace.updateShortcuts(updated);
4275 }
4276
4277 if (!removed.isEmpty()) {
4278 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4279 for (ShortcutInfo si : removed) {
4280 removedComponents.add(si.getTargetComponent());
4281 }
4282 mWorkspace.removeItemsByComponentName(removedComponents, user);
4283 // Notify the drag controller
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004284 mDragController.onAppsRemoved(new HashSet<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004285 }
4286 }
4287
4288 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004289 * Update the state of a package, typically related to install state.
4290 *
4291 * Implementation of the method from LauncherModel.Callbacks.
4292 */
Sunny Goyale755d462014-07-22 13:48:29 -07004293 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004294 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4295 Runnable r = new Runnable() {
4296 public void run() {
4297 bindRestoreItemsChange(updates);
4298 }
4299 };
4300 if (waitUntilResume(r)) {
4301 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004302 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004303
Sunny Goyal756adbc2015-04-16 15:20:51 -07004304 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004305 }
4306
4307 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004308 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07004309 * in addition to specific applications to remove, the reason being that
4310 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004311 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07004312 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004313 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004314 @Override
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004315 public void bindWorkspaceComponentsRemoved(
4316 final HashSet<String> packageNames, final HashSet<ComponentName> components,
4317 final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004318 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004319 public void run() {
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004320 bindWorkspaceComponentsRemoved(packageNames, components, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004321 }
Winson Chungd64d1762013-08-20 14:37:16 -07004322 };
4323 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004324 return;
4325 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004326 if (!packageNames.isEmpty()) {
4327 mWorkspace.removeItemsByPackageName(packageNames, user);
4328 }
4329 if (!components.isEmpty()) {
4330 mWorkspace.removeItemsByComponentName(components, user);
4331 }
4332 // Notify the drag controller
4333 mDragController.onAppsRemoved(packageNames, components);
Winson Chung83892cc2013-05-01 16:53:33 -07004334
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004335 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004336
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004337 @Override
4338 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
4339 Runnable r = new Runnable() {
4340 public void run() {
4341 bindAppInfosRemoved(appInfos);
4342 }
4343 };
4344 if (waitUntilResume(r)) {
4345 return;
Joe Onorato36115782010-06-17 13:28:48 -04004346 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004347
Winson Chungdf95eb12013-10-16 14:57:07 -07004348 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004349 if (mAppsView != null) {
4350 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004351 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004352 }
Joe Onoratobe386092009-11-17 17:32:16 -08004353
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004354 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004355 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004356 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004357 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004358 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004359
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004360 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004361 public void bindWidgetsModel(WidgetsModel model) {
4362 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004363 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004364 return;
4365 }
4366
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004367 if (mWidgetsView != null && model != null) {
4368 mWidgetsView.addWidgets(model);
4369 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004370 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004371 }
4372
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004373 @Override
4374 public void notifyWidgetProvidersChanged() {
4375 if (mWorkspace.getState().shouldUpdateWidget) {
4376 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4377 }
4378 }
4379
Winson Chung400438b2011-01-16 17:53:48 -08004380 private int mapConfigurationOriActivityInfoOri(int configOri) {
4381 final Display d = getWindowManager().getDefaultDisplay();
4382 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4383 switch (d.getRotation()) {
4384 case Surface.ROTATION_0:
4385 case Surface.ROTATION_180:
4386 // We are currently in the same basic orientation as the natural orientation
4387 naturalOri = configOri;
4388 break;
4389 case Surface.ROTATION_90:
4390 case Surface.ROTATION_270:
4391 // We are currently in the other basic orientation to the natural orientation
4392 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4393 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4394 break;
4395 }
4396
4397 int[] oriMap = {
4398 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4399 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4400 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4401 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4402 };
4403 // Since the map starts at portrait, we need to offset if this device's natural orientation
4404 // is landscape.
4405 int indexOffset = 0;
4406 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4407 indexOffset = 1;
4408 }
4409 return oriMap[(d.getRotation() + indexOffset) % 4];
4410 }
Adam Cohen446e9402011-09-15 18:21:21 -07004411
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004412 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004413 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004414 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004415 if (Utilities.ATLEAST_JB_MR2) {
4416 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4417 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004418 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4419 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004420 }
Winson Chung4b919f82012-05-01 10:44:08 -07004421 }
4422 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004423
Winson Chung4b919f82012-05-01 10:44:08 -07004424 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004425 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004426 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004427 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004428 } else {
4429 mHandler.postDelayed(new Runnable() {
4430 public void run() {
4431 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4432 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004433 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004434 }
Winson Chung4b919f82012-05-01 10:44:08 -07004435 }
Winson Chung400438b2011-01-16 17:53:48 -08004436 }
4437
Winson Chunge43a1e72014-01-15 10:33:02 -08004438 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004439 if (mLauncherCallbacks != null) {
4440 return mLauncherCallbacks.isLauncherPreinstalled();
4441 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004442 PackageManager pm = getPackageManager();
4443 try {
4444 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4445 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4446 return true;
4447 } else {
4448 return false;
4449 }
4450 } catch (NameNotFoundException e) {
4451 e.printStackTrace();
4452 return false;
4453 }
4454 }
4455
Adam Cohenea90f832014-05-21 15:03:34 -07004456 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004457 * To be overridden by subclasses to indicate that there is an activity to launch
4458 * before showing the standard launcher experience.
4459 */
4460 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004461 if (mLauncherCallbacks != null) {
4462 return mLauncherCallbacks.hasFirstRunActivity();
4463 }
Adam Cohen432609a2014-03-13 17:03:22 -07004464 return false;
4465 }
4466
4467 /**
4468 * To be overridden by subclasses to launch any first run activity
4469 */
4470 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004471 if (mLauncherCallbacks != null) {
4472 return mLauncherCallbacks.getFirstRunActivity();
4473 }
Adam Cohen432609a2014-03-13 17:03:22 -07004474 return null;
4475 }
4476
Winson Chunga6945242014-01-08 14:04:34 -08004477 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004478 return !ActivityManager.isRunningInTestHarness() &&
4479 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004480 }
4481
Adam Cohen4a9423d2014-03-28 14:22:31 -07004482 protected boolean hasRunFirstRunActivity() {
4483 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4484 }
4485
Adam Cohen432609a2014-03-13 17:03:22 -07004486 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004487 if (shouldRunFirstRunActivity() &&
4488 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004489 Intent firstRunIntent = getFirstRunActivity();
4490 if (firstRunIntent != null) {
4491 startActivity(firstRunIntent);
4492 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004493 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004494 }
4495 }
Adam Cohen432609a2014-03-13 17:03:22 -07004496 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004497 }
4498
4499 private void markFirstRunActivityShown() {
4500 SharedPreferences.Editor editor = mSharedPrefs.edit();
4501 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4502 editor.apply();
4503 }
4504
Adam Cohen432609a2014-03-13 17:03:22 -07004505 /**
4506 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4507 * screen that must be displayed and dismissed.
4508 */
4509 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004510 if (mLauncherCallbacks != null) {
4511 return mLauncherCallbacks.hasDismissableIntroScreen();
4512 }
Adam Cohen432609a2014-03-13 17:03:22 -07004513 return false;
4514 }
4515
4516 /**
4517 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4518 */
4519 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004520 if (mLauncherCallbacks != null) {
4521 return mLauncherCallbacks.getIntroScreen();
4522 }
Adam Cohen432609a2014-03-13 17:03:22 -07004523 return null;
4524 }
4525
4526 /**
4527 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4528 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4529 */
4530 private boolean shouldShowIntroScreen() {
4531 return hasDismissableIntroScreen() &&
4532 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4533 }
4534
4535 protected void showIntroScreen() {
4536 View introScreen = getIntroScreen();
4537 changeWallpaperVisiblity(false);
4538 if (introScreen != null) {
4539 mDragLayer.showOverlayView(introScreen);
4540 }
4541 }
4542
4543 public void dismissIntroScreen() {
4544 markIntroScreenDismissed();
4545 if (showFirstRunActivity()) {
4546 // We delay hiding the intro view until the first run activity is showing. This
4547 // avoids a blip.
4548 mWorkspace.postDelayed(new Runnable() {
4549 @Override
4550 public void run() {
4551 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004552 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004553 }
4554 }, ACTIVITY_START_DELAY);
4555 } else {
4556 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004557 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004558 }
4559 changeWallpaperVisiblity(true);
4560 }
4561
4562 private void markIntroScreenDismissed() {
4563 SharedPreferences.Editor editor = mSharedPrefs.edit();
4564 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4565 editor.apply();
4566 }
4567
Adam Cohen091440a2015-03-18 14:16:05 -07004568 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004569 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4570 // on the device, then we always show the first run cling experience (or if there is no
4571 // launcher2). Otherwise, we prompt the user upon started for migration
4572 LauncherClings launcherClings = new LauncherClings(this);
4573 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004574 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004575 if (mModel.canMigrateFromOldLauncherDb(this)) {
4576 launcherClings.showMigrationCling();
4577 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004578 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004579 }
4580 }
4581 }
4582
Winson Chunga6945242014-01-08 14:04:34 -08004583 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004584 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4585 if (mHotseat != null) mHotseat.setAlpha(1f);
4586 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004587 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4588 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004589 }
4590
4591 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004592 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4593 if (mHotseat != null) mHotseat.setAlpha(0f);
4594 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004595 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4596 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004597 }
4598
Winson Chung5ffd51d2015-06-25 11:36:50 -07004599 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004600 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004601 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004602 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004603 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004604 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004605 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4606 if (userHandle != null) {
4607 user = UserHandleCompat.fromUser(userHandle);
4608 }
4609 }
4610 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004611 }
4612
4613 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004614 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004615 if (user == null) {
4616 user = UserHandleCompat.myUserHandle();
4617 }
4618
4619 // Called from search suggestion, add the profile extra to the intent to ensure that we
4620 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004621 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004622 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004623 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004624 return null;
4625 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004626 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004627 }
4628
Winson Chung5ffd51d2015-06-25 11:36:50 -07004629 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004630 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4631 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004632 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004633 UserHandleCompat.myUserHandle());
4634 }
4635
Winson Chung5ffd51d2015-06-25 11:36:50 -07004636 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004637 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4638 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004639 mWorkspace.onExternalDragStartedWithItem(dragView);
4640 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004641 }
4642
Winson Chung5ffd51d2015-06-25 11:36:50 -07004643 protected void moveWorkspaceToDefaultScreen() {
4644 mWorkspace.moveToDefaultScreen(false);
4645 }
4646
Anjali Koppalf5d29132014-02-28 13:33:27 -08004647 @Override
4648 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004649 if (mLauncherCallbacks != null) {
4650 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4651 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004652 }
4653
Winson Chung80baf5a2010-08-09 16:03:15 -07004654 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004655 * Returns a FastBitmapDrawable with the icon, accurately sized.
4656 */
4657 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4658 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4659 d.setFilterBitmap(true);
4660 resizeIconDrawable(d);
4661 return d;
4662 }
4663
4664 /**
4665 * Resizes an icon drawable to the correct icon size.
4666 */
Winson5fbe0742015-09-30 15:33:00 -07004667 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004668 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004669 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004670 }
4671
4672 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004673 * Prints out out state for debugging.
4674 */
4675 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004676 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004677 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004678 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4679 Log.d(TAG, "mRestoring=" + mRestoring);
4680 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Joe Onoratobe386092009-11-17 17:32:16 -08004681 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004682 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004683
Daniel Sandler325dc232013-06-05 22:57:57 -04004684 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004685 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004686
4687 @Override
4688 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4689 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004690 // Dump workspace
4691 writer.println(prefix + "Workspace Items");
4692 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4693 writer.println(prefix + " Homescreen " + i);
4694
4695 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4696 for (int j = 0; j < layout.getChildCount(); j++) {
4697 Object tag = layout.getChildAt(j).getTag();
4698 if (tag != null) {
4699 writer.println(prefix + " " + tag.toString());
4700 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004701 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004702 }
Sunny Goyala1365452015-10-01 15:46:24 -07004703
4704 writer.println(prefix + " Hotseat");
4705 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4706 for (int j = 0; j < layout.getChildCount(); j++) {
4707 Object tag = layout.getChildAt(j).getTag();
4708 if (tag != null) {
4709 writer.println(prefix + " " + tag.toString());
4710 }
4711 }
4712
4713 synchronized (sDumpLogs) {
4714 writer.println();
4715 writer.println(prefix + "Debug logs");
4716 for (String log : sDumpLogs) {
4717 writer.println(prefix + " " + log);
4718 }
4719 }
4720
Adam Cohen9211d422014-10-07 18:14:53 -07004721 if (mLauncherCallbacks != null) {
4722 mLauncherCallbacks.dump(prefix, fd, writer, args);
4723 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004724 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004725
Sunny Goyala1365452015-10-01 15:46:24 -07004726 public static void addDumpLog(String tag, String log) {
4727 Log.d(tag, log);
4728 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004729 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004730 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004731 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004732 }
4733
Adam Cohen59400422014-03-05 18:07:04 -08004734 public static CustomAppWidget getCustomAppWidget(String name) {
4735 return sCustomAppWidgets.get(name);
4736 }
4737
4738 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4739 return sCustomAppWidgets;
4740 }
4741
Sunny Goyal29538332016-02-18 09:10:19 -08004742 public static List<View> getFolderContents(View icon) {
4743 if (icon instanceof FolderIcon) {
4744 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4745 } else {
4746 return Collections.EMPTY_LIST;
4747 }
4748 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004749}
Michael Jurka2763be32011-02-24 11:19:57 -08004750
Dan Sandlerd5024042014-01-09 15:01:33 -05004751interface DebugIntents {
4752 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4753 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004754}