blob: 123f657efeb803f2adc1a6078a0093cbf7df3868 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyal28c6b962015-10-12 11:42:05 -070019import android.Manifest;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070025import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Sunny Goyal756cd262015-08-20 12:33:21 -070039import android.content.ContentValues;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Sunny Goyal745bad92016-05-02 10:54:12 -070046import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Winson Chungaafa03c2010-06-11 17:34:16 -070047import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080048import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070050import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070052import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Tony Wickhama3c74d12015-10-23 11:43:47 -070056import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070057import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070059import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070060import android.graphics.drawable.Drawable;
Sunny Goyal1acb9e92016-05-16 12:41:09 -070061import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070062import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020063import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020065import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080066import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070067import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070068import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040069import android.os.SystemClock;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070070import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.Selection;
72import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070073import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070075import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Tony Wickhame2217252016-03-22 16:34:23 -070089import android.view.accessibility.AccessibilityManager;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070090import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080094import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070096
Sunny Goyal651077b2014-06-30 14:15:31 -070097import com.android.launcher3.DropTarget.DragObject;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070098import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080099import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700100import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100101import com.android.launcher3.compat.LauncherActivityInfoCompat;
102import com.android.launcher3.compat.LauncherAppsCompat;
103import com.android.launcher3.compat.UserHandleCompat;
104import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800105import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700106import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700107import com.android.launcher3.dragndrop.DragController;
108import com.android.launcher3.dragndrop.DragLayer;
109import com.android.launcher3.dragndrop.DragView;
Tony Wickham827cef22016-03-17 15:39:39 -0700110import com.android.launcher3.dynamicui.ExtractedColors;
Sunny Goyal26119432016-02-18 22:09:23 +0000111import com.android.launcher3.folder.Folder;
112import com.android.launcher3.folder.FolderIcon;
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800113import com.android.launcher3.logging.LoggerUtils;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700114import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700115import com.android.launcher3.model.WidgetsModel;
Tony Wickhamf549dab2016-05-16 09:54:06 -0700116import com.android.launcher3.pageindicators.PageIndicator;
117import com.android.launcher3.pageindicators.PageIndicatorLine;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800118import com.android.launcher3.userevent.nano.LauncherLogProto;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700119import com.android.launcher3.util.ComponentKey;
Sunny Goyal713edfc2016-05-06 09:58:34 -0700120import com.android.launcher3.logging.FileLog;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700121import com.android.launcher3.util.PackageManagerHelper;
Sunny Goyal322d5562015-06-25 19:35:49 -0700122import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700123import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700124import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700125import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700126import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700127import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700128
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700129import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700130import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700132import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800133import java.util.Collections;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700134import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700135import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700136import java.util.List;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800137import java.util.Locale;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700138
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139/**
140 * Default launcher application.
141 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100142public class Launcher extends Activity
Adam Cohen79d90c52016-04-22 13:29:20 -0700143 implements LauncherExterns, View.OnClickListener, OnLongClickListener,
144 LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener,
Tony Wickhame2217252016-03-22 16:34:23 -0700145 AccessibilityManager.AccessibilityStateChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700146 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700147 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Daniel Sandlerf061f822013-06-27 13:59:36 -0400149 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700150 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700151 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400152 static final boolean DEBUG_RESUME_TIME = false;
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700153 static final boolean DEBUG_LOGGING = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700154
Dan Sandlerd5024042014-01-09 15:01:33 -0500155 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
156
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700158 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700159 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700160 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161
Michael Jurka8b805b12012-04-18 14:23:14 -0700162 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700163 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700164
Sunny Goyal28c6b962015-10-12 11:42:05 -0700165 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
166
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700167 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
168 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
169 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
170
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700171 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
172
Mathew Inwood876a8462013-06-14 14:12:41 +0100173 /**
174 * IntentStarter uses request codes starting with this. This must be greater than all activity
175 * request codes used internally.
176 */
177 protected static final int REQUEST_LAST = 100;
178
Michael Jurka0a457bf2012-11-19 14:05:05 -0800179 // To turn on these properties, type
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700180 // adb shell setprop logTap.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800181 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182
Winson Chung2672ff92012-05-04 16:22:30 -0700183 // The Intent extra that defines whether to ignore the launch animation
184 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400185 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700186
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 // Type: int
188 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700189 // Type: int
190 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700191 // Type: Content Values / parcelable
192 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700193 // Type: parcelable
194 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000195 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800196 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
Adam Cohen432609a2014-03-13 17:03:22 -0700198 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800199 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
200
Sunny Goyal594d76d2014-11-06 10:12:54 -0800201 private static final String QSB_WIDGET_ID = "qsb_widget_id";
202 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
203
Winson Chunga6945242014-01-08 14:04:34 -0800204 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
Sunny Goyal1acb9e92016-05-16 12:41:09 -0700205 private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
Winson Chunga6945242014-01-08 14:04:34 -0800206
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700208 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
209 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700210
Adam Cohen091440a2015-03-18 14:16:05 -0700211 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700212 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700213
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700214 private boolean mIsSafeModeEnabled;
215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800217 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700218 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700219 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
Winson Chunga2413752012-04-03 14:22:34 -0700221 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700222 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
223 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700225
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800226 private final BroadcastReceiver mCloseSystemDialogsReceiver
227 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800228
Adam Cohen091440a2015-03-18 14:16:05 -0700229 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700230 private View mLauncherView;
Tony Wickhamf549dab2016-05-16 09:54:06 -0700231 private PageIndicatorLine mPageIndicator;
Adam Cohen091440a2015-03-18 14:16:05 -0700232 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800233 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700234
235 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Sunny Goyalffe83f12014-08-14 17:39:34 -0700237 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700238 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700239
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700240 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800241 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800242 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700243
Michael Jurka0280c3b2010-09-17 15:00:07 -0700244 private int[] mTmpAddItemCellCoordinates = new int[2];
245
Sunny Goyal316490e2015-06-02 09:38:28 -0700246 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800247 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700248
Michael Jurka838a4ca2011-02-07 13:33:06 -0800249 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700250 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700251
Winson Chungc51db6a2011-10-05 11:44:49 -0700252 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700253 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700254
255 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700256 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700257
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700258 // Main container view and the model for the widget tray screen.
259 @Thunk WidgetsContainerView mWidgetsView;
260 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700261
Sunny Goyal594d76d2014-11-06 10:12:54 -0800262 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700265 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
266 // scroll issues (because the workspace may not have been measured yet) and extra work.
267 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
268 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269
270 private SpannableStringBuilder mDefaultKeySsb = null;
271
Adam Cohen091440a2015-03-18 14:16:05 -0700272 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400273
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800274 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 private boolean mRestoring;
276 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700277 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278
Michael Jurka1e2f4652013-07-08 18:03:46 -0700279 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700280 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700281 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700282
Joe Onorato9c1289c2009-08-17 11:03:03 -0400283 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800284 private IconCache mIconCache;
Tony Wickham827cef22016-03-17 15:39:39 -0700285 private ExtractedColors mExtractedColors;
Adam Cohen091440a2015-03-18 14:16:05 -0700286 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800287 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700288 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800289 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290
Sunny Goyal639e9062015-08-19 19:17:06 -0700291 private LauncherClings mClings;
292
Adam Cohen61f560d2013-09-30 15:58:20 -0700293 private View.OnTouchListener mHapticFeedbackTouchListener;
294
Adam Cohended9f8d2010-11-03 13:25:16 -0700295 // Related to the auto-advancing of widgets
296 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700297 private static final int ADVANCE_INTERVAL = 20000;
298 private static final int ADVANCE_STAGGER = 250;
299
300 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700301 private long mAutoAdvanceSentTime;
302 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700303 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700304
Winson Chung400438b2011-01-16 17:53:48 -0800305 // Determines how long to wait after a rotation before restoring the screen orientation to
306 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700307 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800308
Adam Cohen091440a2015-03-18 14:16:05 -0700309 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700310
Adam Cohen1462de32012-07-24 22:34:36 -0700311 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700312 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Winson Chungf0c6ae02012-03-21 16:10:31 -0700318 // Holds the page that we need to animate to, and the icon views that we need to animate up
319 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700320 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700321 private Bitmap mFolderIconBitmap;
322 private Canvas mFolderIconCanvas;
323 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700324
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700325 private DeviceProfile mDeviceProfile;
326
Adam Cohen4b66bf32015-09-18 12:15:19 -0700327 private boolean mMoveToDefaultScreenFromNewIntent;
328
Winson Chung13eb5272015-05-11 16:30:13 -0700329 // This is set to the view that launched the activity that navigated the user away from
330 // launcher. Since there is no callback for when the activity has finished launching, enable
331 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800332 private BubbleTextView mWaitingForResume;
333
Adam Cohen59400422014-03-05 18:07:04 -0800334 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
335 new HashMap<String, CustomAppWidget>();
336
Adam Cohen59400422014-03-05 18:07:04 -0800337 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700338 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
339 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800340 }
341 }
342
Adam Cohen091440a2015-03-18 14:16:05 -0700343 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700344 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700345 if (mWorkspace != null) {
346 mWorkspace.buildPageHardwareLayers();
347 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700348 }
349 };
350
Adam Cohendb364c32014-05-20 14:23:40 -0700351 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352
Adam Cohen091440a2015-03-18 14:16:05 -0700353 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int requestCode;
355 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700356 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700357 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358 int cellX;
359 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700360 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 }
362
Hyunyoung Songaa953652016-04-19 18:30:24 -0700363 private UserEventDispatcher mUserEventDispatcher;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800364
Adam Cohenf9c184a2016-01-15 16:47:43 -0800365 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700366 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400367
368 @Thunk void setOrientation() {
369 if (mRotationEnabled) {
370 unlockScreenOrientation(true);
371 } else {
372 setRequestedOrientation(
373 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700374 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400375 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700376
Sunny Goyal745bad92016-05-02 10:54:12 -0700377 private RotationPrefChangeHandler mRotationPrefChangeHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 @Override
380 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700381 if (DEBUG_STRICT_MODE) {
382 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
383 .detectDiskReads()
384 .detectDiskWrites()
385 .detectNetwork() // or .detectAll() for all detectable problems
386 .penaltyLog()
387 .build());
388 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
389 .detectLeakedSqlLiteObjects()
390 .detectLeakedClosableObjects()
391 .penaltyLog()
392 .penaltyDeath()
393 .build());
394 }
395
Adam Cohen9211d422014-10-07 18:14:53 -0700396 if (mLauncherCallbacks != null) {
397 mLauncherCallbacks.preOnCreate();
398 }
399
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400401
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400402 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700403
Adam Cohen2e6da152015-05-06 11:42:25 -0700404 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700405 mDeviceProfile = getResources().getConfiguration().orientation
406 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700407 app.getInvariantDeviceProfile().landscapeProfile
408 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700409
Sunny Goyalf7258242015-10-19 16:59:07 -0700410 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700411 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800412 mModel = app.setLauncher(this);
413 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700414
Joe Onorato41a12d22009-10-31 18:30:00 -0400415 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700416 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700417
Sunny Goyalffe83f12014-08-14 17:39:34 -0700418 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700419
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700420 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
421 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700422
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700423 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
424 // this also ensures that any synchronous binding below doesn't re-trigger another
425 // LauncherModel load.
426 mPaused = false;
427
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200429 android.os.Debug.startMethodTracing(
430 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 }
432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700434
Tony Wickhameef44322015-10-20 13:24:36 -0700435 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
436 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700438 mDeviceProfile.layout(this);
Tony Wickham827cef22016-03-17 15:39:39 -0700439 mExtractedColors = new ExtractedColors();
440 loadExtractedColorsAndColorItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441
Tony Wickhame2217252016-03-22 16:34:23 -0700442 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
443 .addAccessibilityStateChangeListener(this);
444
Joe Onorato7c312c12009-08-13 21:36:53 -0700445 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700446
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447 mSavedState = savedInstanceState;
448 restoreState(mSavedState);
449
450 if (PROFILE_STARTUP) {
451 android.os.Debug.stopMethodTracing();
452 }
453
454 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700455 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700456 // If the user leaves launcher, then we should just load items asynchronously when
457 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700458 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700459 } else {
460 // We only load the page synchronously if the user rotates (or triggers a
461 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700462 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 }
465
466 // For handling default keys
467 mDefaultKeySsb = new SpannableStringBuilder();
468 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800469
470 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
471 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800472
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800473 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700474 // In case we are on a device with locked rotation, we should look at preferences to check
475 // if the user has specifically allowed rotation.
476 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700477 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Sunny Goyal745bad92016-05-02 10:54:12 -0700478 mRotationPrefChangeHandler = new RotationPrefChangeHandler();
479 mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700480 }
481
482 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
483 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400484 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700485
Adam Cohen9211d422014-10-07 18:14:53 -0700486 if (mLauncherCallbacks != null) {
487 mLauncherCallbacks.onCreate(savedInstanceState);
488 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700489
490 if (shouldShowIntroScreen()) {
491 showIntroScreen();
492 } else {
493 showFirstRunActivity();
494 showFirstRunClings();
495 }
Adam Cohen9211d422014-10-07 18:14:53 -0700496 }
497
Sunny Goyal7779d622015-06-11 16:18:39 -0700498 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700499 public void onExtractedColorsChanged() {
500 loadExtractedColorsAndColorItems();
501 }
502
503 private void loadExtractedColorsAndColorItems() {
Tony Wickham462b5cc2016-04-01 16:00:49 -0700504 // TODO: do this in pre-N as well, once the extraction part is complete.
505 if (mExtractedColors != null && Utilities.isNycOrAbove()) {
Tony Wickham827cef22016-03-17 15:39:39 -0700506 mExtractedColors.load(this);
Tony Wickham462b5cc2016-04-01 16:00:49 -0700507 mHotseat.updateColor(mExtractedColors, !mPaused);
Tony Wickhamf549dab2016-05-16 09:54:06 -0700508 mPageIndicator.updateColor(mExtractedColors);
Tony Wickham827cef22016-03-17 15:39:39 -0700509 }
510 }
511
Adam Cohen9211d422014-10-07 18:14:53 -0700512 private LauncherCallbacks mLauncherCallbacks;
513
514 public void onPostCreate(Bundle savedInstanceState) {
515 super.onPostCreate(savedInstanceState);
516 if (mLauncherCallbacks != null) {
517 mLauncherCallbacks.onPostCreate(savedInstanceState);
518 }
519 }
520
Sunny Goyal32554d12015-12-03 15:31:25 -0800521 /**
522 * Call this after onCreate to set or clear overlay.
523 */
524 public void setLauncherOverlay(LauncherOverlay overlay) {
525 if (overlay != null) {
526 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
527 }
528 mWorkspace.setLauncherOverlay(overlay);
529 }
530
Adam Cohen9211d422014-10-07 18:14:53 -0700531 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
532 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700533 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700534 private boolean mWorkspaceImportanceStored = false;
535 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700536 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800537 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700538 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
539
540 @Override
541 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700542 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700543 return;
544 }
545 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700546 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700547 if (mWorkspace != null) {
548 mWorkspaceImportanceForAccessibility =
549 mWorkspace.getImportantForAccessibility();
550 mWorkspace.setImportantForAccessibility(
551 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
552 mWorkspaceImportanceStored = true;
553 }
554 if (mHotseat != null) {
555 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
556 mHotseat.setImportantForAccessibility(
557 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
558 mHotseatImportanceStored = true;
559 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700560 }
561
562 @Override
563 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700564 if (mWorkspaceImportanceStored && mWorkspace != null) {
565 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
566 }
567 if (mHotseatImportanceStored && mHotseat != null) {
568 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
569 }
570 mWorkspaceImportanceStored = false;
571 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700572 }
573 });
Adam Cohen9211d422014-10-07 18:14:53 -0700574 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700575 }
576
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700577 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700578 public void onLauncherProviderChange() {
579 if (mLauncherCallbacks != null) {
580 mLauncherCallbacks.onLauncherProviderChange();
581 }
582 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700583
Adam Cohen9211d422014-10-07 18:14:53 -0700584 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700585 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700586 if (mLauncherCallbacks != null) {
587 return mLauncherCallbacks.hasCustomContentToLeft();
588 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700589 return false;
590 }
591
Dave Hawkeya8881582013-09-17 15:55:33 -0600592 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500593 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600594 * {@link #addToCustomContentPage}. This will only be invoked if
595 * {@link #hasCustomContentToLeft()} is {@code true}.
596 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500597 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700598 if (mLauncherCallbacks != null) {
599 mLauncherCallbacks.populateCustomContentContainer();
600 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600601 }
602
603 /**
604 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
605 * ensure the custom content page is added or removed if necessary.
606 */
607 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600608 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600609 // Not bound yet, wait for bindScreens to be called.
610 return;
611 }
612
613 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
614 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500615 mWorkspace.createCustomContentContainer();
616 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600617 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
618 mWorkspace.removeCustomContentPage();
619 }
620 }
621
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800622 /**
623 * Logger object is a singleton and does not have to be coupled with the foreground activity.
624 * Since most user event logging is done on the UI, the object is retrieved from the
625 * callback for convenience.
626 */
Hyunyoung Songaa953652016-04-19 18:30:24 -0700627 private UserEventDispatcher createUserEventDispatcher() {
628 return new UserEventDispatcher() {
629 @Override
630 public void dispatchUserEvent(LauncherLogProto.LauncherEvent ev, Intent intent) {
631 if (!DEBUG_LOGGING) {
632 return;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800633 }
Hyunyoung Songaa953652016-04-19 18:30:24 -0700634 Log.d("UserEvent", String.format(Locale.US,
635 "action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
636 LoggerUtils.getActionStr(ev.action),
637 LoggerUtils.getTargetStr(ev.srcTarget[0]),
638 LoggerUtils.getTargetStr(ev.srcTarget[1]),
639 ev.elapsedContainerMillis,
640 ev.elapsedSessionMillis));
641 }
642 };
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800643 }
644
Hyunyoung Songaa953652016-04-19 18:30:24 -0700645 public UserEventDispatcher getUserEventDispatcher() {
646 if (mLauncherCallbacks != null) {
647 UserEventDispatcher dispatcher = mLauncherCallbacks.getUserEventDispatcher();
648 if (dispatcher != null) {
649 return dispatcher;
650 }
651 }
652
653 if (mUserEventDispatcher == null) {
654 mUserEventDispatcher = createUserEventDispatcher();
655 }
656 return mUserEventDispatcher;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800657 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100658
Hyunyoung Song3f471442015-04-08 19:01:34 -0700659 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700660 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
661 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700662 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700663 }
664
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000665 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700666 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
667 // This cast is safe as long as the id < 0x00FFFFFF
668 // Since we jail all the dynamically generated views, there should be no clashes
669 // with any other views.
670 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000671 }
672
673 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700674 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
675 * a configuration step, this allows the proper animations to run after other transitions.
676 */
Adam Cohendb364c32014-05-20 14:23:40 -0700677 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700678 long screenId = args.screenId;
679 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
680 // When the screen id represents an actual screen (as opposed to a rank) we make sure
681 // that the drop page actually exists.
682 screenId = ensurePendingDropLayoutExists(args.screenId);
683 }
Adam Cohendb364c32014-05-20 14:23:40 -0700684
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800685 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700687 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700688 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700689 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800690 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700691 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700692 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700693 case REQUEST_RECONFIGURE_APPWIDGET:
694 completeRestoreAppWidget(args.appWidgetId);
695 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800696 }
Michael Jurka27614d22012-04-02 06:40:22 -0700697 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
698 // if you turned the screen off and then back while in All Apps, Launcher would not
699 // return to the workspace. Clearing mAddInfo.container here fixes this issue
700 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700701 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800702 }
703
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800704 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700705 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700706 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700707 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700708 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800709 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700710
Adam Cohenad4e15c2013-10-17 16:21:35 -0700711 Runnable exitSpringLoaded = new Runnable() {
712 @Override
713 public void run() {
714 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
715 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
716 }
717 };
718
Michael Jurka8b805b12012-04-18 14:23:14 -0700719 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700720 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700721 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700722 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
723 if (resultCode == RESULT_CANCELED) {
724 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700725 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700726 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700727 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800728 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700729 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700730
731 // When the user has granted permission to bind widgets, we should check to see if
732 // we can inflate the default search bar widget.
733 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700734 }
735 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200736 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
737 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700738 // User could have free-scrolled between pages before picking a wallpaper; make sure
739 // we move to the closest one now.
740 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700741 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200742 }
743 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700744 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200745
Adam Cohened66b2b2012-01-23 17:28:51 -0800746 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700747 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700748
Adam Cohendb364c32014-05-20 14:23:40 -0700749 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800750 // We have special handling for widgets
751 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800752 final int appWidgetId;
753 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
754 : -1;
755 if (widgetId < 0) {
756 appWidgetId = pendingAddWidgetId;
757 } else {
758 appWidgetId = widgetId;
759 }
760
Adam Cohenad4e15c2013-10-17 16:21:35 -0700761 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800762 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700763 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
764 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700765 result = RESULT_CANCELED;
766 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700767 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700768 @Override
769 public void run() {
770 exitSpringLoadedDragModeDelayed(false, 0, null);
771 }
772 };
Adam Cohendb364c32014-05-20 14:23:40 -0700773 if (workspaceLocked) {
774 // No need to remove the empty screen if we're mid-binding, as the
775 // the bind will not add the empty screen.
776 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
777 } else {
778 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
779 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
780 }
Winson Chung5aaab772012-04-27 15:24:02 -0700781 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700782 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700783 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
784 // When the screen id represents an actual screen (as opposed to a rank)
785 // we make sure that the drop page actually exists.
786 mPendingAddInfo.screenId =
787 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
788 }
Adam Cohendb364c32014-05-20 14:23:40 -0700789 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
790
791 dropLayout.setDropPending(true);
792 final Runnable onComplete = new Runnable() {
793 @Override
794 public void run() {
795 completeTwoStageWidgetDrop(resultCode, appWidgetId);
796 dropLayout.setDropPending(false);
797 }
798 };
799 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
800 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
801 } else {
802 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
803 mPendingAddInfo);
804 sPendingAddItem = args;
805 }
Winson Chung5aaab772012-04-27 15:24:02 -0700806 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800807 return;
808 }
809
Sunny Goyalff572272014-07-23 13:58:07 -0700810 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
811 if (resultCode == RESULT_OK) {
812 // Update the widget view.
813 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
814 pendingAddWidgetId, mPendingAddInfo);
815 if (workspaceLocked) {
816 sPendingAddItem = args;
817 } else {
818 completeAdd(args);
819 }
820 }
821 // Leave the widget in the pending state if the user canceled the configure.
822 return;
823 }
824
Sunny Goyalaad90582015-07-09 14:22:50 -0700825 if (requestCode == REQUEST_CREATE_SHORTCUT) {
826 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
827 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
828 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
829 mPendingAddInfo);
830 if (isWorkspaceLocked()) {
831 sPendingAddItem = args;
832 } else {
833 completeAdd(args);
834 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
835 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
836 }
837 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700838 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
839 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800842 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800843
844 }
845
846 @Override
847 protected void onActivityResult(
848 final int requestCode, final int resultCode, final Intent data) {
849 handleActivityResult(requestCode, resultCode, data);
850 if (mLauncherCallbacks != null) {
851 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
852 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800853 }
854
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600855 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700856 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600857 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700858 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
859 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
860 View v = null;
861 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
862 if (layout != null) {
863 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
864 }
865 Intent intent = sPendingAddItem.intent;
866 sPendingAddItem = null;
867 if (grantResults.length > 0
868 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
869 startActivity(v, intent, null);
870 } else {
871 // TODO: Show a snack bar with link to settings
872 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
873 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
874 }
875 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600876 if (mLauncherCallbacks != null) {
877 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
878 grantResults);
879 }
880 }
881
Adam Cohendb364c32014-05-20 14:23:40 -0700882 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
883 appWidgetId, ItemInfo info) {
884 PendingAddArguments args = new PendingAddArguments();
885 args.requestCode = requestCode;
886 args.intent = data;
887 args.container = info.container;
888 args.screenId = info.screenId;
889 args.cellX = info.cellX;
890 args.cellY = info.cellY;
891 args.appWidgetId = appWidgetId;
892 return args;
893 }
894
895 /**
896 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
897 *
898 * @param screenId the screen id to check
899 * @return the new screen, or screenId if it exists
900 */
901 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800902 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700903 if (dropLayout == null) {
904 // it's possible that the add screen was removed because it was
905 // empty and a re-bind occurred
906 mWorkspace.addExtraEmptyScreen();
907 return mWorkspace.commitExtraEmptyScreen();
908 } else {
909 return screenId;
910 }
911 }
912
Adam Cohen091440a2015-03-18 14:16:05 -0700913 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800914 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800915 Runnable onCompleteRunnable = null;
916 int animationType = 0;
917
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700918 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800919 if (resultCode == RESULT_OK) {
920 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
921 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700922 mPendingAddWidgetInfo);
923 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800924 onCompleteRunnable = new Runnable() {
925 @Override
926 public void run() {
927 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700928 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700929 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
930 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 }
932 };
933 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800934 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800935 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800936 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700937 if (mDragLayer.getAnimatedView() != null) {
938 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
939 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
940 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700941 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700942 // The animated view may be null in the case of a rotation during widget configuration
943 onCompleteRunnable.run();
944 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800945 }
946
947 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700948 protected void onStop() {
949 super.onStop();
950 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700951
952 if (mLauncherCallbacks != null) {
953 mLauncherCallbacks.onStop();
954 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700955 }
956
957 @Override
958 protected void onStart() {
959 super.onStart();
960 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700961
962 if (mLauncherCallbacks != null) {
963 mLauncherCallbacks.onStart();
964 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700965 }
966
967 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800968 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200969 long startTime = 0;
970 if (DEBUG_RESUME_TIME) {
971 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400972 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200973 }
Adam Cohen9211d422014-10-07 18:14:53 -0700974
975 if (mLauncherCallbacks != null) {
976 mLauncherCallbacks.preOnResume();
977 }
978
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 super.onResume();
Hyunyoung Songaa953652016-04-19 18:30:24 -0700980 getUserEventDispatcher().resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700981
Winson Chung4a2afa32012-07-19 14:53:05 -0700982 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700983 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700984 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800985 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700986 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700987 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700988 // view after launching an app, as they may be depending on the UI to be static to
989 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700990 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700991 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800992 } else if (mOnResumeState == State.WIDGETS) {
993 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700994 }
995 mOnResumeState = State.NONE;
996
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700997 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -0700998 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
999 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001000
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001001 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001002 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001003 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -07001004 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onorato9c1289c2009-08-17 11:03:03 -04001005 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001006 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001007 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001008 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001009 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1010 // execute them here
1011 long startTimeCallbacks = 0;
1012 if (DEBUG_RESUME_TIME) {
1013 startTimeCallbacks = System.currentTimeMillis();
1014 }
1015
Michael Jurka1e2f4652013-07-08 18:03:46 -07001016 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1017 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001018 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001019 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001020 if (DEBUG_RESUME_TIME) {
1021 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1022 (System.currentTimeMillis() - startTimeCallbacks));
1023 }
Michael Jurka447bf842013-05-15 14:52:15 +02001024 }
Michael Jurka54554252013-08-01 12:52:23 +02001025 if (mOnResumeCallbacks.size() > 0) {
1026 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1027 mOnResumeCallbacks.get(i).run();
1028 }
1029 mOnResumeCallbacks.clear();
1030 }
Winson Chunge4e50662012-01-23 14:45:13 -08001031
1032 // Reset the pressed state of icons that were locked in the press state while activities
1033 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001034 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001035 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001036 mWaitingForResume.setStayPressed(false);
1037 }
Winson Chung82963d52013-10-09 11:20:57 -07001038
Adam Cohen06dff352012-06-01 17:17:08 -07001039 // It is possible that widgets can receive updates while launcher is not in the foreground.
1040 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1041 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1042 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001043 if (!isWorkspaceLoading()) {
1044 getWorkspace().reinflateWidgetsIfNecessary();
1045 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001046 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001047
Michael Jurka447bf842013-05-15 14:52:15 +02001048 if (DEBUG_RESUME_TIME) {
1049 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1050 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001051
Adam Cohen4b66bf32015-09-18 12:15:19 -07001052 // We want to suppress callbacks about CustomContent being shown if we have just received
1053 // onNewIntent while the user was present within launcher. In that case, we post a call
1054 // to move the user to the main screen (which will occur after onResume). We don't want to
1055 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1056 // suppress here.
1057 if (mWorkspace.getCustomContentCallbacks() != null
1058 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001059 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001060 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001061 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1062 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001063 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001064 }
1065 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001066 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001067 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001068 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001069
Sunny Goyal756adbc2015-04-16 15:20:51 -07001070 if (!isWorkspaceLoading()) {
1071 // Process any items that were added while Launcher was away.
1072 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1073 }
Adam Cohen9211d422014-10-07 18:14:53 -07001074
1075 if (mLauncherCallbacks != null) {
1076 mLauncherCallbacks.onResume();
1077 }
Adam Cohen06dff352012-06-01 17:17:08 -07001078 }
1079
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001081 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001082 // Ensure that items added to Launcher are queued until Launcher returns
1083 InstallShortcutReceiver.enableInstallQueue();
1084
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001085 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001086 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001087 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001088 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001089
1090 // We call onHide() aggressively. The custom content callbacks should be able to
1091 // debounce excess onHide calls.
1092 if (mWorkspace.getCustomContentCallbacks() != null) {
1093 mWorkspace.getCustomContentCallbacks().onHide();
1094 }
Romain Guycbb89e42009-06-08 15:52:54 -07001095
Adam Cohen9211d422014-10-07 18:14:53 -07001096 if (mLauncherCallbacks != null) {
1097 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001098 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001099 }
1100
1101 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001102 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1103 // by a onResume or by scrolling otherwise.
1104 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001105
1106 // Custom content is completely hidden
1107 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001108
1109 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1110 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001111
1112 // Indicates whether the user is allowed to scroll away from the custom content.
1113 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001114 }
1115
Adam Cohenc2d6e892014-10-16 09:49:24 -07001116 public interface LauncherOverlay {
1117
1118 /**
1119 * Touch interaction leading to overscroll has begun
1120 */
1121 public void onScrollInteractionBegin();
1122
1123 /**
1124 * Touch interaction related to overscroll has ended
1125 */
1126 public void onScrollInteractionEnd();
1127
1128 /**
1129 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1130 * screen (or in the case of RTL, the rightmost screen).
1131 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001132 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001133
1134 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001135 * Called when the launcher is ready to use the overlay
1136 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001137 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001138 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001139 }
1140
Jun Mukai8af0cd82015-05-12 12:32:12 -07001141 public interface LauncherSearchCallbacks {
1142 /**
1143 * Called when the search overlay is shown.
1144 */
1145 public void onSearchOverlayOpened();
1146
1147 /**
1148 * Called when the search overlay is dismissed.
1149 */
1150 public void onSearchOverlayClosed();
1151 }
1152
Adam Cohenc2d6e892014-10-16 09:49:24 -07001153 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001154 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001155 }
1156
1157 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1158
Sunny Goyalc86df472016-02-25 09:19:38 -08001159 public void onScrollChanged(float progress) {
1160 if (mWorkspace != null) {
1161 mWorkspace.onOverlayScrollChanged(progress);
1162 }
1163 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001164 }
1165
Jorim Jaggid017f882014-01-14 17:08:48 -08001166 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001167 if (mLauncherCallbacks != null) {
1168 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001169 } else {
1170 // On devices with a locked orientation, we will at least have the allow rotation
1171 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001172 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001173 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001174 }
1175
Adam Cohen9211d422014-10-07 18:14:53 -07001176 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001177 CustomContentCallbacks callbacks, String description) {
1178 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001179 }
1180
Adam Cohenedb40762013-07-18 16:45:45 -07001181 // The custom content needs to offset its content to account for the QSB
1182 public int getTopOffsetForCustomContent() {
1183 return mWorkspace.getPaddingTop();
1184 }
1185
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001186 @Override
1187 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001188 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001189 if (mModel.isCurrentCallbacks(this)) {
1190 mModel.stopLoader();
1191 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001192 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1193
Romain Guy13c2e7b2010-03-10 19:45:00 -08001194 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001195 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001196
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001197 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001198 @Override
1199 public void onWindowFocusChanged(boolean hasFocus) {
1200 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001201 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001202
1203 if (mLauncherCallbacks != null) {
1204 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1205 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001206 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001207
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 private boolean acceptFilter() {
1209 final InputMethodManager inputManager = (InputMethodManager)
1210 getSystemService(Context.INPUT_METHOD_SERVICE);
1211 return !inputManager.isFullscreenMode();
1212 }
1213
1214 @Override
1215 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001216 final int uniChar = event.getUnicodeChar();
1217 final boolean handled = super.onKeyDown(keyCode, event);
1218 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1219 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1221 keyCode, event);
1222 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001223 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001224 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001225 // showSearchDialog()
1226 // If there are multiple keystrokes before the search dialog takes focus,
1227 // onSearchRequested() will be called for every keystroke,
1228 // but it is idempotent, so it's fine.
1229 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 }
1231 }
1232
Joe Onorato8a9625e2010-01-28 15:55:35 -08001233 // Eat the long press event so the keyboard doesn't come up.
1234 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1235 return true;
1236 }
1237
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 return handled;
1239 }
1240
Winson46163472015-09-22 17:31:56 -07001241 @Override
1242 public boolean onKeyUp(int keyCode, KeyEvent event) {
1243 if (keyCode == KeyEvent.KEYCODE_MENU) {
1244 // Ignore the menu key if we are currently dragging or are on the custom content screen
1245 if (!isOnCustomContent() && !mDragController.isDragging()) {
1246 // Close any open folders
1247 closeFolder();
1248
1249 // Stop resizing any widgets
1250 mWorkspace.exitWidgetResizeMode();
1251
1252 // Show the overview mode if we are on the workspace
1253 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1254 !mWorkspace.isSwitchingState()) {
1255 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001256 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001257 }
1258 }
1259 return true;
1260 }
1261 return super.onKeyUp(keyCode, event);
1262 }
1263
Karl Rosaen138a0412009-04-23 19:00:21 -07001264 private String getTypedText() {
1265 return mDefaultKeySsb.toString();
1266 }
1267
1268 private void clearTypedText() {
1269 mDefaultKeySsb.clear();
1270 mDefaultKeySsb.clearSpans();
1271 Selection.setSelection(mDefaultKeySsb, 0);
1272 }
1273
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001275 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1276 * State
1277 */
1278 private static State intToState(int stateOrdinal) {
1279 State state = State.WORKSPACE;
1280 final State[] stateValues = State.values();
1281 for (int i = 0; i < stateValues.length; i++) {
1282 if (stateValues[i].ordinal() == stateOrdinal) {
1283 state = stateValues[i];
1284 break;
1285 }
1286 }
1287 return state;
1288 }
1289
1290 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 * Restores the previous state, if it exists.
1292 *
1293 * @param savedState The previous state.
1294 */
1295 private void restoreState(Bundle savedState) {
1296 if (savedState == null) {
1297 return;
1298 }
1299
Michael Jurka883f55b2010-10-21 15:47:14 -07001300 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001301 if (state == State.APPS || state == State.WIDGETS) {
1302 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001303 }
1304
Adam Cohen21cd0022013-10-09 18:57:02 -07001305 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1306 PagedView.INVALID_RESTORE_PAGE);
1307 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001308 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 }
1310
Sunny Goyal756cd262015-08-20 12:33:21 -07001311 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1312 if (itemValues != null) {
1313 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001314 AppWidgetProviderInfo info = savedState.getParcelable(
1315 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001316 mPendingAddWidgetInfo = info == null ?
1317 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1318
Adam Cohen4637b5a2013-11-04 18:21:24 -08001319 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001320 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 mRestoring = true;
1322 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 }
1324
1325 /**
1326 * Finds all the views we need and configure them properly.
1327 */
1328 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001329 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001330
Craig Mautner360310b2012-10-26 15:13:08 -07001331 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001332 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001333 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1334 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Tony Wickhamf549dab2016-05-16 09:54:06 -07001335 mPageIndicator = (PageIndicatorLine) mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001336
Sunny Goyal784f9c32016-03-23 16:56:54 -07001337 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1338 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1339 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
Craig Mautner360310b2012-10-26 15:13:08 -07001340 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341
Winson Chung4c98d922011-05-31 16:50:48 -07001342 // Setup the drag layer
1343 mDragLayer.setup(this, dragController);
1344
Winson Chung3d503fb2011-07-13 17:25:49 -07001345 // Setup the hotseat
1346 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1347 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001348 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001349 }
1350
Winsone9f27272015-10-13 10:47:51 -07001351 // Setup the overview panel
1352 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001353
Winson Chung4c98d922011-05-31 16:50:48 -07001354 // Setup the workspace
1355 mWorkspace.setHapticFeedbackEnabled(false);
1356 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001357 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001358 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001359
Tony Wickham34d2c912015-09-11 09:27:58 -07001360 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001361 mSearchDropTargetBar = (SearchDropTargetBar)
1362 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001363 // Get the app info bar
1364 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1365 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001366
Winson Chungef7f8742015-06-04 17:18:17 -07001367 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001368 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001369 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001370 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1371 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1372 } else {
1373 mAppsView.setSearchBarController(new DefaultAppSearchController());
1374 }
Craig Mautner360310b2012-10-26 15:13:08 -07001375
Winson Chung3d503fb2011-07-13 17:25:49 -07001376 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001377 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001378 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001379 dragController.setMoveTarget(mWorkspace);
1380 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001381 if (mSearchDropTargetBar != null) {
1382 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001383 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001384 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001385 if (mAppInfoDropTargetBar != null) {
1386 mAppInfoDropTargetBar.setup(this, dragController);
1387 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001388
Sunny Goyal322d5562015-06-25 19:35:49 -07001389 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1390 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001391 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001392 }
1393
Winsone9f27272015-10-13 10:47:51 -07001394 private void setupOverviewPanel() {
1395 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1396
1397 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1398 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1399 @Override
1400 public boolean onLongClick(View v) {
1401 return v.performClick();
1402 }
1403 };
1404
1405 // Bind wallpaper button actions
1406 View wallpaperButton = findViewById(R.id.wallpaper_button);
1407 wallpaperButton.setOnClickListener(new OnClickListener() {
1408 @Override
1409 public void onClick(View view) {
1410 if (!mWorkspace.isSwitchingState()) {
1411 onClickWallpaperPicker(view);
1412 }
1413 }
1414 });
1415 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1416 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1417
1418 // Bind widget button actions
1419 mWidgetsButton = findViewById(R.id.widget_button);
1420 mWidgetsButton.setOnClickListener(new OnClickListener() {
1421 @Override
1422 public void onClick(View view) {
1423 if (!mWorkspace.isSwitchingState()) {
1424 onClickAddWidgetButton(view);
1425 }
1426 }
1427 });
1428 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1429 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1430
1431 // Bind settings actions
1432 View settingsButton = findViewById(R.id.settings_button);
1433 boolean hasSettings = hasSettings();
1434 if (hasSettings) {
1435 settingsButton.setOnClickListener(new OnClickListener() {
1436 @Override
1437 public void onClick(View view) {
1438 if (!mWorkspace.isSwitchingState()) {
1439 onClickSettingsButton(view);
1440 }
1441 }
1442 });
1443 settingsButton.setOnLongClickListener(performClickOnLongClick);
1444 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1445 } else {
1446 settingsButton.setVisibility(View.GONE);
1447 }
1448
1449 mOverviewPanel.setAlpha(0f);
1450 }
1451
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001453 * Sets the all apps button. This method is called from {@link Hotseat}.
1454 */
1455 public void setAllAppsButton(View allAppsButton) {
1456 mAllAppsButton = allAppsButton;
1457 }
1458
1459 public View getAllAppsButton() {
1460 return mAllAppsButton;
1461 }
1462
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001463 public View getWidgetsButton() {
1464 return mWidgetsButton;
1465 }
1466
Anjali Koppal5ad44842014-03-10 20:34:39 -07001467 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 * Creates a view representing a shortcut.
1469 *
1470 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001472 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001473 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
1475
1476 /**
1477 * Creates a view representing a shortcut inflated from the specified resource.
1478 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 * @param parent The group the shortcut belongs to.
1480 * @param info The data structure describing the shortcut.
1481 *
1482 * @return A View inflated from layoutResId.
1483 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001484 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001485 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001486 parent, false);
1487 favorite.applyFromShortcutInfo(info, mIconCache);
1488 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001490 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 return favorite;
1492 }
1493
1494 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001495 * Add a shortcut to the workspace.
1496 *
1497 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001499 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001500 int cellY) {
1501 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001502 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001503
Sunny Goyal5c97f512015-05-19 16:03:28 -07001504 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001505 if (info == null) {
1506 return;
1507 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001508 final View view = createShortcut(info);
1509
Sunny Goyal5c97f512015-05-19 16:03:28 -07001510 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001511 // First we check if we already know the exact location where we want to add this item.
1512 if (cellX >= 0 && cellY >= 0) {
1513 cellXY[0] = cellX;
1514 cellXY[1] = cellY;
1515 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001516
1517 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001518 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001519 true, null,null)) {
1520 return;
1521 }
1522 DragObject dragObject = new DragObject();
1523 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001524 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1525 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001526 return;
1527 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001528 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001529 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001530 }
1531
1532 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001533 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001534 return;
1535 }
1536
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001537 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538
1539 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001540 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001541 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 }
1543 }
1544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001546 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001548 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 */
Adam Cohen091440a2015-03-18 14:16:05 -07001550 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001551 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1552
1553 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001554 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001555 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001556 }
Romain Guycbb89e42009-06-08 15:52:54 -07001557
Adam Cohen59400422014-03-05 18:07:04 -08001558 if (appWidgetInfo.isCustomWidget) {
1559 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001560 }
1561
Adam Cohen59400422014-03-05 18:07:04 -08001562 LauncherAppWidgetInfo launcherInfo;
1563 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1564 launcherInfo.spanX = info.spanX;
1565 launcherInfo.spanY = info.spanY;
1566 launcherInfo.minSpanX = info.minSpanX;
1567 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001568 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001569
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001571 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572
1573 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001574 if (hostView == null) {
1575 // Perform actual inflation because we're live
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001576 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001577 }
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001578 hostView.setVisibility(View.VISIBLE);
1579 addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001581 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001582 }
Romain Guycbb89e42009-06-08 15:52:54 -07001583
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001584 private void addAppWidgetToWorkspace(
1585 AppWidgetHostView hostView, LauncherAppWidgetInfo item,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001586 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001587 hostView.setTag(item);
1588 item.onBindAppWidget(this, hostView);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001589
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001590 hostView.setFocusable(true);
1591 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001592
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001593 mWorkspace.addInScreen(hostView, item.container, item.screenId,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001594 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1595
1596 if (!item.isCustomWidget()) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001597 addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001598 }
1599 }
1600
Adam Cohended9f8d2010-11-03 13:25:16 -07001601 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1602 @Override
1603 public void onReceive(Context context, Intent intent) {
1604 final String action = intent.getAction();
1605 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1606 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001607 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001608 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001609
Winson Chungc100e8e2011-08-09 16:02:43 -07001610 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001611 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001612 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001613 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001614 if (!showWorkspace(false)) {
1615 // If we are already on the workspace, then manually reset all apps
1616 mAppsView.reset();
1617 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001618 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001619 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1620 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001621 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001622 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1623 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001624 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001625 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1626 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1627 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001628 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001629 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1630 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001631 }
1632 }
1633 };
1634
1635 @Override
1636 public void onAttachedToWindow() {
1637 super.onAttachedToWindow();
1638
1639 // Listen for broadcasts related to user-presence
1640 final IntentFilter filter = new IntentFilter();
1641 filter.addAction(Intent.ACTION_SCREEN_OFF);
1642 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001643 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001644 if (ENABLE_DEBUG_INTENTS) {
1645 filter.addAction(DebugIntents.DELETE_DATABASE);
1646 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1647 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001649 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001650 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001651 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001652
1653 if (mLauncherCallbacks != null) {
1654 mLauncherCallbacks.onAttachedToWindow();
1655 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001656 }
1657
1658 @Override
1659 public void onDetachedFromWindow() {
1660 super.onDetachedFromWindow();
1661 mVisible = false;
1662
Adam Cohend113e0c2010-11-11 10:48:05 -08001663 if (mAttached) {
1664 unregisterReceiver(mReceiver);
1665 mAttached = false;
1666 }
Winson Chungb745afb2015-03-02 11:51:23 -08001667 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001668
1669 if (mLauncherCallbacks != null) {
1670 mLauncherCallbacks.onDetachedFromWindow();
1671 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001672 }
1673
1674 public void onWindowVisibilityChanged(int visibility) {
1675 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001676 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001677 // The following code used to be in onResume, but it turns out onResume is called when
1678 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1679 // is a more appropriate event to handle
1680 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001681 if (!mWorkspaceLoading) {
1682 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001683 // We want to let Launcher draw itself at least once before we force it to build
1684 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001685 // apps is nice and speedy.
1686 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001687 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001688 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001689 if (mStarted) return;
1690 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001691 // We delay the layer building a bit in order to give
1692 // other message processing a time to run. In particular
1693 // this avoids a delay in hiding the IME if it was
1694 // currently shown, because doing that may involve
1695 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001696 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001697 final ViewTreeObserver.OnDrawListener listener = this;
1698 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001699 public void run() {
1700 if (mWorkspace != null &&
1701 mWorkspace.getViewTreeObserver() != null) {
1702 mWorkspace.getViewTreeObserver().
1703 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001704 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001705 }
1706 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001707 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001708 }
1709 });
1710 }
1711 clearTypedText();
1712 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001713 }
1714
Adam Cohen091440a2015-03-18 14:16:05 -07001715 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001716 mHandler.removeMessages(ADVANCE_MSG);
1717 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1718 mHandler.sendMessageDelayed(msg, delay);
1719 mAutoAdvanceSentTime = System.currentTimeMillis();
1720 }
1721
Adam Cohen091440a2015-03-18 14:16:05 -07001722 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001723 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1724 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1725 mAutoAdvanceRunning = autoAdvanceRunning;
1726 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001727 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 sendAdvanceMessage(delay);
1729 } else {
1730 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001731 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001732 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1733 }
1734 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001735 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001736 }
1737 }
1738 }
1739
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001740 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1741
Adam Cohended9f8d2010-11-03 13:25:16 -07001742 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001743 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 if (msg.what == ADVANCE_MSG) {
1745 int i = 0;
1746 for (View key: mWidgetsToAdvance.keySet()) {
1747 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001748 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001749 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001750 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 public void run() {
1752 ((Advanceable) v).advance();
1753 }
1754 }, delay);
1755 }
1756 i++;
1757 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001758 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001760 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001762 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001763
Winsonc0b52fe2015-09-09 16:38:15 -07001764 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001765 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001766 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1767 if (v instanceof Advanceable) {
1768 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001769 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001770 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001771 }
1772 }
1773
Winsonc0b52fe2015-09-09 16:38:15 -07001774 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001775 if (mWidgetsToAdvance.containsKey(hostView)) {
1776 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001777 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001778 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001779 }
1780
Hyunyoung Song3f471442015-04-08 19:01:34 -07001781 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001782 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1783 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001784 }
1785
Winson Chunga6945242014-01-08 14:04:34 -08001786 public DragLayer getDragLayer() {
1787 return mDragLayer;
1788 }
1789
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001790 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001791 return mAppsView;
1792 }
1793
Hyunyoung Song3f471442015-04-08 19:01:34 -07001794 public WidgetsContainerView getWidgetsView() {
1795 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001796 }
1797
Winson Chunga6945242014-01-08 14:04:34 -08001798 public Workspace getWorkspace() {
1799 return mWorkspace;
1800 }
1801
1802 public Hotseat getHotseat() {
1803 return mHotseat;
1804 }
1805
Jorim Jaggid017f882014-01-14 17:08:48 -08001806 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001807 return mOverviewPanel;
1808 }
1809
Winson Chung006ee262015-08-03 14:40:11 -07001810 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001811 return mSearchDropTargetBar;
1812 }
1813
Tony Wickham34d2c912015-09-11 09:27:58 -07001814 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1815 return mAppInfoDropTargetBar;
1816 }
1817
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001818 public LauncherAppWidgetHost getAppWidgetHost() {
1819 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
Romain Guycbb89e42009-06-08 15:52:54 -07001821
Winson Chunga9abd0e2010-10-27 17:18:37 -07001822 public LauncherModel getModel() {
1823 return mModel;
1824 }
1825
Adam Cohen79d90c52016-04-22 13:29:20 -07001826 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001827 return mSharedPrefs;
1828 }
1829
Adam Cohen2e6da152015-05-06 11:42:25 -07001830 public DeviceProfile getDeviceProfile() {
1831 return mDeviceProfile;
1832 }
1833
Bjorn Bringertc459e522013-06-07 19:36:01 +01001834 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001835 getWindow().closeAllPanels();
1836
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001837 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001838 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001839 }
1840
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001841 @Override
1842 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001843 long startTime = 0;
1844 if (DEBUG_RESUME_TIME) {
1845 startTime = System.currentTimeMillis();
1846 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 super.onNewIntent(intent);
1848
1849 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001850 Folder openFolder = mWorkspace.getOpenFolder();
1851 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1852 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1853 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1854 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1855 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001856 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001857 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001858
Adam Cohen6fecd412013-10-02 17:41:50 -07001859 if (mWorkspace == null) {
1860 // Can be cases where mWorkspace is null, this prevents a NPE
1861 return;
1862 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001863 // In all these cases, only animate if we're already on home
1864 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001865
Sunny Goyal935fca12015-10-13 10:19:01 -07001866 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001867 exitSpringLoadedDragMode();
1868
1869 // If we are already on home, then just animate back to the workspace,
1870 // otherwise, just wait until onResume to set the state back to Workspace
1871 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001872 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001873 } else {
1874 mOnResumeState = State.WORKSPACE;
1875 }
1876
1877 final View v = getWindow().peekDecorView();
1878 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001879 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001880 INPUT_METHOD_SERVICE);
1881 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1882 }
1883
Winson Chungb745afb2015-03-02 11:51:23 -08001884 // Reset the apps view
1885 if (!alreadyOnHome && mAppsView != null) {
1886 mAppsView.scrollToTop();
1887 }
1888
Hyunyoung Song3f471442015-04-08 19:01:34 -07001889 // Reset the widgets view
1890 if (!alreadyOnHome && mWidgetsView != null) {
1891 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001892 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001893
Adam Cohen9211d422014-10-07 18:14:53 -07001894 if (mLauncherCallbacks != null) {
1895 mLauncherCallbacks.onHomeIntent();
1896 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 }
Adam Cohened307df2013-10-02 09:37:31 -07001898
Adam Cohen9211d422014-10-07 18:14:53 -07001899 if (mLauncherCallbacks != null) {
1900 mLauncherCallbacks.onNewIntent(intent);
1901 }
Winson15f8b172015-08-19 11:02:39 -07001902
1903 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1904 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1905 // animation.
1906 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001907 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1908 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001909 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1910 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001911
1912 // We use this flag to suppress noisy callbacks above custom content state
1913 // from onResume.
1914 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001915 mWorkspace.post(new Runnable() {
1916 @Override
1917 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001918 if (mWorkspace != null) {
1919 mWorkspace.moveToDefaultScreen(true);
1920 }
Winson15f8b172015-08-19 11:02:39 -07001921 }
1922 });
1923 }
1924 }
1925
1926 if (DEBUG_RESUME_TIME) {
1927 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1928 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001929 }
1930
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001932 public void onRestoreInstanceState(Bundle state) {
1933 super.onRestoreInstanceState(state);
1934 for (int page: mSynchronouslyBoundPages) {
1935 mWorkspace.restoreInstanceStateForChild(page);
1936 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001937 }
1938
1939 @Override
1940 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001941 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001942 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1943 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001944 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001945 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946
Michael Jurka883f55b2010-10-21 15:47:14 -07001947 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001948 // We close any open folder since it will not be re-opened, and we need to make sure
1949 // this state is reflected.
1950 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1951 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952
Adam Cohendcd297f2013-06-18 13:13:40 -07001953 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001954 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001955 ContentValues itemValues = new ContentValues();
1956 mPendingAddInfo.writeToValues(itemValues);
1957 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001958 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001959 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960 }
1961
Adam Cohen9211d422014-10-07 18:14:53 -07001962 if (mLauncherCallbacks != null) {
1963 mLauncherCallbacks.onSaveInstanceState(outState);
1964 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965 }
1966
1967 @Override
1968 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001970
Winson Chunge7a03942011-08-05 15:05:12 -07001971 // Remove all pending runnables
1972 mHandler.removeMessages(ADVANCE_MSG);
1973 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001974 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001975 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001976
Winson Chungcd2b0142011-06-08 16:02:26 -07001977 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001978 // It's possible to receive onDestroy after a new Launcher activity has
1979 // been created. In this case, don't interfere with the new Launcher.
1980 if (mModel.isCurrentCallbacks(this)) {
1981 mModel.stopLoader();
Sunny Goyald365ed62016-02-12 09:44:03 -08001982 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001983 }
Winson Chungcd2b0142011-06-08 16:02:26 -07001984
Sunny Goyal745bad92016-05-02 10:54:12 -07001985 if (mRotationPrefChangeHandler != null) {
1986 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
1987 }
1988
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001990 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001992 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001994 mAppWidgetHost = null;
1995
1996 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997
1998 TextKeyListener.getInstance().release();
1999
Tony Wickhame2217252016-03-22 16:34:23 -07002000 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
2001 .removeAccessibilityStateChangeListener(this);
2002
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002003 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002004
Michael Jurka2ecf9952012-06-18 12:52:28 -07002005 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002006
2007 if (mLauncherCallbacks != null) {
2008 mLauncherCallbacks.onDestroy();
2009 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 }
2011
Adam Cohena9cf38f2011-05-02 15:36:58 -07002012 public DragController getDragController() {
2013 return mDragController;
2014 }
2015
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002016 @Override
2017 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002018 onStartForResult(requestCode);
2019 super.startActivityForResult(intent, requestCode);
2020 }
2021
2022 @Override
2023 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2024 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2025 onStartForResult(requestCode);
2026 try {
2027 super.startIntentSenderForResult(intent, requestCode,
2028 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2029 } catch (IntentSender.SendIntentException e) {
2030 throw new ActivityNotFoundException();
2031 }
2032 }
2033
2034 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002035 if (requestCode >= 0) {
2036 setWaitingForResult(true);
2037 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 }
2039
Winson Chung70d72102011-08-12 11:24:35 -07002040 /**
2041 * Indicates that we want global search for this activity by setting the globalSearch
2042 * argument for {@link #startSearch} to true.
2043 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002045 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002047
Karl Rosaen138a0412009-04-23 19:00:21 -07002048 if (initialQuery == null) {
2049 // Use any text typed in the launcher as the initial query
2050 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002051 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 if (appSearchData == null) {
2053 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002054 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 }
Winson Chungadf0c182012-08-23 14:59:07 -07002056 Rect sourceBounds = new Rect();
2057 if (mSearchDropTargetBar != null) {
2058 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2059 }
Romain Guycbb89e42009-06-08 15:52:54 -07002060
Ian Parkinson047036e2014-09-01 15:40:53 +01002061 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002062 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002063 if (clearTextImmediately) {
2064 clearTypedText();
2065 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002066
2067 // We need to show the workspace after starting the search
2068 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002069 }
2070
Ian Parkinson047036e2014-09-01 15:40:53 +01002071 /**
2072 * Start a text search.
2073 *
2074 * @return {@code true} if the search will start immediately, so any further keypresses
2075 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2076 * to buffer keypresses.
2077 */
2078 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002079 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002080 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2081 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2082 sourceBounds);
2083 }
2084
Michael Jurkaa33411c2012-06-14 16:18:21 -07002085 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002086 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002087 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002088 }
2089
2090 /**
2091 * Starts the global search activity. This code is a copied from SearchManager
2092 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002093 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002094 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002095 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002096 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2097 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2098 if (globalSearchActivity == null) {
2099 Log.w(TAG, "No global search activity found.");
2100 return;
2101 }
2102 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2103 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2104 intent.setComponent(globalSearchActivity);
2105 // Make sure that we have a Bundle to put source in
2106 if (appSearchData == null) {
2107 appSearchData = new Bundle();
2108 } else {
2109 appSearchData = new Bundle(appSearchData);
2110 }
Adam Cohen9211d422014-10-07 18:14:53 -07002111 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002112 if (!appSearchData.containsKey("source")) {
2113 appSearchData.putString("source", getPackageName());
2114 }
2115 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2116 if (!TextUtils.isEmpty(initialQuery)) {
2117 intent.putExtra(SearchManager.QUERY, initialQuery);
2118 }
2119 if (selectInitialQuery) {
2120 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2121 }
2122 intent.setSourceBounds(sourceBounds);
2123 try {
2124 startActivity(intent);
2125 } catch (ActivityNotFoundException ex) {
2126 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2127 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 }
2129
Yura4f93ec62014-02-04 14:15:21 +00002130 public boolean isOnCustomContent() {
2131 return mWorkspace.isOnOrMovingToCustomContent();
2132 }
2133
Winson Chung70d72102011-08-12 11:24:35 -07002134 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002135 public boolean onPrepareOptionsMenu(Menu menu) {
2136 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002137 if (mLauncherCallbacks != null) {
2138 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2139 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002140 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002141 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002143 @Override
2144 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002145 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002146 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002147 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002148 }
2149
Joe Onorato9c1289c2009-08-17 11:03:03 -04002150 public boolean isWorkspaceLocked() {
2151 return mWorkspaceLoading || mWaitingForResult;
2152 }
2153
Adam Cohen517a7f52014-03-01 12:12:59 -08002154 public boolean isWorkspaceLoading() {
2155 return mWorkspaceLoading;
2156 }
2157
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002158 private void setWorkspaceLoading(boolean value) {
2159 boolean isLocked = isWorkspaceLocked();
2160 mWorkspaceLoading = value;
2161 if (isLocked != isWorkspaceLocked()) {
2162 onWorkspaceLockedChanged();
2163 }
2164 }
2165
2166 private void setWaitingForResult(boolean value) {
2167 boolean isLocked = isWorkspaceLocked();
2168 mWaitingForResult = value;
2169 if (isLocked != isWorkspaceLocked()) {
2170 onWorkspaceLockedChanged();
2171 }
2172 }
2173
Adam Cohen9211d422014-10-07 18:14:53 -07002174 protected void onWorkspaceLockedChanged() {
2175 if (mLauncherCallbacks != null) {
2176 mLauncherCallbacks.onWorkspaceLockedChanged();
2177 }
2178 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002179
Michael Jurka0280c3b2010-09-17 15:00:07 -07002180 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002181 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002182 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002183 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2184 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002185 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002186 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002187
Tony Wickhama0628cc2015-10-14 15:23:04 -07002188 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002189 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002190 if (LOGD) {
2191 Log.d(TAG, "Adding widget from drop");
2192 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002193 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2194 }
2195
Sunny Goyale6b63a32015-01-16 16:14:29 -08002196 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002197 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2198 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002199 if (appWidgetInfo.configure != null) {
2200 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002201 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002202
Bjorn Bringert7984c942009-12-09 15:38:25 +00002203 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002204 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2205 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2206
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002207 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002208 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002209 Runnable onComplete = new Runnable() {
2210 @Override
2211 public void run() {
2212 // Exit spring loaded mode if necessary after adding the widget
2213 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2214 null);
2215 }
2216 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002217 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002218 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002219 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002220 }
2221 }
Romain Guycbb89e42009-06-08 15:52:54 -07002222
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002223 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002224 // Close any folders that may be open.
2225 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002226 mWorkspace.moveToCustomContentScreen(animate);
2227 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002228
2229 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2230 int[] cell, int spanX, int spanY) {
2231 switch (info.itemType) {
2232 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2233 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2234 int span[] = new int[2];
2235 span[0] = spanX;
2236 span[1] = spanY;
2237 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2238 container, screenId, cell, span);
2239 break;
2240 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2241 processShortcutFromDrop(info.componentName, container, screenId, cell);
2242 break;
2243 default:
2244 throw new IllegalStateException("Unknown item type: " + info.itemType);
2245 }
2246 }
2247
Adam Cohenfbba09b2011-07-18 21:43:05 -07002248 /**
2249 * Process a shortcut drop.
2250 *
2251 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002254 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002255 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2256 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002257 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002258 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002259 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002260
2261 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002262 mPendingAddInfo.cellX = cell[0];
2263 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002265
2266 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2267 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002268 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002269 }
2270
Adam Cohenfbba09b2011-07-18 21:43:05 -07002271 /**
2272 * Process a widget drop.
2273 *
2274 * @param info The PendingAppWidgetInfo of the widget being added.
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 addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2279 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002280 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002282 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002283 mPendingAddInfo.minSpanX = info.minSpanX;
2284 mPendingAddInfo.minSpanY = info.minSpanY;
2285
Adam Cohenfbba09b2011-07-18 21:43:05 -07002286 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002287 mPendingAddInfo.cellX = cell[0];
2288 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002289 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002290 if (span != null) {
2291 mPendingAddInfo.spanX = span[0];
2292 mPendingAddInfo.spanY = span[1];
2293 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002294
Adam Cohened66b2b2012-01-23 17:28:51 -08002295 AppWidgetHostView hostView = info.boundWidget;
2296 int appWidgetId;
2297 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002298 // In the case where we've prebound the widget, we remove it from the DragLayer
2299 if (LOGD) {
2300 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2301 }
2302 getDragLayer().removeView(hostView);
2303
Adam Cohened66b2b2012-01-23 17:28:51 -08002304 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002305 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002306
2307 // Clear the boundWidget so that it doesn't get destroyed.
2308 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002309 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002310 // In this case, we either need to start an activity to get permission to bind
2311 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002312 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002313 Bundle options = info.bindOptions;
2314
Sunny Goyalffe83f12014-08-14 17:39:34 -07002315 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2316 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002317 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002318 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002319 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002320 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002321 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2322 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2323 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002324 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2325 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002326 // TODO: we need to make sure that this accounts for the options bundle.
2327 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002328 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2329 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002330 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002331 }
2332
Adam Cohendcd297f2013-06-18 13:13:40 -07002333 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002334 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002335 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 folderInfo.title = getText(R.string.folder_name);
2337
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002339 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2340 cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341
2342 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002343 FolderIcon newFolder =
2344 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002345 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002346 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002347 // Force measure the new folder icon
2348 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2349 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002350 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002351 }
Romain Guycbb89e42009-06-08 15:52:54 -07002352
Winsonc0b52fe2015-09-09 16:38:15 -07002353 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002354 * Unbinds the view for the specified item, and removes the item and all its children.
2355 *
2356 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002357 * @param itemInfo the {@link ItemInfo} for this view.
2358 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002359 */
Winson2949fb52015-09-24 09:56:11 -07002360 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002361 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002362 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07002363 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
2364 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07002365 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07002366 } else {
2367 mWorkspace.removeWorkspaceItem(v);
2368 }
Winsonc0b52fe2015-09-09 16:38:15 -07002369 if (deleteFromDb) {
2370 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2371 }
2372 } else if (itemInfo instanceof FolderInfo) {
2373 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07002374 if (v instanceof FolderIcon) {
2375 ((FolderIcon) v).removeListeners();
2376 }
Winsonc0b52fe2015-09-09 16:38:15 -07002377 mWorkspace.removeWorkspaceItem(v);
2378 if (deleteFromDb) {
2379 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2380 }
2381 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2382 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002383 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07002384 removeWidgetToAutoAdvance(v);
Winsonc0b52fe2015-09-09 16:38:15 -07002385 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002386 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002387 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002388
Winsonc0b52fe2015-09-09 16:38:15 -07002389 } else {
2390 return false;
2391 }
2392 return true;
2393 }
2394
2395 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002396 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002397 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002398 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002399 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002400 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002401 // Deleting an app widget ID is a void call but writes to disk before returning
2402 // to the caller...
2403 new AsyncTask<Void, Void, Void>() {
2404 public Void doInBackground(Void ... args) {
2405 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2406 return null;
2407 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002408 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002409 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002410 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002411 }
2412
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002413 @Override
2414 public boolean dispatchKeyEvent(KeyEvent event) {
2415 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2416 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002417 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002418 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002419 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002420 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002421 dumpState();
2422 return true;
2423 }
2424 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002425 }
2426 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2427 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002428 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 return true;
2430 }
2431 }
2432
2433 return super.dispatchKeyEvent(event);
2434 }
2435
Joe Onorato88ec0992009-11-19 13:16:06 -08002436 @Override
2437 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002438 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2439 return;
2440 }
2441
Sunny Goyal45478022015-06-08 16:52:41 -07002442 if (mDragController.isDragging()) {
2443 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002444 return;
2445 }
2446
Winson Chungb745afb2015-03-02 11:51:23 -08002447 if (isAppsViewVisible()) {
2448 showWorkspace(true);
2449 } else if (isWidgetsViewVisible()) {
2450 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002451 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002452 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002453 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002454 Folder openFolder = mWorkspace.getOpenFolder();
2455 if (openFolder.isEditingName()) {
2456 openFolder.dismissEditingName();
2457 } else {
2458 closeFolder();
2459 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002460 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002461 mWorkspace.exitWidgetResizeMode();
2462
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002463 // Back button is a no-op here, but give at least some feedback for the button press
2464 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002465 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002466 }
2467
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002468 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002469 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002470 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002471 @Override
2472 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002473 if (mAppWidgetHost != null) {
2474 mAppWidgetHost.startListening();
2475 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002476
2477 // Recreate the QSB, as the widget has been reset.
2478 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002479 }
2480
2481 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002482 * Launches the intent referred by the clicked shortcut.
2483 *
2484 * @param v The view representing the clicked shortcut.
2485 */
2486 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002487 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2488 // view has detached (it's possible for this to happen if the view is removed mid touch).
2489 if (v.getWindowToken() == null) {
2490 return;
2491 }
2492
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002493 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002494 return;
2495 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002496
Adam Cohen1697b792013-09-17 19:08:21 -07002497 if (v instanceof Workspace) {
2498 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002499 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002500 }
2501 return;
2502 }
2503
2504 if (v instanceof CellLayout) {
2505 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002506 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2507 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002508 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002509 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002510 }
2511
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002512 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002513 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002514 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002515 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002516 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002517 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002518 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002519 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002520 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002521 } else if (tag instanceof AppInfo) {
2522 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002523 } else if (tag instanceof LauncherAppWidgetInfo) {
2524 if (v instanceof PendingAppWidgetHostView) {
2525 onClickPendingWidget((PendingAppWidgetHostView) v);
2526 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002527 }
2528 }
2529
Sunny Goyal70660032015-05-14 00:07:08 -07002530 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002531 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002532 return false;
2533 }
2534
Michael Jurkaaf442092010-06-10 17:01:57 -07002535 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002536 * Event handler for the app widget view which has not fully restored.
2537 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002538 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002539 if (mIsSafeModeEnabled) {
2540 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2541 return;
2542 }
2543
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002544 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002545 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002546 int widgetId = info.appWidgetId;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002547 LauncherAppWidgetProviderInfo appWidgetInfo =
2548 mAppWidgetManager.getLauncherAppWidgetInfo(widgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002549 if (appWidgetInfo != null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002550 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002551 mPendingAddInfo.copyFrom(info);
2552 mPendingAddWidgetId = widgetId;
2553
Sunny Goyalffe83f12014-08-14 17:39:34 -07002554 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2555 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002556 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002557 } else if (info.installProgress < 0) {
2558 // The install has not been queued
2559 final String packageName = info.providerName.getPackageName();
2560 showBrokenAppInstallDialog(packageName,
2561 new DialogInterface.OnClickListener() {
2562 public void onClick(DialogInterface dialog, int id) {
2563 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2564 }
2565 });
2566 } else {
2567 // Download has started.
2568 final String packageName = info.providerName.getPackageName();
2569 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002570 }
2571 }
2572
2573 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002574 * Event handler for the "grid" button that appears on the home screen, which
2575 * enters all apps mode.
2576 *
2577 * @param v The view that was clicked.
2578 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002579 protected void onClickAllAppsButton(View v) {
2580 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002581 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002582 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002583 true /* updatePredictedApps */, false /* focusSearchBar */);
2584 }
2585 }
2586
2587 protected void onLongClickAllAppsButton(View v) {
2588 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2589 if (!isAppsViewVisible()) {
2590 showAppsView(true /* animated */, false /* resetListToTop */,
2591 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002592 }
2593 }
2594
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002595 private void showBrokenAppInstallDialog(final String packageName,
2596 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002597 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002598 .setTitle(R.string.abandoned_promises_title)
2599 .setMessage(R.string.abandoned_promise_explanation)
2600 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2601 .setNeutralButton(R.string.abandoned_clean_this,
2602 new DialogInterface.OnClickListener() {
2603 public void onClick(DialogInterface dialog, int id) {
2604 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2605 mWorkspace.removeAbandonedPromise(packageName, user);
2606 }
2607 })
2608 .create().show();
2609 return;
2610 }
2611
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002612 /**
2613 * Event handler for an app shortcut click.
2614 *
2615 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2616 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002617 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002618 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2619 Object tag = v.getTag();
2620 if (!(tag instanceof ShortcutInfo)) {
2621 throw new IllegalArgumentException("Input must be a Shortcut");
2622 }
2623
2624 // Open shortcut
2625 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002626
2627 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002628 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2629 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002630 // Launch activity anyway, framework will tell the user why the app is suspended.
2631 } else {
2632 int error = R.string.activity_not_available;
2633 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2634 error = R.string.safemode_shortcut_error;
2635 }
2636 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2637 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002638 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002639 }
2640
Chris Wren40c5ed32014-06-24 18:24:23 -04002641 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002642 if ((v instanceof BubbleTextView)
2643 && shortcut.isPromise()
2644 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002645 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002646 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002647 new DialogInterface.OnClickListener() {
2648 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002649 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002650 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002651 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002652 return;
2653 }
2654
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002655 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002656 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002657 }
2658
Adam Cohen091440a2015-03-18 14:16:05 -07002659 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002660 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002661 final ShortcutInfo shortcut;
2662 final Intent intent;
2663 if (tag instanceof ShortcutInfo) {
2664 shortcut = (ShortcutInfo) tag;
2665 intent = shortcut.intent;
2666 int[] pos = new int[2];
2667 v.getLocationOnScreen(pos);
2668 intent.setSourceBounds(new Rect(pos[0], pos[1],
2669 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002670
Sunny Goyal508da152014-08-14 10:53:27 -07002671 } else if (tag instanceof AppInfo) {
2672 shortcut = null;
2673 intent = ((AppInfo) tag).intent;
2674 } else {
2675 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2676 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002677
2678 boolean success = startActivitySafely(v, intent, tag);
Hyunyoung Songaa953652016-04-19 18:30:24 -07002679 getUserEventDispatcher().logAppLaunch(v, intent);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002680
2681 if (success && v instanceof BubbleTextView) {
2682 mWaitingForResume = (BubbleTextView) v;
2683 mWaitingForResume.setStayPressed(true);
2684 }
2685 }
2686
2687 /**
2688 * Event handler for a folder icon click.
2689 *
2690 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2691 */
2692 protected void onClickFolderIcon(View v) {
2693 if (LOGD) Log.d(TAG, "onClickFolder");
2694 if (!(v instanceof FolderIcon)){
2695 throw new IllegalArgumentException("Input must be a FolderIcon");
2696 }
2697
2698 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002699 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002700 // Open the requested folder
Adam Cohen37b2a492016-04-06 18:36:06 -07002701 openFolder(folderIcon);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002702 }
Michael Jurka5130e402011-10-13 04:55:35 -07002703 }
2704
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002705 /**
2706 * Event handler for the (Add) Widgets button that appears after a long press
2707 * on the home screen.
2708 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002709 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002710 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002711 if (mIsSafeModeEnabled) {
2712 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2713 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002714 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Adam Cohen9211d422014-10-07 18:14:53 -07002715 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002716 }
2717
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002718 /**
2719 * Event handler for the wallpaper picker button that appears after a long press
2720 * on the home screen.
2721 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002722 protected void onClickWallpaperPicker(View v) {
Sunny Goyal1ed6c4a2016-04-21 15:16:11 -07002723 if (!Utilities.isWallapaperAllowed(this)) {
2724 Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show();
2725 return;
2726 }
2727
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002728 String pickerPackage = getString(R.string.wallpaper_picker_package);
2729 if (TextUtils.isEmpty(pickerPackage)) {
2730 pickerPackage = PackageManagerHelper.getWallpaperPickerPackage(getPackageManager());
2731 }
2732
Tony Wickham785f7a52015-08-31 17:28:32 -07002733 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2734 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002735 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER)
2736 .setPackage(pickerPackage)
2737 .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset),
2738 REQUEST_PICK_WALLPAPER);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002739 }
2740
2741 /**
2742 * Event handler for a click on the settings button that appears after a long press
2743 * on the home screen.
2744 */
Sunny Goyal745bad92016-05-02 10:54:12 -07002745 private void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002746 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Sunny Goyal745bad92016-05-02 10:54:12 -07002747 startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES)
2748 .setPackage(getPackageName()));
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002749 }
2750
Adam Cohen61f560d2013-09-30 15:58:20 -07002751 public View.OnTouchListener getHapticFeedbackTouchListener() {
2752 if (mHapticFeedbackTouchListener == null) {
2753 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002754 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002755 @Override
2756 public boolean onTouch(View v, MotionEvent event) {
2757 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2758 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2759 }
2760 return false;
2761 }
2762 };
2763 }
2764 return mHapticFeedbackTouchListener;
2765 }
2766
Tony Wickhame2217252016-03-22 16:34:23 -07002767 @Override
2768 public void onAccessibilityStateChanged(boolean enabled) {
2769 mDragLayer.onAccessibilityStateChanged(enabled);
2770 }
2771
Adam Cohen9211d422014-10-07 18:14:53 -07002772 public void onDragStarted(View view) {
2773 if (isOnCustomContent()) {
2774 // Custom content screen doesn't participate in drag and drop. If on custom
2775 // content screen, move to default.
2776 moveWorkspaceToDefaultScreen();
2777 }
Adam Cohen9211d422014-10-07 18:14:53 -07002778 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002779
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002780 /**
2781 * Called when the user stops interacting with the launcher.
2782 * This implies that the user is now on the homescreen and is not doing housekeeping.
2783 */
Adam Cohen9211d422014-10-07 18:14:53 -07002784 protected void onInteractionEnd() {
2785 if (mLauncherCallbacks != null) {
2786 mLauncherCallbacks.onInteractionEnd();
2787 }
2788 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002789
2790 /**
2791 * Called when the user starts interacting with the launcher.
2792 * The possible interactions are:
2793 * - open all apps
2794 * - reorder an app shortcut, or a widget
2795 * - open the overview mode.
2796 * This is a good time to stop doing things that only make sense
2797 * when the user is on the homescreen and not doing housekeeping.
2798 */
Adam Cohen9211d422014-10-07 18:14:53 -07002799 protected void onInteractionBegin() {
2800 if (mLauncherCallbacks != null) {
2801 mLauncherCallbacks.onInteractionBegin();
2802 }
2803 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002804
Winson Chungcd99cd32015-04-29 11:03:24 -07002805 /** Updates the interaction state. */
2806 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002807 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002808 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002809 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2810 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002811 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002812 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002813 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002814 onInteractionEnd();
2815 }
2816 }
2817
Winson Chung8f1eff72015-05-28 17:33:40 -07002818 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002819 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002820 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002821 // Only launch using the new animation if the shortcut has not opted out (this is a
2822 // private contract between launcher and may be ignored in the future).
2823 boolean useLaunchAnimation = (v != null) &&
2824 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002825 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2826 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002827
Kenny Guy1317e2d2014-05-08 18:52:50 +01002828 UserHandleCompat user = null;
2829 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2830 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2831 user = userManager.getUserForSerialNumber(serialNumber);
2832 }
2833
2834 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002835 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002836 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002837 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002838 int left = 0, top = 0;
2839 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2840 if (v instanceof TextView) {
2841 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002842 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2843 if (icon != null) {
2844 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002845 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002846 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002847 width = bounds.width();
2848 height = bounds.height();
2849 }
2850 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002851 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2852 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002853 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002854 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002855 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002856 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002857 // On L devices, we use the device default slide-up transition.
2858 // On L MR1 devices, we a custom version of the slide-up transition which
2859 // doesn't have the delay present in the device default.
2860 opts = ActivityOptions.makeCustomAnimation(this,
2861 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002862 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002863 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002864 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002865
2866 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2867 // Could be launching some bookkeeping activity
2868 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002869 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002870 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002871 launcherApps.startActivityForProfile(intent.getComponent(), user,
2872 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002873 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002874 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002875 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002876 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2877 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2878 // corresponding permission. Show the appropriate permission prompt if that
2879 // is the case.
2880 if (intent.getComponent() == null
2881 && Intent.ACTION_CALL.equals(intent.getAction())
2882 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2883 PackageManager.PERMISSION_GRANTED) {
2884 // TODO: Rename sPendingAddItem to a generic name.
2885 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2886 0, (ItemInfo) tag);
2887 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2888 REQUEST_PERMISSION_CALL_PHONE);
2889 return false;
2890 }
2891 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002892 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002893 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002895 "or use the exported attribute for this activity. "
2896 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002897 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002898 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002900
Winson Chungbedf9232015-07-10 12:38:30 -07002901 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002902 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002903 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2904 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2905 return false;
2906 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002907 try {
2908 success = startActivity(v, intent, tag);
2909 } catch (ActivityNotFoundException e) {
2910 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2911 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2912 }
2913 return success;
2914 }
2915
Adam Cohen268c4752012-06-06 17:47:33 -07002916 /**
2917 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2918 * in the DragLayer in the exact absolute location of the original FolderIcon.
2919 */
2920 private void copyFolderIconToImage(FolderIcon fi) {
2921 final int width = fi.getMeasuredWidth();
2922 final int height = fi.getMeasuredHeight();
2923
2924 // Lazy load ImageView, Bitmap and Canvas
2925 if (mFolderIconImageView == null) {
2926 mFolderIconImageView = new ImageView(this);
2927 }
2928 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2929 mFolderIconBitmap.getHeight() != height) {
2930 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2931 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2932 }
2933
2934 DragLayer.LayoutParams lp;
2935 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2936 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2937 } else {
2938 lp = new DragLayer.LayoutParams(width, height);
2939 }
2940
Adam Cohen307fe232012-08-16 17:55:58 -07002941 // The layout from which the folder is being opened may be scaled, adjust the starting
2942 // view size by this scale factor.
2943 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002944 lp.customPosition = true;
2945 lp.x = mRectForFolderAnimation.left;
2946 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002947 lp.width = (int) (scale * width);
2948 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002949
2950 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2951 fi.draw(mFolderIconCanvas);
2952 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002953 if (fi.getFolder() != null) {
2954 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2955 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002956 }
Adam Cohen268c4752012-06-06 17:47:33 -07002957 // Just in case this image view is still in the drag layer from a previous animation,
2958 // we remove it and re-add it.
2959 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2960 mDragLayer.removeView(mFolderIconImageView);
2961 }
2962 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002963 if (fi.getFolder() != null) {
2964 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002965 }
Adam Cohen268c4752012-06-06 17:47:33 -07002966 }
2967
Adam Cohen37b2a492016-04-06 18:36:06 -07002968 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002969 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07002970 FolderInfo info = (FolderInfo) fi.getTag();
2971 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2972 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002973 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2974 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002975 }
2976
Adam Cohen268c4752012-06-06 17:47:33 -07002977 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2978 copyFolderIconToImage(fi);
2979 fi.setVisibility(View.INVISIBLE);
2980
Sunny Goyal5d2fc322015-07-06 22:52:49 -07002981 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
2982 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002983 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002984 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2985 }
2986 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002987 oa.start();
2988 }
2989
Sunny Goyal935fca12015-10-13 10:19:01 -07002990 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002991 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07002992 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002993
Adam Cohen268c4752012-06-06 17:47:33 -07002994 // We remove and re-draw the FolderIcon in-case it has changed
2995 mDragLayer.removeView(mFolderIconImageView);
2996 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08002997
2998 if (cl != null) {
2999 cl.clearFolderLeaveBehind();
3000 }
3001
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003002 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003003 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003004 oa.addListener(new AnimatorListenerAdapter() {
3005 @Override
3006 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003007 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003008 // Remove the ImageView copy of the FolderIcon and make the original visible.
3009 mDragLayer.removeView(mFolderIconImageView);
3010 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003011 }
3012 }
3013 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003014 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003015 if (!animate) {
3016 oa.end();
3017 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003018 }
3019
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003020 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003021 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003022 * is animated relative to the specified View. If the View is null, no animation
3023 * is played.
3024 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003025 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003026 */
Adam Cohen37b2a492016-04-06 18:36:06 -07003027 public void openFolder(FolderIcon folderIcon) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003028
Adam Cohenfb91f302012-06-11 15:45:18 -07003029 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003030 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3031 if (openFolder != null && openFolder != folder) {
3032 // Close any open folder before opening a folder.
3033 closeFolder();
3034 }
3035
Adam Cohena9cf38f2011-05-02 15:36:58 -07003036 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003037
Adam Cohena9cf38f2011-05-02 15:36:58 -07003038 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003039
Sunny Goyalf4066152015-04-15 09:42:19 -07003040 // While the folder is open, the position of the icon cannot change.
3041 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3042
Adam Cohen4554ee12011-08-03 16:13:21 -07003043 // Just verify that the folder hasn't already been added to the DragLayer.
3044 // There was a one-off crash where the folder had a parent already.
3045 if (folder.getParent() == null) {
3046 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003047 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003048 } else {
3049 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3050 folder.getParent() + ").");
3051 }
Adam Cohen37b2a492016-04-06 18:36:06 -07003052 folder.animateOpen();
3053
3054 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003055
3056 // Notify the accessibility manager that this folder "window" has appeared and occluded
3057 // the workspace items
3058 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3059 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003060 }
3061
3062 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003063 closeFolder(true);
3064 }
3065
3066 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003067 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003068 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003069 if (folder.isEditingName()) {
3070 folder.dismissEditingName();
3071 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003072 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003073 }
3074 }
3075
Sunny Goyal935fca12015-10-13 10:19:01 -07003076 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003077 animate &= !Utilities.isPowerSaverOn(this);
3078
Adam Cohen4554ee12011-08-03 16:13:21 -07003079 folder.getInfo().opened = false;
3080
3081 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3082 if (parent != null) {
3083 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003084 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003085 if (fi != null) {
3086 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3087 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003088 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003089 if (animate) {
3090 folder.animateClosed();
3091 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003092 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003093 }
Winson Chung83ca4802013-04-12 15:10:52 -07003094
Sunny Goyal935fca12015-10-13 10:19:01 -07003095 // Notify the accessibility manager that this folder "window" has disappeared and no
3096 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003097 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003098 }
3099
Tony Wickhamdadb3042016-02-24 11:07:00 -08003100 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003101 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003102 if (!isDraggingEnabled()) return false;
3103 if (isWorkspaceLocked()) return false;
3104 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003105
Winson Chung76648c52015-07-10 14:33:23 -07003106 if (v == mAllAppsButton) {
3107 onLongClickAllAppsButton(v);
3108 return true;
3109 }
3110
Adam Cohen1697b792013-09-17 19:08:21 -07003111 if (v instanceof Workspace) {
3112 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003113 if (!mWorkspace.isTouchActive()) {
3114 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003115 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3116 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3117 return true;
3118 } else {
3119 return false;
3120 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003121 } else {
3122 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003123 }
Adam Cohen1697b792013-09-17 19:08:21 -07003124 }
3125
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003126 CellLayout.CellInfo longClickCellInfo = null;
3127 View itemUnderLongClick = null;
3128 if (v.getTag() instanceof ItemInfo) {
3129 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003130 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003131 itemUnderLongClick = longClickCellInfo.cell;
3132 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003133 }
3134
Winson Chung3d503fb2011-07-13 17:25:49 -07003135 // The hotseat touch handling does not go through Workspace, and we always allow long press
3136 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003137 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003138 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003139 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003140 // User long pressed on empty space
3141 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3142 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003143 if (mWorkspace.isInOverviewMode()) {
3144 mWorkspace.startReordering(v);
3145 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003146 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003147 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003148 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003149 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3150 mHotseat.getOrderInHotseat(
3151 longClickCellInfo.cellX,
3152 longClickCellInfo.cellY));
3153 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003154 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003155 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003156 }
3157 }
3158 }
3159 return true;
3160 }
3161
Winson Chung3d503fb2011-07-13 17:25:49 -07003162 boolean isHotseatLayout(View layout) {
3163 return mHotseat != null && layout != null &&
3164 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3165 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003166
Winson Chung3d503fb2011-07-13 17:25:49 -07003167 /**
3168 * Returns the CellLayout of the specified container at the specified screen.
3169 */
Sunny Goyal92820592015-03-02 11:31:35 -08003170 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003171 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3172 if (mHotseat != null) {
3173 return mHotseat.getLayout();
3174 } else {
3175 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003176 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003177 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003178 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003179 }
3180 }
3181
Winson Chungb745afb2015-03-02 11:51:23 -08003182 /**
3183 * For overridden classes.
3184 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003185 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003186 return isAppsViewVisible();
3187 }
3188
3189 public boolean isAppsViewVisible() {
3190 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3191 }
3192
3193 public boolean isWidgetsViewVisible() {
3194 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003195 }
3196
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003197 private void setWorkspaceBackground(int background) {
3198 switch (background) {
3199 case WORKSPACE_BACKGROUND_TRANSPARENT:
3200 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3201 break;
3202 case WORKSPACE_BACKGROUND_BLACK:
3203 getWindow().setBackgroundDrawable(null);
3204 break;
3205 default:
3206 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3207 }
Craig Mautner360310b2012-10-26 15:13:08 -07003208 }
3209
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003210 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003211 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3212 int curflags = getWindow().getAttributes().flags
3213 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3214 if (wpflags != curflags) {
3215 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3216 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003217 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003218 }
3219
Michael Jurkae326f182011-11-21 14:05:46 -08003220 @Override
3221 public void onTrimMemory(int level) {
3222 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003223 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3224 // The widget preview db can result in holding onto over
3225 // 3MB of memory for caching which isn't necessary.
3226 SQLiteDatabase.releaseMemory();
3227
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003228 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003229 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003230 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003231 if (mLauncherCallbacks != null) {
3232 mLauncherCallbacks.onTrimMemory(level);
3233 }
Michael Jurkae326f182011-11-21 14:05:46 -08003234 }
3235
Winson5c6bdbb2015-09-03 11:36:19 -07003236 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003237 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003238 }
3239
Winson5c6bdbb2015-09-03 11:36:19 -07003240 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003241 boolean changed = mState != State.WORKSPACE ||
3242 mWorkspace.getState() != Workspace.State.NORMAL;
3243 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003244 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003245 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003246 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003247
Michael Jurkab3e22d92011-10-31 15:58:33 -07003248 // Set focus to the AppsCustomize button
3249 if (mAllAppsButton != null) {
3250 mAllAppsButton.requestFocus();
3251 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003252 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003253
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003254 // Change the state *after* we've called all the transition code
3255 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003256
Winson Chung5fb63472011-02-02 17:03:37 -08003257 // Resume the auto-advance of widgets
3258 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003259 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003260
Winson Chung0f785722015-04-08 10:27:49 -07003261 if (changed) {
3262 // Send an accessibility event to announce the context change
3263 getWindow().getDecorView()
3264 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003265 }
Winson5c6bdbb2015-09-03 11:36:19 -07003266 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003267 }
3268
Winsone9f27272015-10-13 10:47:51 -07003269 /**
3270 * Shows the overview button.
3271 */
Adam Cohened307df2013-10-02 09:37:31 -07003272 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003273 showOverviewMode(animated, false);
3274 }
3275
3276 /**
3277 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3278 * onto one of the overview panel buttons.
3279 */
3280 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3281 Runnable postAnimRunnable = null;
3282 if (requestButtonFocus) {
3283 postAnimRunnable = new Runnable() {
3284 @Override
3285 public void run() {
3286 // Hitting the menu button when in touch mode does not trigger touch mode to
3287 // be disabled, so if requested, force focus on one of the overview panel
3288 // buttons.
3289 mOverviewPanel.requestFocusFromTouch();
3290 }
3291 };
3292 }
Adam Cohened307df2013-10-02 09:37:31 -07003293 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003294 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003295 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003296 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003297 }
3298
Winson Chungb745afb2015-03-02 11:51:23 -08003299 /**
3300 * Shows the apps view.
3301 */
Winson Chung76648c52015-07-10 14:33:23 -07003302 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3303 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003304 if (resetListToTop) {
3305 mAppsView.scrollToTop();
3306 }
Winson Chung4ac30062015-05-08 17:34:17 -07003307 if (updatePredictedApps) {
3308 tryAndUpdatePredictedApps();
3309 }
Winson Chung76648c52015-07-10 14:33:23 -07003310 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003311 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003312
Winson Chungb745afb2015-03-02 11:51:23 -08003313 /**
3314 * Shows the widgets view.
3315 */
3316 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003317 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003318 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003319 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003320 }
Winson Chung76648c52015-07-10 14:33:23 -07003321 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003322
3323 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003324 @Override
3325 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003326 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003327 }
3328 });
Winson Chungb745afb2015-03-02 11:51:23 -08003329 }
3330
3331 /**
3332 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003333 *
3334 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003335 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003336 // TODO: calling method should use the return value so that when {@code false} is returned
3337 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003338 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003339 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3340 mState != State.WIDGETS_SPRING_LOADED) {
3341 return false;
3342 }
3343 if (toState != State.APPS && toState != State.WIDGETS) {
3344 return false;
3345 }
Winson Chungb745afb2015-03-02 11:51:23 -08003346
3347 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003348 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3349 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003350 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003351 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003352 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003353
Michael Jurkab3e22d92011-10-31 15:58:33 -07003354 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003355 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003356
3357 // Pause the auto-advance of widgets until we are out of AllApps
3358 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003359 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003360 closeFolder();
3361
3362 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003363 getWindow().getDecorView()
3364 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003365 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003366 }
3367
Winson Chungcd99cd32015-04-29 11:03:24 -07003368 /**
3369 * Updates the workspace and interaction state on state change, and return the animation to this
3370 * new state.
3371 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003372 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003373 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003374 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003375 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003376 updateInteraction(fromState, toState);
3377 return anim;
3378 }
3379
Jun Mukaif0033da2015-08-04 18:34:30 -07003380 public void onLauncherClingShown() {
3381 // When a launcher cling appears, it should cover the underlying layers, so their focus
3382 // should be blocked.
3383 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3384 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3385 }
3386 }
3387
3388 public void onLauncherClingDismissed() {
3389 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3390 }
3391
Hyunyoung Song3f471442015-04-08 19:01:34 -07003392 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003393 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003394 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003395 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003396 }
Winson Chungb745afb2015-03-02 11:51:23 -08003397
Winson Chung006ee262015-08-03 14:40:11 -07003398 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003399 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003400 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003401
3402 if (isAppsViewVisible()) {
3403 mState = State.APPS_SPRING_LOADED;
3404 } else if (isWidgetsViewVisible()) {
3405 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003406 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003407 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003408 } else {
3409 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003410 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003411 }
Adam Cohen7777d962011-08-18 18:58:38 -07003412
Hyunyoung Song3f471442015-04-08 19:01:34 -07003413 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003414 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003415 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003416
Winson Chunge7a03942011-08-05 15:05:12 -07003417 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003418 @Override
3419 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003420 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003421 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3422 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003423 // Before we show workspace, hide all apps again because
3424 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3425 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003426 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003427 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003428 } else {
3429 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003430 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003431 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003432 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003433 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003434
Tony Wickhame0c33232016-02-08 11:37:04 -08003435 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003436 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3437 || mState == State.WIDGETS_SPRING_LOADED;
3438 }
3439
Michael Jurkad3ef3062010-11-23 16:23:58 -08003440 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003441 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003442 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003443 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003444 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003445 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003446 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3447 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003448 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003449 }
3450
Winson Chung4ac30062015-05-08 17:34:17 -07003451 /**
3452 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3453 * resumed.
3454 */
3455 private void tryAndUpdatePredictedApps() {
3456 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003457 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003458 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003459 mAppsView.setPredictedApps(apps);
Hyunyoung Songaa953652016-04-19 18:30:24 -07003460 getUserEventDispatcher().setPredictedApps(apps);
Winson Chung4ac30062015-05-08 17:34:17 -07003461 }
3462 }
3463 }
3464
Michael Jurkab3e22d92011-10-31 15:58:33 -07003465 void lockAllApps() {
3466 // TODO
3467 }
3468
3469 void unlockAllApps() {
3470 // TODO
3471 }
3472
Winsonf768d932015-09-25 16:12:35 -07003473 public boolean launcherCallbacksProvidesSearch() {
3474 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3475 }
3476
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003477 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003478 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003479 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003480 }
3481
Adam Cohen24ce0b32014-01-14 16:18:14 -08003482 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003483 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3484 if (searchProvider == null) {
3485 return null;
3486 }
3487
3488 Bundle opts = new Bundle();
3489 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003490 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003491
Tony Wickham3a3517f2015-10-06 11:27:04 -07003492 // Determine the min and max dimensions of the widget.
3493 LauncherAppState app = LauncherAppState.getInstance();
3494 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3495 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3496 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003497 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3498 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003499 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003500 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003501 int minWidth = maxWidth;
3502 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003503 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3504 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3505 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3506 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3507 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003508 }
3509 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3510 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3511 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3512 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003513 if (LOGD) {
3514 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3515 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3516 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003517
Tony Wickham775455c2015-10-16 09:49:32 -07003518 if (mLauncherCallbacks != null) {
3519 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3520 }
3521
Sunny Goyalf7258242015-10-19 16:59:07 -07003522 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003523 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003524 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003525 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003526 || (widgetInfo == null)
3527 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003528 // A valid widget is not already bound.
3529 if (widgetId > -1) {
3530 mAppWidgetHost.deleteAppWidgetId(widgetId);
3531 widgetId = -1;
3532 }
3533
3534 // Try to bind a new widget
3535 widgetId = mAppWidgetHost.allocateAppWidgetId();
3536
3537 if (!AppWidgetManagerCompat.getInstance(this)
3538 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3539 mAppWidgetHost.deleteAppWidgetId(widgetId);
3540 widgetId = -1;
3541 }
3542
Sunny Goyalf7258242015-10-19 16:59:07 -07003543 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003544 .putInt(QSB_WIDGET_ID, widgetId)
3545 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003546 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003547 }
3548
Sunny Goyal8d595092015-07-06 12:22:14 -07003549 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003550 if (widgetId != -1) {
3551 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003552 mQsb.setId(R.id.qsb_widget);
Sunny Goyal3f732192016-05-13 13:48:44 -07003553 if (!Utilities.containsAll(
3554 AppWidgetManager.getInstance(this).getAppWidgetOptions(widgetId), opts)) {
3555 // Launcher should not be updating the options often.
3556 FileLog.d(TAG, "Options for QSB were not same");
3557 mQsb.updateAppWidgetOptions(opts);
3558 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08003559 mQsb.setPadding(0, 0, 0, 0);
3560 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003561 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003562 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003563 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003564 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003565 }
3566
Sunny Goyal22235bc2015-04-03 09:23:43 -07003567 private void reinflateQSBIfNecessary() {
3568 if (mQsb instanceof LauncherAppWidgetHostView &&
3569 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3570 mSearchDropTargetBar.removeView(mQsb);
3571 mQsb = null;
3572 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3573 }
3574 }
3575
Michael Jurkad7c28052012-04-27 15:43:36 -07003576 @Override
3577 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003578 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003579 final List<CharSequence> text = event.getText();
3580 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003581 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003582 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003583 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003584 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003585 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003586 } else if (mWorkspace != null) {
3587 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003588 } else {
3589 text.add(getString(R.string.all_apps_home_button_label));
3590 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003591 return result;
3592 }
3593
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003594 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003595 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003596 */
Adam Cohen091440a2015-03-18 14:16:05 -07003597 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003598 @Override
3599 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003600 closeSystemDialogs();
3601 }
3602 }
3603
3604 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003605 * If the activity is currently paused, signal that we need to run the passed Runnable
3606 * in onResume.
3607 *
3608 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003609 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3610 * wrong when we're not running, and if the activity comes back to what the configuration was
3611 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003612 *
3613 * Implementation of the method from LauncherModel.Callbacks.
3614 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003615 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003616 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003617 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003618 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003619 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003620 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003621 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003622 }
3623 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003624 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003625 return true;
3626 } else {
3627 return false;
3628 }
3629 }
3630
Michael Jurkac402cd92013-05-20 15:49:32 +02003631 private boolean waitUntilResume(Runnable run) {
3632 return waitUntilResume(run, false);
3633 }
3634
Michael Jurka1e2f4652013-07-08 18:03:46 -07003635 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003636 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003637 }
3638
Michael Jurka7607c2f2013-04-03 14:33:19 -07003639 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003640 * If the activity is currently paused, signal that we need to re-run the loader
3641 * in onResume.
3642 *
3643 * This needs to be called from incoming places where resources might have been loaded
3644 * while we are paused. That is becaues the Configuration might be wrong
3645 * when we're not running, and if it comes back to what it was when we
3646 * were paused, we are not restarted.
3647 *
3648 * Implementation of the method from LauncherModel.Callbacks.
3649 *
3650 * @return true if we are currently paused. The caller might be able to
3651 * skip some work in that case since we will come back again.
3652 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003653 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003654 public boolean setLoadOnResume() {
3655 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003656 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003657 mOnResumeNeedsLoad = true;
3658 return true;
3659 } else {
3660 return false;
3661 }
3662 }
3663
3664 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003665 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003666 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003667 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04003668 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003669 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003670 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003671 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003672 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003673 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003674 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003675
Joe Onorato9c1289c2009-08-17 11:03:03 -04003676 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003677 * Clear any pending bind callbacks. This is called when is loader is planning to
3678 * perform a full rebind from scratch.
3679 */
3680 @Override
3681 public void clearPendingBinds() {
3682 mBindOnResumeCallbacks.clear();
3683 if (mPendingExecutor != null) {
3684 mPendingExecutor.markCompleted();
3685 mPendingExecutor = null;
3686 }
3687 }
3688
3689 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003690 * Refreshes the shortcuts shown on the workspace.
3691 *
3692 * Implementation of the method from LauncherModel.Callbacks.
3693 */
3694 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003695 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003696
Winson Chungd64d1762013-08-20 14:37:16 -07003697 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003698 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003699 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003700
Michael Jurka05bf644e2011-11-30 20:28:53 -08003701 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003702 if (mHotseat != null) {
3703 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003704 }
3705 }
3706
Adam Cohendcd297f2013-06-18 13:13:40 -07003707 @Override
3708 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003709 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003710
Adam Cohen5084cba2013-09-03 12:01:16 -07003711 // If there are no screens, we need to have an empty screen
3712 if (orderedScreenIds.size() == 0) {
3713 mWorkspace.addExtraEmptyScreen();
3714 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003715
3716 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003717 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003718 if (hasCustomContentToLeft()) {
3719 mWorkspace.createCustomContentContainer();
3720 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003721 }
Winson Chung64359a52013-07-08 17:17:08 -07003722 }
3723
3724 @Override
3725 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003726 int count = orderedScreenIds.size();
3727 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003728 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003729 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003730 }
3731
Winson Chungd64d1762013-08-20 14:37:16 -07003732 public void bindAppsAdded(final ArrayList<Long> newScreens,
3733 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003734 final ArrayList<ItemInfo> addAnimated,
3735 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003736 Runnable r = new Runnable() {
3737 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003738 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003739 }
3740 };
3741 if (waitUntilResume(r)) {
3742 return;
3743 }
3744
Winson Chungd64d1762013-08-20 14:37:16 -07003745 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003746 if (newScreens != null) {
3747 bindAddScreens(newScreens);
3748 }
Winson Chungd64d1762013-08-20 14:37:16 -07003749
3750 // We add the items without animation on non-visible pages, and with
3751 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003752 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003753 bindItems(addNotAnimated, 0,
3754 addNotAnimated.size(), false);
3755 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003756 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003757 bindItems(addAnimated, 0,
3758 addAnimated.size(), true);
3759 }
Winson Chungc58497e2013-09-03 17:48:37 -07003760
Winson Chung87412982013-10-03 18:34:14 -07003761 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003762 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003763
Winson Chungb745afb2015-03-02 11:51:23 -08003764 if (addedApps != null && mAppsView != null) {
3765 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003766 }
Winson Chungd64d1762013-08-20 14:37:16 -07003767 }
3768
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003769 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770 * Bind the items start-end from the list.
3771 *
3772 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003773 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003774 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003775 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3776 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003777 Runnable r = new Runnable() {
3778 public void run() {
3779 bindItems(shortcuts, start, end, forceAnimateIcons);
3780 }
3781 };
3782 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003783 return;
3784 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003785
Winson Chungf0c6ae02012-03-21 16:10:31 -07003786 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003787 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3788 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003789 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003790 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003791 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003792 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003793 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003794
3795 // Short circuit if we are loading dock items for a configuration which has no dock
3796 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3797 mHotseat == null) {
3798 continue;
3799 }
3800
Sunny Goyal639e9062015-08-19 19:17:06 -07003801 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003802 switch (item.itemType) {
3803 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3804 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003805 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003806 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003807
Winson Chung64359a52013-07-08 17:17:08 -07003808 /*
3809 * TODO: FIX collision case
3810 */
Winson Chungce376632013-07-11 16:12:41 -07003811 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3812 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3813 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003814 View v = cl.getChildAt(item.cellX, item.cellY);
3815 Object tag = v.getTag();
3816 String desc = "Collision while binding workspace item: " + item
3817 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003818 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003819 throw (new RuntimeException(desc));
3820 } else {
3821 Log.d(TAG, desc);
3822 }
Winson Chungce376632013-07-11 16:12:41 -07003823 }
Winson Chung64359a52013-07-08 17:17:08 -07003824 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003825 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003826 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003827 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003828 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003829 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003831 default:
3832 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003834
3835 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3836 item.cellY, 1, 1);
3837 if (animateIcons) {
3838 // Animate all the applications up now
3839 view.setAlpha(0f);
3840 view.setScaleX(0f);
3841 view.setScaleY(0f);
3842 bounceAnims.add(createNewAppBounceAnimation(view, i));
3843 newShortcutsScreenId = item.screenId;
3844 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003845 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003846
Winson Chung997a9232013-07-24 15:33:46 -07003847 if (animateIcons) {
3848 // Animate to the correct page
3849 if (newShortcutsScreenId > -1) {
3850 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003851 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003852 final Runnable startBounceAnimRunnable = new Runnable() {
3853 public void run() {
3854 anim.playTogether(bounceAnims);
3855 anim.start();
3856 }
3857 };
Winson Chung997a9232013-07-24 15:33:46 -07003858 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003859 // We post the animation slightly delayed to prevent slowdowns
3860 // when we are loading right after we return to launcher.
3861 mWorkspace.postDelayed(new Runnable() {
3862 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003863 if (mWorkspace != null) {
3864 mWorkspace.snapToPage(newScreenIndex);
3865 mWorkspace.postDelayed(startBounceAnimRunnable,
3866 NEW_APPS_ANIMATION_DELAY);
3867 }
Winson Chung94d67682013-09-25 16:29:40 -07003868 }
3869 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003870 } else {
3871 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003872 }
3873 }
Winson Chung64359a52013-07-08 17:17:08 -07003874 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003875 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003876 }
3877
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003878 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3879 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3880 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003881 view.updateAppWidget(null);
3882 view.setOnClickListener(this);
3883 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003884 mWorkspace.requestLayout();
3885 }
3886
Joe Onorato9c1289c2009-08-17 11:03:03 -04003887 /**
3888 * Add the views for a widget to the workspace.
3889 *
3890 * Implementation of the method from LauncherModel.Callbacks.
3891 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003892 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003893 Runnable r = new Runnable() {
3894 public void run() {
3895 bindAppWidget(item);
3896 }
3897 };
3898 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003899 return;
3900 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003901
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003902 if (mIsSafeModeEnabled) {
3903 bindSafeModeWidget(item);
3904 return;
3905 }
3906
Daniel Sandler843e8602010-06-07 14:59:01 -04003907 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3908 if (DEBUG_WIDGETS) {
3909 Log.d(TAG, "bindAppWidget: " + item);
3910 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003911
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003912 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003913
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003914 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3915 // If the provider is not ready, bind as a pending widget.
3916 appWidgetInfo = null;
3917 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3918 // The widget id is not valid. Try to find the widget based on the provider info.
3919 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3920 } else {
3921 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3922 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003923
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003924 // If the provider is ready, but the width is not yet restored, try to restore it.
3925 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3926 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003927 if (appWidgetInfo == null) {
3928 if (DEBUG_WIDGETS) {
3929 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3930 + " belongs to component " + item.providerName
3931 + ", as the povider is null");
3932 }
3933 LauncherModel.deleteItemFromDatabase(this, item);
3934 return;
3935 }
Sunny Goyalff572272014-07-23 13:58:07 -07003936
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003937 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003938 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003939 // Note: This assumes that the id remap broadcast is received before this step.
3940 // If that is not the case, the id remap will be ignored and user may see the
3941 // click to setup view.
Sunny Goyal16466f12016-03-10 05:34:30 -08003942 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003943 pendingInfo.spanX = item.spanX;
3944 pendingInfo.spanY = item.spanY;
3945 pendingInfo.minSpanX = item.minSpanX;
3946 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08003947 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07003948
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003949 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
3950 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
3951 newWidgetId, appWidgetInfo, options);
3952
3953 // TODO consider showing a permission dialog when the widget is clicked.
3954 if (!success) {
3955 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
3956 if (DEBUG_WIDGETS) {
3957 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3958 + " belongs to component " + item.providerName
3959 + ", as the launcher is unable to bing a new widget id");
3960 }
3961 LauncherModel.deleteItemFromDatabase(this, item);
3962 return;
Sunny Goyalff572272014-07-23 13:58:07 -07003963 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003964
3965 item.appWidgetId = newWidgetId;
3966
3967 // If the widget has a configure activity, it is still needs to set it up, otherwise
3968 // the widget is ready to go.
3969 item.restoreStatus = (appWidgetInfo.configure == null)
3970 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
3971 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
3972
3973 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003974 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003975 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003976 // The widget was marked as UI not ready, but there is no configure activity to
3977 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003978 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
3979 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07003980 }
Sunny Goyalff572272014-07-23 13:58:07 -07003981 }
3982
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003983 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07003984 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08003985 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
3986 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07003987 }
Daniel Sandler843e8602010-06-07 14:59:01 -04003988
Sunny Goyal56c73602015-09-25 12:55:01 -07003989 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003990 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07003991 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07003992 deleteWidgetInfo(item);
3993 return;
3994 }
3995
Sunny Goyal233ee962015-08-03 13:05:01 -07003996 item.minSpanX = appWidgetInfo.minSpanX;
3997 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003998 addAppWidgetToWorkspace(
3999 mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo),
4000 item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004001 } else {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07004002 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004003 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07004004 view.updateAppWidget(null);
4005 view.setOnClickListener(this);
4006 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004007 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004008 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004009
Daniel Sandler843e8602010-06-07 14:59:01 -04004010 if (DEBUG_WIDGETS) {
4011 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4012 + (SystemClock.uptimeMillis()-start) + "ms");
4013 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004014 }
4015
Sunny Goyalff572272014-07-23 13:58:07 -07004016 /**
4017 * Restores a pending widget.
4018 *
4019 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07004020 */
4021 private void completeRestoreAppWidget(final int appWidgetId) {
4022 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4023 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4024 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4025 return;
4026 }
4027
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004028 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004029 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4030
4031 mWorkspace.reinflateWidgetsIfNecessary();
4032 LauncherModel.updateItemInDatabase(this, info);
4033 }
4034
Adam Cohen1462de32012-07-24 22:34:36 -07004035 public void onPageBoundSynchronously(int page) {
4036 mSynchronouslyBoundPages.add(page);
4037 }
4038
Sunny Goyal527c7d32015-08-28 15:19:36 -07004039 @Override
4040 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4041 if (mPendingExecutor != null) {
4042 mPendingExecutor.markCompleted();
4043 }
4044 mPendingExecutor = executor;
4045 executor.attachTo(this);
4046 }
4047
4048 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4049 if (mPendingExecutor == executor) {
4050 mPendingExecutor = null;
4051 }
4052 }
4053
Joe Onorato9c1289c2009-08-17 11:03:03 -04004054 /**
4055 * Callback saying that there aren't any more items to bind.
4056 *
4057 * Implementation of the method from LauncherModel.Callbacks.
4058 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004059 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004060 Runnable r = new Runnable() {
4061 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004062 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004063 }
4064 };
4065 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004066 return;
4067 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004068 if (mSavedState != null) {
4069 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004070 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004071 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004072
Joe Onorato9c1289c2009-08-17 11:03:03 -04004073 mSavedState = null;
4074 }
4075
Adam Cohen1462de32012-07-24 22:34:36 -07004076 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004077
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004078 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07004079
4080 // If we received the result of any pending adds while the loader was running (e.g. the
4081 // widget configuration forced an orientation change), process them now.
4082 if (sPendingAddItem != null) {
4083 final long screenId = completeAdd(sPendingAddItem);
4084
4085 // TODO: this moves the user to the page where the pending item was added. Ideally,
4086 // the screen would be guaranteed to exist after bind, and the page would be set through
4087 // the workspace restore process.
4088 mWorkspace.post(new Runnable() {
4089 @Override
4090 public void run() {
4091 mWorkspace.snapToScreenId(screenId);
4092 }
4093 });
4094 sPendingAddItem = null;
4095 }
4096
Sunny Goyal756adbc2015-04-16 15:20:51 -07004097 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004098
4099 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004100 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004101 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004102 }
4103
Winson Chunga0b7e862013-09-05 16:03:15 -07004104 public boolean isAllAppsButtonRank(int rank) {
4105 if (mHotseat != null) {
4106 return mHotseat.isAllAppsButtonRank(rank);
4107 }
4108 return false;
4109 }
4110
Winson Chunga2413752012-04-03 14:22:34 -07004111 private boolean canRunNewAppsAnimation() {
4112 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004113 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4114 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004115 }
4116
Winson Chungc9168342013-06-26 14:54:55 -07004117 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004118 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004119 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4120 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004121 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004122 return bounceAnim;
4123 }
4124
Adam Cohen27772732013-11-11 14:00:56 +00004125 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004126 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004127 }
4128
Tony Wickham3a3517f2015-10-06 11:27:04 -07004129 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004130 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004131 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004132 }
4133
Tony Wickham55616cd2015-09-23 14:55:17 -07004134 public int getSearchBarHeight() {
4135 if (mLauncherCallbacks != null) {
4136 return mLauncherCallbacks.getSearchBarHeight();
4137 }
4138 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4139 }
4140
Winson Chung88fa7412015-08-03 14:25:28 -07004141 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004142 if (mSearchDropTargetBar == null) {
4143 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004144 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004145 if (mQsb != null) {
4146 mSearchDropTargetBar.removeView(mQsb);
4147 mQsb = null;
4148 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004149 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004150 }
4151
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004152 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004153 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4154 * multiple calls to bind the same list.)
4155 */
4156 @Thunk ArrayList<AppInfo> mTmpAppsList;
4157 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4158 public void run() {
4159 bindAllApplications(mTmpAppsList);
4160 mTmpAppsList = null;
4161 }
4162 };
4163
4164 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004165 * Add the icons for all apps.
4166 *
4167 * Implementation of the method from LauncherModel.Callbacks.
4168 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004169 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004170 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4171 mTmpAppsList = apps;
4172 return;
4173 }
4174
Winson Chungb745afb2015-03-02 11:51:23 -08004175 if (mAppsView != null) {
4176 mAppsView.setApps(apps);
4177 }
Adam Cohen9211d422014-10-07 18:14:53 -07004178 if (mLauncherCallbacks != null) {
4179 mLauncherCallbacks.bindAllApplications(apps);
4180 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004181 }
4182
4183 /**
4184 * A package was updated.
4185 *
4186 * Implementation of the method from LauncherModel.Callbacks.
4187 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004188 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004189 Runnable r = new Runnable() {
4190 public void run() {
4191 bindAppsUpdated(apps);
4192 }
4193 };
4194 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004195 return;
4196 }
4197
Winson Chungb745afb2015-03-02 11:51:23 -08004198 if (mAppsView != null) {
4199 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004200 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004201 }
4202
Sunny Goyal4390ace2014-10-13 11:33:11 -07004203 @Override
4204 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4205 Runnable r = new Runnable() {
4206 public void run() {
4207 bindWidgetsRestored(widgets);
4208 }
4209 };
4210 if (waitUntilResume(r)) {
4211 return;
4212 }
4213 mWorkspace.widgetsRestored(widgets);
4214 }
4215
Joe Onorato9c1289c2009-08-17 11:03:03 -04004216 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004217 * Some shortcuts were updated in the background.
4218 *
4219 * Implementation of the method from LauncherModel.Callbacks.
4220 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004221 @Override
4222 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4223 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004224 Runnable r = new Runnable() {
4225 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004226 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004227 }
4228 };
4229 if (waitUntilResume(r)) {
4230 return;
4231 }
4232
Sunny Goyal4390ace2014-10-13 11:33:11 -07004233 if (!updated.isEmpty()) {
4234 mWorkspace.updateShortcuts(updated);
4235 }
4236
4237 if (!removed.isEmpty()) {
4238 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4239 for (ShortcutInfo si : removed) {
4240 removedComponents.add(si.getTargetComponent());
4241 }
4242 mWorkspace.removeItemsByComponentName(removedComponents, user);
4243 // Notify the drag controller
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004244 mDragController.onAppsRemoved(new HashSet<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004245 }
4246 }
4247
4248 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004249 * Update the state of a package, typically related to install state.
4250 *
4251 * Implementation of the method from LauncherModel.Callbacks.
4252 */
Sunny Goyale755d462014-07-22 13:48:29 -07004253 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004254 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4255 Runnable r = new Runnable() {
4256 public void run() {
4257 bindRestoreItemsChange(updates);
4258 }
4259 };
4260 if (waitUntilResume(r)) {
4261 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004262 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004263
Sunny Goyal756adbc2015-04-16 15:20:51 -07004264 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004265 }
4266
4267 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004268 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07004269 * in addition to specific applications to remove, the reason being that
4270 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004271 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07004272 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004273 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004274 @Override
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004275 public void bindWorkspaceComponentsRemoved(
4276 final HashSet<String> packageNames, final HashSet<ComponentName> components,
4277 final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004278 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004279 public void run() {
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004280 bindWorkspaceComponentsRemoved(packageNames, components, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004281 }
Winson Chungd64d1762013-08-20 14:37:16 -07004282 };
4283 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004284 return;
4285 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004286 if (!packageNames.isEmpty()) {
4287 mWorkspace.removeItemsByPackageName(packageNames, user);
4288 }
4289 if (!components.isEmpty()) {
4290 mWorkspace.removeItemsByComponentName(components, user);
4291 }
4292 // Notify the drag controller
4293 mDragController.onAppsRemoved(packageNames, components);
Winson Chung83892cc2013-05-01 16:53:33 -07004294
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004295 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004296
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004297 @Override
4298 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
4299 Runnable r = new Runnable() {
4300 public void run() {
4301 bindAppInfosRemoved(appInfos);
4302 }
4303 };
4304 if (waitUntilResume(r)) {
4305 return;
Joe Onorato36115782010-06-17 13:28:48 -04004306 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004307
Winson Chungdf95eb12013-10-16 14:57:07 -07004308 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004309 if (mAppsView != null) {
4310 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004311 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004312 }
Joe Onoratobe386092009-11-17 17:32:16 -08004313
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004314 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004315 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004316 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004317 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004318 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004319
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004320 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004321 public void bindWidgetsModel(WidgetsModel model) {
4322 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004323 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004324 return;
4325 }
4326
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004327 if (mWidgetsView != null && model != null) {
4328 mWidgetsView.addWidgets(model);
4329 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004330 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004331 }
4332
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004333 @Override
4334 public void notifyWidgetProvidersChanged() {
4335 if (mWorkspace.getState().shouldUpdateWidget) {
4336 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4337 }
4338 }
4339
Winson Chung400438b2011-01-16 17:53:48 -08004340 private int mapConfigurationOriActivityInfoOri(int configOri) {
4341 final Display d = getWindowManager().getDefaultDisplay();
4342 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4343 switch (d.getRotation()) {
4344 case Surface.ROTATION_0:
4345 case Surface.ROTATION_180:
4346 // We are currently in the same basic orientation as the natural orientation
4347 naturalOri = configOri;
4348 break;
4349 case Surface.ROTATION_90:
4350 case Surface.ROTATION_270:
4351 // We are currently in the other basic orientation to the natural orientation
4352 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4353 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4354 break;
4355 }
4356
4357 int[] oriMap = {
4358 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4359 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4360 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4361 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4362 };
4363 // Since the map starts at portrait, we need to offset if this device's natural orientation
4364 // is landscape.
4365 int indexOffset = 0;
4366 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4367 indexOffset = 1;
4368 }
4369 return oriMap[(d.getRotation() + indexOffset) % 4];
4370 }
Adam Cohen446e9402011-09-15 18:21:21 -07004371
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004372 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004373 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004374 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004375 if (Utilities.ATLEAST_JB_MR2) {
4376 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4377 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004378 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4379 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004380 }
Winson Chung4b919f82012-05-01 10:44:08 -07004381 }
4382 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004383
Winson Chung4b919f82012-05-01 10:44:08 -07004384 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004385 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004386 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004387 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004388 } else {
4389 mHandler.postDelayed(new Runnable() {
4390 public void run() {
4391 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4392 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004393 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004394 }
Winson Chung4b919f82012-05-01 10:44:08 -07004395 }
Winson Chung400438b2011-01-16 17:53:48 -08004396 }
4397
Adam Cohenea90f832014-05-21 15:03:34 -07004398 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004399 * To be overridden by subclasses to indicate that there is an activity to launch
4400 * before showing the standard launcher experience.
4401 */
4402 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004403 if (mLauncherCallbacks != null) {
4404 return mLauncherCallbacks.hasFirstRunActivity();
4405 }
Adam Cohen432609a2014-03-13 17:03:22 -07004406 return false;
4407 }
4408
4409 /**
4410 * To be overridden by subclasses to launch any first run activity
4411 */
4412 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004413 if (mLauncherCallbacks != null) {
4414 return mLauncherCallbacks.getFirstRunActivity();
4415 }
Adam Cohen432609a2014-03-13 17:03:22 -07004416 return null;
4417 }
4418
Winson Chunga6945242014-01-08 14:04:34 -08004419 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004420 return !ActivityManager.isRunningInTestHarness() &&
4421 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004422 }
4423
Adam Cohen4a9423d2014-03-28 14:22:31 -07004424 protected boolean hasRunFirstRunActivity() {
4425 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4426 }
4427
Adam Cohen432609a2014-03-13 17:03:22 -07004428 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004429 if (shouldRunFirstRunActivity() &&
4430 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004431 Intent firstRunIntent = getFirstRunActivity();
4432 if (firstRunIntent != null) {
4433 startActivity(firstRunIntent);
4434 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004435 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004436 }
4437 }
Adam Cohen432609a2014-03-13 17:03:22 -07004438 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004439 }
4440
4441 private void markFirstRunActivityShown() {
4442 SharedPreferences.Editor editor = mSharedPrefs.edit();
4443 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4444 editor.apply();
4445 }
4446
Adam Cohen432609a2014-03-13 17:03:22 -07004447 /**
4448 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4449 * screen that must be displayed and dismissed.
4450 */
4451 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004452 if (mLauncherCallbacks != null) {
4453 return mLauncherCallbacks.hasDismissableIntroScreen();
4454 }
Adam Cohen432609a2014-03-13 17:03:22 -07004455 return false;
4456 }
4457
4458 /**
4459 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4460 */
4461 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004462 if (mLauncherCallbacks != null) {
4463 return mLauncherCallbacks.getIntroScreen();
4464 }
Adam Cohen432609a2014-03-13 17:03:22 -07004465 return null;
4466 }
4467
4468 /**
4469 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4470 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4471 */
4472 private boolean shouldShowIntroScreen() {
4473 return hasDismissableIntroScreen() &&
4474 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4475 }
4476
4477 protected void showIntroScreen() {
4478 View introScreen = getIntroScreen();
4479 changeWallpaperVisiblity(false);
4480 if (introScreen != null) {
4481 mDragLayer.showOverlayView(introScreen);
4482 }
4483 }
4484
4485 public void dismissIntroScreen() {
4486 markIntroScreenDismissed();
4487 if (showFirstRunActivity()) {
4488 // We delay hiding the intro view until the first run activity is showing. This
4489 // avoids a blip.
4490 mWorkspace.postDelayed(new Runnable() {
4491 @Override
4492 public void run() {
4493 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004494 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004495 }
4496 }, ACTIVITY_START_DELAY);
4497 } else {
4498 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004499 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004500 }
4501 changeWallpaperVisiblity(true);
4502 }
4503
4504 private void markIntroScreenDismissed() {
4505 SharedPreferences.Editor editor = mSharedPrefs.edit();
4506 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4507 editor.apply();
4508 }
4509
Adam Cohen091440a2015-03-18 14:16:05 -07004510 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004511 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4512 // on the device, then we always show the first run cling experience (or if there is no
4513 // launcher2). Otherwise, we prompt the user upon started for migration
4514 LauncherClings launcherClings = new LauncherClings(this);
4515 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004516 mClings = launcherClings;
Sunny Goyal1acb9e92016-05-16 12:41:09 -07004517 if (canMigrateFromOldLauncherDb()) {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004518 launcherClings.showMigrationCling();
4519 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004520 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004521 }
4522 }
4523 }
4524
Sunny Goyal1acb9e92016-05-16 12:41:09 -07004525 private boolean canMigrateFromOldLauncherDb() {
4526 // Return true if launcher was not preinstalled and and old content provider exists.
4527 return ((getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) &&
4528 providerExists(MIGRATE_AUTHORITY) &&
4529 providerExists(Uri.parse(getString(R.string.old_launcher_provider_uri)).getAuthority());
4530
4531 }
4532
4533 private boolean providerExists(String authority) {
4534 return getPackageManager().resolveContentProvider(authority, 0) != null;
4535 }
4536
4537
Winson Chunga6945242014-01-08 14:04:34 -08004538 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004539 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4540 if (mHotseat != null) mHotseat.setAlpha(1f);
Tony Wickhamf549dab2016-05-16 09:54:06 -07004541 if (mPageIndicator != null) mPageIndicator.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004542 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4543 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004544 }
4545
4546 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004547 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4548 if (mHotseat != null) mHotseat.setAlpha(0f);
Tony Wickhamf549dab2016-05-16 09:54:06 -07004549 if (mPageIndicator != null) mPageIndicator.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004550 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4551 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004552 }
4553
Winson Chung5ffd51d2015-06-25 11:36:50 -07004554 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004555 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004556 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004557 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004558 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004559 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004560 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4561 if (userHandle != null) {
4562 user = UserHandleCompat.fromUser(userHandle);
4563 }
4564 }
4565 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004566 }
4567
4568 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004569 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004570 if (user == null) {
4571 user = UserHandleCompat.myUserHandle();
4572 }
4573
4574 // Called from search suggestion, add the profile extra to the intent to ensure that we
4575 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004576 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004577 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004578 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004579 return null;
4580 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004581 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004582 }
4583
Winson Chung5ffd51d2015-06-25 11:36:50 -07004584 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004585 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4586 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004587 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004588 UserHandleCompat.myUserHandle());
4589 }
4590
Winson Chung5ffd51d2015-06-25 11:36:50 -07004591 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004592 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4593 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004594 mWorkspace.onExternalDragStartedWithItem(dragView);
4595 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004596 }
4597
Winson Chung5ffd51d2015-06-25 11:36:50 -07004598 protected void moveWorkspaceToDefaultScreen() {
4599 mWorkspace.moveToDefaultScreen(false);
4600 }
4601
Winson Chung80baf5a2010-08-09 16:03:15 -07004602 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004603 * Returns a FastBitmapDrawable with the icon, accurately sized.
4604 */
4605 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4606 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4607 d.setFilterBitmap(true);
4608 resizeIconDrawable(d);
4609 return d;
4610 }
4611
4612 /**
4613 * Resizes an icon drawable to the correct icon size.
4614 */
Winson5fbe0742015-09-30 15:33:00 -07004615 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004616 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004617 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004618 }
4619
4620 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004621 * Prints out out state for debugging.
4622 */
4623 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004624 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004625 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004626 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4627 Log.d(TAG, "mRestoring=" + mRestoring);
4628 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Joe Onoratobe386092009-11-17 17:32:16 -08004629 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004630 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004631
Daniel Sandler325dc232013-06-05 22:57:57 -04004632 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004633 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004634
4635 @Override
4636 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4637 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004638 // Dump workspace
4639 writer.println(prefix + "Workspace Items");
4640 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4641 writer.println(prefix + " Homescreen " + i);
4642
4643 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4644 for (int j = 0; j < layout.getChildCount(); j++) {
4645 Object tag = layout.getChildAt(j).getTag();
4646 if (tag != null) {
4647 writer.println(prefix + " " + tag.toString());
4648 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004649 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004650 }
Sunny Goyala1365452015-10-01 15:46:24 -07004651
4652 writer.println(prefix + " Hotseat");
4653 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4654 for (int j = 0; j < layout.getChildCount(); j++) {
4655 Object tag = layout.getChildAt(j).getTag();
4656 if (tag != null) {
4657 writer.println(prefix + " " + tag.toString());
4658 }
4659 }
4660
Sunny Goyal713edfc2016-05-06 09:58:34 -07004661 try {
4662 FileLog.flushAll(writer);
4663 } catch (Exception e) {
4664 // Ignore
Sunny Goyala1365452015-10-01 15:46:24 -07004665 }
4666
Adam Cohen9211d422014-10-07 18:14:53 -07004667 if (mLauncherCallbacks != null) {
4668 mLauncherCallbacks.dump(prefix, fd, writer, args);
4669 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004670 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004671
Adam Cohen59400422014-03-05 18:07:04 -08004672 public static CustomAppWidget getCustomAppWidget(String name) {
4673 return sCustomAppWidgets.get(name);
4674 }
4675
4676 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4677 return sCustomAppWidgets;
4678 }
4679
Sunny Goyal29538332016-02-18 09:10:19 -08004680 public static List<View> getFolderContents(View icon) {
4681 if (icon instanceof FolderIcon) {
4682 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4683 } else {
4684 return Collections.EMPTY_LIST;
4685 }
4686 }
Sunny Goyal745bad92016-05-02 10:54:12 -07004687
4688 private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable {
4689
4690 @Override
4691 public void onSharedPreferenceChanged(
4692 SharedPreferences sharedPreferences, String key) {
4693 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
4694 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
4695 if (!waitUntilResume(this, true)) {
4696 run();
4697 }
4698 }
4699 }
4700
4701 @Override
4702 public void run() {
4703 setOrientation();
4704 }
4705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004706}
Michael Jurka2763be32011-02-24 11:19:57 -08004707
Dan Sandlerd5024042014-01-09 15:01:33 -05004708interface DebugIntents {
4709 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4710 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004711}