blob: 545768f51a21cf8c0901a0b994b36e720368cf2c [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyal28c6b962015-10-12 11:42:05 -070019import android.Manifest;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070025import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Sunny Goyal756cd262015-08-20 12:33:21 -070039import android.content.ContentValues;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070051import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Tony Wickhama3c74d12015-10-23 11:43:47 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070069import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070078import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.MotionEvent;
80import android.view.Surface;
81import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070082import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070085import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import 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;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070089import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080093import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070095
Sunny Goyal651077b2014-06-30 14:15:31 -070096import com.android.launcher3.DropTarget.DragObject;
97import com.android.launcher3.PagedView.PageSwitchListener;
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;
Adam Cohenf9c184a2016-01-15 16:47:43 -0800110import com.android.launcher3.folder.Folder;
111import com.android.launcher3.folder.FolderIcon;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700112import com.android.launcher3.model.WidgetsModel;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700113import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700114import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700115import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700116import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700117import com.android.launcher3.util.ViewOnDrawExecutor;
Sunny Goyal5abb9f82016-02-09 15:22:42 -0800118import com.android.launcher3.util.WallpaperUtils;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700119import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700120import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700121import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700122
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700123import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700124import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700127import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700128import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700129import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700130import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700131import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133/**
134 * Default launcher application.
135 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100136public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700137 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chung006ee262015-08-03 14:40:11 -0700138 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700139 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700143 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700144 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700146
Dan Sandlerd5024042014-01-09 15:01:33 -0500147 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
148
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700152 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Michael Jurka8b805b12012-04-18 14:23:14 -0700154 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700155 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700156
Sunny Goyal28c6b962015-10-12 11:42:05 -0700157 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
158
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700159 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
160 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
161 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
162
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700163 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
164
Mathew Inwood876a8462013-06-14 14:12:41 +0100165 /**
166 * IntentStarter uses request codes starting with this. This must be greater than all activity
167 * request codes used internally.
168 */
169 protected static final int REQUEST_LAST = 100;
170
Michael Jurka0a457bf2012-11-19 14:05:05 -0800171 // To turn on these properties, type
172 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800173 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
Winson Chung2672ff92012-05-04 16:22:30 -0700175 // The Intent extra that defines whether to ignore the launch animation
176 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400177 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 // Type: int
180 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700181 // Type: int
182 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal08442b82015-10-21 17:15:08 -0700183 // Type: long
184 private static final String RUNTIME_STATE_OPEN_FOLDER_ID = "launcher.open_folder_id";
Sunny Goyal756cd262015-08-20 12:33:21 -0700185 // Type: Content Values / parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700187 // Type: parcelable
188 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000189 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800190 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
Adam Cohen432609a2014-03-13 17:03:22 -0700192 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800193 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
194
Adam Cohen3ed316a2014-07-23 18:21:20 -0700195 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
196 static final String ACTION_FIRST_LOAD_COMPLETE =
197 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
198
Sunny Goyal594d76d2014-11-06 10:12:54 -0800199 private static final String QSB_WIDGET_ID = "qsb_widget_id";
200 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
201
Winson Chunga6945242014-01-08 14:04:34 -0800202 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
203
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700204 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700205 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
206 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700207
Adam Cohen091440a2015-03-18 14:16:05 -0700208 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700209 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700210
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700211 private boolean mIsSafeModeEnabled;
212
Adam Cohenc2d6e892014-10-16 09:49:24 -0700213 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
214 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700215 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700216
Joe Onorato9c1289c2009-08-17 11:03:03 -0400217 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700218 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
219 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700220 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
Winson Chunga2413752012-04-03 14:22:34 -0700222 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700223 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
224 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700225 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700226
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800227 private final BroadcastReceiver mCloseSystemDialogsReceiver
228 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800229
Adam Cohen091440a2015-03-18 14:16:05 -0700230 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700231 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800232 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700233 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800234 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700235
236 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700237
Sunny Goyalffe83f12014-08-14 17:39:34 -0700238 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700239 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700240
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700241 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800242 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800243 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700244
Michael Jurka0280c3b2010-09-17 15:00:07 -0700245 private int[] mTmpAddItemCellCoordinates = new int[2];
246
Sunny Goyal316490e2015-06-02 09:38:28 -0700247 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800248 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700249
Michael Jurka838a4ca2011-02-07 13:33:06 -0800250 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700251 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700252
Winson Chungc51db6a2011-10-05 11:44:49 -0700253 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700254 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700255
256 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700257 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700258
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700259 // Main container view and the model for the widget tray screen.
260 @Thunk WidgetsContainerView mWidgetsView;
261 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700262
Sunny Goyal594d76d2014-11-06 10:12:54 -0800263 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
267 // scroll issues (because the workspace may not have been measured yet) and extra work.
268 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
269 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
271 private SpannableStringBuilder mDefaultKeySsb = null;
272
Adam Cohen091440a2015-03-18 14:16:05 -0700273 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800275 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 private boolean mRestoring;
277 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700278 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279
Michael Jurka1e2f4652013-07-08 18:03:46 -0700280 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700281 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700282 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700283
Joe Onorato9c1289c2009-08-17 11:03:03 -0400284 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800285 private IconCache mIconCache;
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
Sunny Goyale2df0622015-04-24 11:27:00 -0700293 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700294
Adam Cohen61f560d2013-09-30 15:58:20 -0700295 private View.OnTouchListener mHapticFeedbackTouchListener;
296
Adam Cohended9f8d2010-11-03 13:25:16 -0700297 // Related to the auto-advancing of widgets
298 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700299 private static final int ADVANCE_INTERVAL = 20000;
300 private static final int ADVANCE_STAGGER = 250;
301
302 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700303 private long mAutoAdvanceSentTime;
304 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700305 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700306
Winson Chung400438b2011-01-16 17:53:48 -0800307 // Determines how long to wait after a rotation before restoring the screen orientation to
308 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700309 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800310
Adam Cohen091440a2015-03-18 14:16:05 -0700311 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700312
Adam Cohen1462de32012-07-24 22:34:36 -0700313 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700314 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700315
Sunny Goyala1365452015-10-01 15:46:24 -0700316 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
317 private static final Date sDateStamp = new Date();
318 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700319 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700320
Winson Chung46353de2012-02-16 14:05:10 -0800321 // We only want to get the SharedPreferences once since it does an FS stat each time we get
322 // it from the context.
323 private SharedPreferences mSharedPrefs;
324
Winson Chungf0c6ae02012-03-21 16:10:31 -0700325 // Holds the page that we need to animate to, and the icon views that we need to animate up
326 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700327 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700328 private Bitmap mFolderIconBitmap;
329 private Canvas mFolderIconCanvas;
330 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700331
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700332 private DeviceProfile mDeviceProfile;
333
Adam Cohen4b66bf32015-09-18 12:15:19 -0700334 private boolean mMoveToDefaultScreenFromNewIntent;
335
Winson Chung13eb5272015-05-11 16:30:13 -0700336 // This is set to the view that launched the activity that navigated the user away from
337 // launcher. Since there is no callback for when the activity has finished launching, enable
338 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800339 private BubbleTextView mWaitingForResume;
340
Adam Cohen59400422014-03-05 18:07:04 -0800341 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
342 new HashMap<String, CustomAppWidget>();
343
Adam Cohen59400422014-03-05 18:07:04 -0800344 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700345 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
346 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800347 }
348 }
349
Adam Cohen091440a2015-03-18 14:16:05 -0700350 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700351 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700352 if (mWorkspace != null) {
353 mWorkspace.buildPageHardwareLayers();
354 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700355 }
356 };
357
Adam Cohendb364c32014-05-20 14:23:40 -0700358 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800359
Adam Cohen091440a2015-03-18 14:16:05 -0700360 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 int requestCode;
362 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700363 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700364 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 int cellX;
366 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700367 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800368 }
369
Daniel Sandlerff02d492013-08-05 02:12:05 -0400370 private Stats mStats;
Adam Cohenf9c184a2016-01-15 16:47:43 -0800371 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700372 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400373
374 @Thunk void setOrientation() {
375 if (mRotationEnabled) {
376 unlockScreenOrientation(true);
377 } else {
378 setRequestedOrientation(
379 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700380 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400381 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700382
Sunny Goyal7779d622015-06-11 16:18:39 -0700383 private Runnable mUpdateOrientationRunnable = new Runnable() {
384 public void run() {
385 setOrientation();
386 }
387 };
388
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 @Override
390 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700391 if (DEBUG_STRICT_MODE) {
392 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
393 .detectDiskReads()
394 .detectDiskWrites()
395 .detectNetwork() // or .detectAll() for all detectable problems
396 .penaltyLog()
397 .build());
398 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
399 .detectLeakedSqlLiteObjects()
400 .detectLeakedClosableObjects()
401 .penaltyLog()
402 .penaltyDeath()
403 .build());
404 }
405
Adam Cohen9211d422014-10-07 18:14:53 -0700406 if (mLauncherCallbacks != null) {
407 mLauncherCallbacks.preOnCreate();
408 }
409
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400411
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400412 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700413
Adam Cohen2e6da152015-05-06 11:42:25 -0700414 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700415 mDeviceProfile = getResources().getConfiguration().orientation
416 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700417 app.getInvariantDeviceProfile().landscapeProfile
418 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700419
Sunny Goyalf7258242015-10-19 16:59:07 -0700420 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700421 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800422 mModel = app.setLauncher(this);
423 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700424
Joe Onorato41a12d22009-10-31 18:30:00 -0400425 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700426 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700427
Daniel Sandlerff02d492013-08-05 02:12:05 -0400428 mStats = new Stats(this);
429
Sunny Goyalffe83f12014-08-14 17:39:34 -0700430 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700431
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700432 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
433 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700434
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700435 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
436 // this also ensures that any synchronous binding below doesn't re-trigger another
437 // LauncherModel load.
438 mPaused = false;
439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200441 android.os.Debug.startMethodTracing(
442 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 }
444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700446
Tony Wickhameef44322015-10-20 13:24:36 -0700447 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
448 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700450 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451
Joe Onorato7c312c12009-08-13 21:36:53 -0700452 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700453
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 mSavedState = savedInstanceState;
455 restoreState(mSavedState);
456
457 if (PROFILE_STARTUP) {
458 android.os.Debug.stopMethodTracing();
459 }
460
461 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700462 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 // If the user leaves launcher, then we should just load items asynchronously when
464 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700465 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 } else {
467 // We only load the page synchronously if the user rotates (or triggers a
468 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700469 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700470 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 }
472
473 // For handling default keys
474 mDefaultKeySsb = new SpannableStringBuilder();
475 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800476
477 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
478 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800479
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700480 mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
481 // In case we are on a device with locked rotation, we should look at preferences to check
482 // if the user has specifically allowed rotation.
483 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700484 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700485 }
486
487 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
488 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400489 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700490
Adam Cohen9211d422014-10-07 18:14:53 -0700491 if (mLauncherCallbacks != null) {
492 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700493 if (mLauncherCallbacks.hasLauncherOverlay()) {
494 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700495 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
496 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
497 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700498 mWorkspace.setLauncherOverlay(mLauncherOverlay);
499 }
Adam Cohen9211d422014-10-07 18:14:53 -0700500 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700501
502 if (shouldShowIntroScreen()) {
503 showIntroScreen();
504 } else {
505 showFirstRunActivity();
506 showFirstRunClings();
507 }
Adam Cohen9211d422014-10-07 18:14:53 -0700508 }
509
Sunny Goyal7779d622015-06-11 16:18:39 -0700510 @Override
511 public void onSettingsChanged(String settings, boolean value) {
512 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
513 mRotationEnabled = value;
514 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
515 mUpdateOrientationRunnable.run();
516 }
517 }
518 }
519
Adam Cohen9211d422014-10-07 18:14:53 -0700520 private LauncherCallbacks mLauncherCallbacks;
521
522 public void onPostCreate(Bundle savedInstanceState) {
523 super.onPostCreate(savedInstanceState);
524 if (mLauncherCallbacks != null) {
525 mLauncherCallbacks.onPostCreate(savedInstanceState);
526 }
527 }
528
529 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
530 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700531 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700532 private boolean mWorkspaceImportanceStored = false;
533 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700534 private int mWorkspaceImportanceForAccessibility =
535 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
536 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
537
538 @Override
539 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700540 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700541 return;
542 }
543 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700544 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700545 if (mWorkspace != null) {
546 mWorkspaceImportanceForAccessibility =
547 mWorkspace.getImportantForAccessibility();
548 mWorkspace.setImportantForAccessibility(
549 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
550 mWorkspaceImportanceStored = true;
551 }
552 if (mHotseat != null) {
553 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
554 mHotseat.setImportantForAccessibility(
555 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
556 mHotseatImportanceStored = true;
557 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700558 }
559
560 @Override
561 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700562 if (mWorkspaceImportanceStored && mWorkspace != null) {
563 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
564 }
565 if (mHotseatImportanceStored && mHotseat != null) {
566 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
567 }
568 mWorkspaceImportanceStored = false;
569 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700570 }
571 });
Adam Cohen9211d422014-10-07 18:14:53 -0700572 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700573 }
574
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700575 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700576 public void onLauncherProviderChange() {
577 if (mLauncherCallbacks != null) {
578 mLauncherCallbacks.onLauncherProviderChange();
579 }
580 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700581
Winson Chungef7f8742015-06-04 17:18:17 -0700582 /**
583 * Updates the bounds of all the overlays to match the new fixed bounds.
584 */
585 public void updateOverlayBounds(Rect newBounds) {
586 mAppsView.setSearchBarBounds(newBounds);
587 mWidgetsView.setSearchBarBounds(newBounds);
588 }
589
Adam Cohen9211d422014-10-07 18:14:53 -0700590 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700591 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700592 if (mLauncherCallbacks != null) {
593 return mLauncherCallbacks.hasCustomContentToLeft();
594 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700595 return false;
596 }
597
Dave Hawkeya8881582013-09-17 15:55:33 -0600598 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500599 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600600 * {@link #addToCustomContentPage}. This will only be invoked if
601 * {@link #hasCustomContentToLeft()} is {@code true}.
602 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500603 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700604 if (mLauncherCallbacks != null) {
605 mLauncherCallbacks.populateCustomContentContainer();
606 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600607 }
608
609 /**
610 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
611 * ensure the custom content page is added or removed if necessary.
612 */
613 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600614 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600615 // Not bound yet, wait for bindScreens to be called.
616 return;
617 }
618
619 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
620 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500621 mWorkspace.createCustomContentContainer();
622 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600623 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
624 mWorkspace.removeCustomContentPage();
625 }
626 }
627
Anton Hanssona2f665f2013-09-26 12:18:32 +0100628 public Stats getStats() {
629 return mStats;
630 }
631
Hyunyoung Song3f471442015-04-08 19:01:34 -0700632 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700633 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
634 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700635 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700636 }
637
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000638 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700639 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
640 // This cast is safe as long as the id < 0x00FFFFFF
641 // Since we jail all the dynamically generated views, there should be no clashes
642 // with any other views.
643 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000644 }
645
646 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700647 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
648 * a configuration step, this allows the proper animations to run after other transitions.
649 */
Adam Cohendb364c32014-05-20 14:23:40 -0700650 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700651 long screenId = args.screenId;
652 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
653 // When the screen id represents an actual screen (as opposed to a rank) we make sure
654 // that the drop page actually exists.
655 screenId = ensurePendingDropLayoutExists(args.screenId);
656 }
Adam Cohendb364c32014-05-20 14:23:40 -0700657
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800658 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800659 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700660 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700661 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700662 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800663 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700664 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700665 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700666 case REQUEST_RECONFIGURE_APPWIDGET:
667 completeRestoreAppWidget(args.appWidgetId);
668 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800669 }
Michael Jurka27614d22012-04-02 06:40:22 -0700670 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
671 // if you turned the screen off and then back while in All Apps, Launcher would not
672 // return to the workspace. Clearing mAddInfo.container here fixes this issue
673 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700674 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800675 }
676
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800677 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700678 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700679 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700680 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700681 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800682 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700683
Adam Cohenad4e15c2013-10-17 16:21:35 -0700684 Runnable exitSpringLoaded = new Runnable() {
685 @Override
686 public void run() {
687 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
688 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
689 }
690 };
691
Michael Jurka8b805b12012-04-18 14:23:14 -0700692 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700693 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700694 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700695 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
696 if (resultCode == RESULT_CANCELED) {
697 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700698 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700699 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700700 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800701 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700702 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700703
704 // When the user has granted permission to bind widgets, we should check to see if
705 // we can inflate the default search bar widget.
706 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700707 }
708 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200709 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
710 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700711 // User could have free-scrolled between pages before picking a wallpaper; make sure
712 // we move to the closest one now.
713 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700714 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200715 }
716 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700717 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200718
Adam Cohened66b2b2012-01-23 17:28:51 -0800719 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700720 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700721
Adam Cohendb364c32014-05-20 14:23:40 -0700722 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800723 // We have special handling for widgets
724 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800725 final int appWidgetId;
726 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
727 : -1;
728 if (widgetId < 0) {
729 appWidgetId = pendingAddWidgetId;
730 } else {
731 appWidgetId = widgetId;
732 }
733
Adam Cohenad4e15c2013-10-17 16:21:35 -0700734 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800735 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700736 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
737 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700738 result = RESULT_CANCELED;
739 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700740 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700741 @Override
742 public void run() {
743 exitSpringLoadedDragModeDelayed(false, 0, null);
744 }
745 };
Adam Cohendb364c32014-05-20 14:23:40 -0700746 if (workspaceLocked) {
747 // No need to remove the empty screen if we're mid-binding, as the
748 // the bind will not add the empty screen.
749 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
750 } else {
751 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
752 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
753 }
Winson Chung5aaab772012-04-27 15:24:02 -0700754 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700755 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700756 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
757 // When the screen id represents an actual screen (as opposed to a rank)
758 // we make sure that the drop page actually exists.
759 mPendingAddInfo.screenId =
760 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
761 }
Adam Cohendb364c32014-05-20 14:23:40 -0700762 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
763
764 dropLayout.setDropPending(true);
765 final Runnable onComplete = new Runnable() {
766 @Override
767 public void run() {
768 completeTwoStageWidgetDrop(resultCode, appWidgetId);
769 dropLayout.setDropPending(false);
770 }
771 };
772 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
773 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
774 } else {
775 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
776 mPendingAddInfo);
777 sPendingAddItem = args;
778 }
Winson Chung5aaab772012-04-27 15:24:02 -0700779 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800780 return;
781 }
782
Sunny Goyalff572272014-07-23 13:58:07 -0700783 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
784 if (resultCode == RESULT_OK) {
785 // Update the widget view.
786 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
787 pendingAddWidgetId, mPendingAddInfo);
788 if (workspaceLocked) {
789 sPendingAddItem = args;
790 } else {
791 completeAdd(args);
792 }
793 }
794 // Leave the widget in the pending state if the user canceled the configure.
795 return;
796 }
797
Sunny Goyalaad90582015-07-09 14:22:50 -0700798 if (requestCode == REQUEST_CREATE_SHORTCUT) {
799 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
800 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
801 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
802 mPendingAddInfo);
803 if (isWorkspaceLocked()) {
804 sPendingAddItem = args;
805 } else {
806 completeAdd(args);
807 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
808 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
809 }
810 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700811 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
812 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800815 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800816
817 }
818
819 @Override
820 protected void onActivityResult(
821 final int requestCode, final int resultCode, final Intent data) {
822 handleActivityResult(requestCode, resultCode, data);
823 if (mLauncherCallbacks != null) {
824 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
825 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800826 }
827
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600828 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700829 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600830 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700831 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
832 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
833 View v = null;
834 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
835 if (layout != null) {
836 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
837 }
838 Intent intent = sPendingAddItem.intent;
839 sPendingAddItem = null;
840 if (grantResults.length > 0
841 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
842 startActivity(v, intent, null);
843 } else {
844 // TODO: Show a snack bar with link to settings
845 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
846 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
847 }
848 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600849 if (mLauncherCallbacks != null) {
850 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
851 grantResults);
852 }
853 }
854
Adam Cohendb364c32014-05-20 14:23:40 -0700855 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
856 appWidgetId, ItemInfo info) {
857 PendingAddArguments args = new PendingAddArguments();
858 args.requestCode = requestCode;
859 args.intent = data;
860 args.container = info.container;
861 args.screenId = info.screenId;
862 args.cellX = info.cellX;
863 args.cellY = info.cellY;
864 args.appWidgetId = appWidgetId;
865 return args;
866 }
867
868 /**
869 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
870 *
871 * @param screenId the screen id to check
872 * @return the new screen, or screenId if it exists
873 */
874 private long ensurePendingDropLayoutExists(long screenId) {
875 CellLayout dropLayout =
876 (CellLayout) mWorkspace.getScreenWithId(screenId);
877 if (dropLayout == null) {
878 // it's possible that the add screen was removed because it was
879 // empty and a re-bind occurred
880 mWorkspace.addExtraEmptyScreen();
881 return mWorkspace.commitExtraEmptyScreen();
882 } else {
883 return screenId;
884 }
885 }
886
Adam Cohen091440a2015-03-18 14:16:05 -0700887 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800888 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800889 Runnable onCompleteRunnable = null;
890 int animationType = 0;
891
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700892 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 if (resultCode == RESULT_OK) {
894 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
895 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700896 mPendingAddWidgetInfo);
897 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800898 onCompleteRunnable = new Runnable() {
899 @Override
900 public void run() {
901 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700902 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700903 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
904 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800905 }
906 };
907 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800908 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800909 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800910 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700911 if (mDragLayer.getAnimatedView() != null) {
912 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
913 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
914 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700915 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700916 // The animated view may be null in the case of a rotation during widget configuration
917 onCompleteRunnable.run();
918 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800919 }
920
921 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700922 protected void onStop() {
923 super.onStop();
924 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700925
926 if (mLauncherCallbacks != null) {
927 mLauncherCallbacks.onStop();
928 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700929 }
930
931 @Override
932 protected void onStart() {
933 super.onStart();
934 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700935
936 if (mLauncherCallbacks != null) {
937 mLauncherCallbacks.onStart();
938 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700939 }
940
941 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800942 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200943 long startTime = 0;
944 if (DEBUG_RESUME_TIME) {
945 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400946 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200947 }
Adam Cohen9211d422014-10-07 18:14:53 -0700948
949 if (mLauncherCallbacks != null) {
950 mLauncherCallbacks.preOnResume();
951 }
952
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800953 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700954
Winson Chung4a2afa32012-07-19 14:53:05 -0700955 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700956 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700957 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800958 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700959 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700960 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700961 // view after launching an app, as they may be depending on the UI to be static to
962 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700963 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700964 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800965 } else if (mOnResumeState == State.WIDGETS) {
966 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700967 }
968 mOnResumeState = State.NONE;
969
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700970 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -0700971 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
972 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -0700973
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800974 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700975 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700976 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700977 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700979 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700981 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200982 // We might have postponed some bind calls until onResume (see waitUntilResume) --
983 // execute them here
984 long startTimeCallbacks = 0;
985 if (DEBUG_RESUME_TIME) {
986 startTimeCallbacks = System.currentTimeMillis();
987 }
988
Michael Jurka1e2f4652013-07-08 18:03:46 -0700989 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
990 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200991 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700992 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200993 if (DEBUG_RESUME_TIME) {
994 Log.d(TAG, "Time spent processing callbacks in onResume: " +
995 (System.currentTimeMillis() - startTimeCallbacks));
996 }
Michael Jurka447bf842013-05-15 14:52:15 +0200997 }
Michael Jurka54554252013-08-01 12:52:23 +0200998 if (mOnResumeCallbacks.size() > 0) {
999 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1000 mOnResumeCallbacks.get(i).run();
1001 }
1002 mOnResumeCallbacks.clear();
1003 }
Winson Chunge4e50662012-01-23 14:45:13 -08001004
1005 // Reset the pressed state of icons that were locked in the press state while activities
1006 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001007 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001008 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001009 mWaitingForResume.setStayPressed(false);
1010 }
Winson Chung82963d52013-10-09 11:20:57 -07001011
Adam Cohen06dff352012-06-01 17:17:08 -07001012 // It is possible that widgets can receive updates while launcher is not in the foreground.
1013 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1014 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1015 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001016 if (!isWorkspaceLoading()) {
1017 getWorkspace().reinflateWidgetsIfNecessary();
1018 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001019 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001020
Michael Jurka447bf842013-05-15 14:52:15 +02001021 if (DEBUG_RESUME_TIME) {
1022 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1023 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001024
Adam Cohen4b66bf32015-09-18 12:15:19 -07001025 // We want to suppress callbacks about CustomContent being shown if we have just received
1026 // onNewIntent while the user was present within launcher. In that case, we post a call
1027 // to move the user to the main screen (which will occur after onResume). We don't want to
1028 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1029 // suppress here.
1030 if (mWorkspace.getCustomContentCallbacks() != null
1031 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001032 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001033 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001034 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1035 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001036 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001037 }
1038 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001039 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001040 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001041 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001042
Sunny Goyal756adbc2015-04-16 15:20:51 -07001043 if (!isWorkspaceLoading()) {
1044 // Process any items that were added while Launcher was away.
1045 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1046 }
Adam Cohen9211d422014-10-07 18:14:53 -07001047
1048 if (mLauncherCallbacks != null) {
1049 mLauncherCallbacks.onResume();
1050 }
Adam Cohen06dff352012-06-01 17:17:08 -07001051 }
1052
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001054 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001055 // Ensure that items added to Launcher are queued until Launcher returns
1056 InstallShortcutReceiver.enableInstallQueue();
1057
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001058 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001059 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001060 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001061 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001062
1063 // We call onHide() aggressively. The custom content callbacks should be able to
1064 // debounce excess onHide calls.
1065 if (mWorkspace.getCustomContentCallbacks() != null) {
1066 mWorkspace.getCustomContentCallbacks().onHide();
1067 }
Romain Guycbb89e42009-06-08 15:52:54 -07001068
Adam Cohen9211d422014-10-07 18:14:53 -07001069 if (mLauncherCallbacks != null) {
1070 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001071 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001072 }
1073
1074 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001075 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1076 // by a onResume or by scrolling otherwise.
1077 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001078
1079 // Custom content is completely hidden
1080 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001081
1082 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1083 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001084
1085 // Indicates whether the user is allowed to scroll away from the custom content.
1086 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001087 }
1088
Adam Cohenc2d6e892014-10-16 09:49:24 -07001089 public interface LauncherOverlay {
1090
1091 /**
1092 * Touch interaction leading to overscroll has begun
1093 */
1094 public void onScrollInteractionBegin();
1095
1096 /**
1097 * Touch interaction related to overscroll has ended
1098 */
1099 public void onScrollInteractionEnd();
1100
1101 /**
1102 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1103 * screen (or in the case of RTL, the rightmost screen).
1104 */
1105 public void onScrollChange(int progress, boolean rtl);
1106
1107 /**
1108 * Screen has stopped scrolling
1109 */
1110 public void onScrollSettled();
1111
1112 /**
1113 * This method can be called by the Launcher in order to force the LauncherOverlay
1114 * to exit fully immersive mode.
1115 */
1116 public void forceExitFullImmersion();
1117 }
1118
Jun Mukai8af0cd82015-05-12 12:32:12 -07001119 public interface LauncherSearchCallbacks {
1120 /**
1121 * Called when the search overlay is shown.
1122 */
1123 public void onSearchOverlayOpened();
1124
1125 /**
1126 * Called when the search overlay is dismissed.
1127 */
1128 public void onSearchOverlayClosed();
1129 }
1130
Adam Cohenc2d6e892014-10-16 09:49:24 -07001131 public interface LauncherOverlayCallbacks {
1132 /**
1133 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1134 * however it doesn't modify any state within the launcher.
1135 */
1136 public boolean canEnterFullImmersion();
1137
1138 /**
1139 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1140 * eg. by occupying the full screen and handling all touch events.
1141 *
1142 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1143 * case, Launcher will modify any necessary state and assumes the overlay is
1144 * handling all interaction. If false, the LauncherOverlay should cancel any
1145 *
1146 */
1147 public boolean enterFullImmersion();
1148
1149 /**
1150 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1151 * full control over UI and state.
1152 */
1153 public void exitFullImmersion();
1154 }
1155
1156 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1157
1158 @Override
1159 public boolean canEnterFullImmersion() {
1160 return mState == State.WORKSPACE;
1161 }
1162
1163 @Override
1164 public boolean enterFullImmersion() {
1165 if (mState == State.WORKSPACE) {
1166 // When fully immersed, disregard any touches which fall through.
1167 mDragLayer.setBlockTouch(true);
1168 return true;
1169 }
1170 return false;
1171 }
1172
1173 @Override
1174 public void exitFullImmersion() {
1175 mDragLayer.setBlockTouch(false);
1176 }
1177 }
1178
Jorim Jaggid017f882014-01-14 17:08:48 -08001179 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001180 if (mLauncherCallbacks != null) {
1181 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001182 } else {
1183 // On devices with a locked orientation, we will at least have the allow rotation
1184 // setting.
1185 return !Utilities.isRotationAllowedForDevice(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001186 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001187 }
1188
Adam Cohen9211d422014-10-07 18:14:53 -07001189 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001190 CustomContentCallbacks callbacks, String description) {
1191 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001192 }
1193
Adam Cohenedb40762013-07-18 16:45:45 -07001194 // The custom content needs to offset its content to account for the QSB
1195 public int getTopOffsetForCustomContent() {
1196 return mWorkspace.getPaddingTop();
1197 }
1198
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001199 @Override
1200 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001201 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001202 if (mModel.isCurrentCallbacks(this)) {
1203 mModel.stopLoader();
1204 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001205 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1206
Romain Guy13c2e7b2010-03-10 19:45:00 -08001207 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001208 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001209
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001210 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001211 @Override
1212 public void onWindowFocusChanged(boolean hasFocus) {
1213 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001214 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001215
1216 if (mLauncherCallbacks != null) {
1217 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1218 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001219 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001220
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221 private boolean acceptFilter() {
1222 final InputMethodManager inputManager = (InputMethodManager)
1223 getSystemService(Context.INPUT_METHOD_SERVICE);
1224 return !inputManager.isFullscreenMode();
1225 }
1226
1227 @Override
1228 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001229 final int uniChar = event.getUnicodeChar();
1230 final boolean handled = super.onKeyDown(keyCode, event);
1231 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1232 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1234 keyCode, event);
1235 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001236 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001237 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001238 // showSearchDialog()
1239 // If there are multiple keystrokes before the search dialog takes focus,
1240 // onSearchRequested() will be called for every keystroke,
1241 // but it is idempotent, so it's fine.
1242 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 }
1244 }
1245
Joe Onorato8a9625e2010-01-28 15:55:35 -08001246 // Eat the long press event so the keyboard doesn't come up.
1247 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1248 return true;
1249 }
1250
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 return handled;
1252 }
1253
Winson46163472015-09-22 17:31:56 -07001254 @Override
1255 public boolean onKeyUp(int keyCode, KeyEvent event) {
1256 if (keyCode == KeyEvent.KEYCODE_MENU) {
1257 // Ignore the menu key if we are currently dragging or are on the custom content screen
1258 if (!isOnCustomContent() && !mDragController.isDragging()) {
1259 // Close any open folders
1260 closeFolder();
1261
1262 // Stop resizing any widgets
1263 mWorkspace.exitWidgetResizeMode();
1264
1265 // Show the overview mode if we are on the workspace
1266 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1267 !mWorkspace.isSwitchingState()) {
1268 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001269 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001270 }
1271 }
1272 return true;
1273 }
1274 return super.onKeyUp(keyCode, event);
1275 }
1276
Karl Rosaen138a0412009-04-23 19:00:21 -07001277 private String getTypedText() {
1278 return mDefaultKeySsb.toString();
1279 }
1280
1281 private void clearTypedText() {
1282 mDefaultKeySsb.clear();
1283 mDefaultKeySsb.clearSpans();
1284 Selection.setSelection(mDefaultKeySsb, 0);
1285 }
1286
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001288 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1289 * State
1290 */
1291 private static State intToState(int stateOrdinal) {
1292 State state = State.WORKSPACE;
1293 final State[] stateValues = State.values();
1294 for (int i = 0; i < stateValues.length; i++) {
1295 if (stateValues[i].ordinal() == stateOrdinal) {
1296 state = stateValues[i];
1297 break;
1298 }
1299 }
1300 return state;
1301 }
1302
1303 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001304 * Restores the previous state, if it exists.
1305 *
1306 * @param savedState The previous state.
1307 */
1308 private void restoreState(Bundle savedState) {
1309 if (savedState == null) {
1310 return;
1311 }
1312
Michael Jurka883f55b2010-10-21 15:47:14 -07001313 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001314 if (state == State.APPS || state == State.WIDGETS) {
1315 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001316 }
1317
Adam Cohen21cd0022013-10-09 18:57:02 -07001318 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1319 PagedView.INVALID_RESTORE_PAGE);
1320 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001321 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 }
1323
Sunny Goyal756cd262015-08-20 12:33:21 -07001324 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1325 if (itemValues != null) {
1326 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001327 AppWidgetProviderInfo info = savedState.getParcelable(
1328 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001329 mPendingAddWidgetInfo = info == null ?
1330 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1331
Adam Cohen4637b5a2013-11-04 18:21:24 -08001332 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001333 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001334 mRestoring = true;
1335 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336 }
1337
1338 /**
1339 * Finds all the views we need and configure them properly.
1340 */
1341 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001342 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001343
Craig Mautner360310b2012-10-26 15:13:08 -07001344 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001345 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001346 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1347 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001348 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001349 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001350
John Spurlock77e1f472013-09-11 10:09:51 -04001351 mLauncherView.setSystemUiVisibility(
1352 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001353 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354
Winson Chung4c98d922011-05-31 16:50:48 -07001355 // Setup the drag layer
1356 mDragLayer.setup(this, dragController);
1357
Winson Chung3d503fb2011-07-13 17:25:49 -07001358 // Setup the hotseat
1359 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1360 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001361 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001362 }
1363
Winsone9f27272015-10-13 10:47:51 -07001364 // Setup the overview panel
1365 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001366
Winson Chung4c98d922011-05-31 16:50:48 -07001367 // Setup the workspace
1368 mWorkspace.setHapticFeedbackEnabled(false);
1369 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001370 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001371 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001372
Tony Wickham34d2c912015-09-11 09:27:58 -07001373 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001374 mSearchDropTargetBar = (SearchDropTargetBar)
1375 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001376 // Get the app info bar
1377 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1378 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001379
Winson Chungef7f8742015-06-04 17:18:17 -07001380 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001381 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001382 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyal954b7d32016-02-11 09:28:40 -08001383 mAppsView.setSearchBarController(new DefaultAppSearchController());
1384
1385 // TODO: Reenable this
1386// if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1387// mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1388// } else {
1389// mAppsView.setSearchBarController(new DefaultAppSearchController());
1390// }
Craig Mautner360310b2012-10-26 15:13:08 -07001391
Winson Chung3d503fb2011-07-13 17:25:49 -07001392 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001393 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001394 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001395 dragController.setMoveTarget(mWorkspace);
1396 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001397 if (mSearchDropTargetBar != null) {
1398 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001399 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001400 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001401 if (mAppInfoDropTargetBar != null) {
1402 mAppInfoDropTargetBar.setup(this, dragController);
1403 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001404
Sunny Goyal322d5562015-06-25 19:35:49 -07001405 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1406 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001407 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 }
1409
Winsone9f27272015-10-13 10:47:51 -07001410 private void setupOverviewPanel() {
1411 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1412
1413 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1414 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1415 @Override
1416 public boolean onLongClick(View v) {
1417 return v.performClick();
1418 }
1419 };
1420
1421 // Bind wallpaper button actions
1422 View wallpaperButton = findViewById(R.id.wallpaper_button);
1423 wallpaperButton.setOnClickListener(new OnClickListener() {
1424 @Override
1425 public void onClick(View view) {
1426 if (!mWorkspace.isSwitchingState()) {
1427 onClickWallpaperPicker(view);
1428 }
1429 }
1430 });
1431 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1432 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1433
1434 // Bind widget button actions
1435 mWidgetsButton = findViewById(R.id.widget_button);
1436 mWidgetsButton.setOnClickListener(new OnClickListener() {
1437 @Override
1438 public void onClick(View view) {
1439 if (!mWorkspace.isSwitchingState()) {
1440 onClickAddWidgetButton(view);
1441 }
1442 }
1443 });
1444 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1445 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1446
1447 // Bind settings actions
1448 View settingsButton = findViewById(R.id.settings_button);
1449 boolean hasSettings = hasSettings();
1450 if (hasSettings) {
1451 settingsButton.setOnClickListener(new OnClickListener() {
1452 @Override
1453 public void onClick(View view) {
1454 if (!mWorkspace.isSwitchingState()) {
1455 onClickSettingsButton(view);
1456 }
1457 }
1458 });
1459 settingsButton.setOnLongClickListener(performClickOnLongClick);
1460 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1461 } else {
1462 settingsButton.setVisibility(View.GONE);
1463 }
1464
1465 mOverviewPanel.setAlpha(0f);
1466 }
1467
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001469 * Sets the all apps button. This method is called from {@link Hotseat}.
1470 */
1471 public void setAllAppsButton(View allAppsButton) {
1472 mAllAppsButton = allAppsButton;
1473 }
1474
1475 public View getAllAppsButton() {
1476 return mAllAppsButton;
1477 }
1478
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001479 public View getWidgetsButton() {
1480 return mWidgetsButton;
1481 }
1482
Anjali Koppal5ad44842014-03-10 20:34:39 -07001483 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 * Creates a view representing a shortcut.
1485 *
1486 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001487 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001488 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001489 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490 }
1491
1492 /**
1493 * Creates a view representing a shortcut inflated from the specified resource.
1494 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001495 * @param parent The group the shortcut belongs to.
1496 * @param info The data structure describing the shortcut.
1497 *
1498 * @return A View inflated from layoutResId.
1499 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001500 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001501 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001502 parent, false);
1503 favorite.applyFromShortcutInfo(info, mIconCache);
1504 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001506 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 return favorite;
1508 }
1509
1510 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 * Add a shortcut to the workspace.
1512 *
1513 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001515 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001516 int cellY) {
1517 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001518 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001519
Sunny Goyal5c97f512015-05-19 16:03:28 -07001520 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001521 if (info == null) {
1522 return;
1523 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001524 final View view = createShortcut(info);
1525
Sunny Goyal5c97f512015-05-19 16:03:28 -07001526 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001527 // First we check if we already know the exact location where we want to add this item.
1528 if (cellX >= 0 && cellY >= 0) {
1529 cellXY[0] = cellX;
1530 cellXY[1] = cellY;
1531 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001532
1533 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001534 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001535 true, null,null)) {
1536 return;
1537 }
1538 DragObject dragObject = new DragObject();
1539 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001540 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1541 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001542 return;
1543 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001544 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001545 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001546 }
1547
1548 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001549 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550 return;
1551 }
1552
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001553 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554
1555 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001556 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001557 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 }
1559 }
1560
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001562 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001564 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565 */
Adam Cohen091440a2015-03-18 14:16:05 -07001566 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001567 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1568
1569 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001570 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001571 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1572 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001573 }
Romain Guycbb89e42009-06-08 15:52:54 -07001574
Adam Cohen59400422014-03-05 18:07:04 -08001575 if (appWidgetInfo.isCustomWidget) {
1576 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001577 }
1578
Adam Cohen59400422014-03-05 18:07:04 -08001579 LauncherAppWidgetInfo launcherInfo;
1580 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1581 launcherInfo.spanX = info.spanX;
1582 launcherInfo.spanY = info.spanY;
1583 launcherInfo.minSpanX = info.minSpanX;
1584 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001585 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001586
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001588 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589
1590 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001591 if (hostView == null) {
1592 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001593 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1594 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001595 } else {
1596 // The AppWidgetHostView has already been inflated and instantiated
1597 launcherInfo.hostView = hostView;
1598 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001599 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001600 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001602 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 }
Romain Guycbb89e42009-06-08 15:52:54 -07001604
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001605 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1606 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1607 item.hostView.setTag(item);
1608 item.onBindAppWidget(this);
1609
1610 item.hostView.setFocusable(true);
1611 item.hostView.setOnFocusChangeListener(mFocusHandler);
1612
1613 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1614 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1615
1616 if (!item.isCustomWidget()) {
1617 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1618 }
1619 }
1620
Adam Cohended9f8d2010-11-03 13:25:16 -07001621 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1622 @Override
1623 public void onReceive(Context context, Intent intent) {
1624 final String action = intent.getAction();
1625 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1626 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001627 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001628 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001629
Winson Chungc100e8e2011-08-09 16:02:43 -07001630 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001631 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001632 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001633 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001634 if (!showWorkspace(false)) {
1635 // If we are already on the workspace, then manually reset all apps
1636 mAppsView.reset();
1637 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001638 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001639 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1640 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001641 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001642 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1643 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001644 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001645 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1646 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1647 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001648 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001649 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1650 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001651 }
1652 }
1653 };
1654
1655 @Override
1656 public void onAttachedToWindow() {
1657 super.onAttachedToWindow();
1658
1659 // Listen for broadcasts related to user-presence
1660 final IntentFilter filter = new IntentFilter();
1661 filter.addAction(Intent.ACTION_SCREEN_OFF);
1662 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001663 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001664 if (ENABLE_DEBUG_INTENTS) {
1665 filter.addAction(DebugIntents.DELETE_DATABASE);
1666 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1667 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001668 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001669 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001670 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001671 mVisible = true;
1672 }
1673
1674 @Override
1675 public void onDetachedFromWindow() {
1676 super.onDetachedFromWindow();
1677 mVisible = false;
1678
Adam Cohend113e0c2010-11-11 10:48:05 -08001679 if (mAttached) {
1680 unregisterReceiver(mReceiver);
1681 mAttached = false;
1682 }
Winson Chungb745afb2015-03-02 11:51:23 -08001683 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001684 }
1685
1686 public void onWindowVisibilityChanged(int visibility) {
1687 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001688 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001689 // The following code used to be in onResume, but it turns out onResume is called when
1690 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1691 // is a more appropriate event to handle
1692 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001693 if (!mWorkspaceLoading) {
1694 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001695 // We want to let Launcher draw itself at least once before we force it to build
1696 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001697 // apps is nice and speedy.
1698 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001699 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001700 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001701 if (mStarted) return;
1702 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001703 // We delay the layer building a bit in order to give
1704 // other message processing a time to run. In particular
1705 // this avoids a delay in hiding the IME if it was
1706 // currently shown, because doing that may involve
1707 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001708 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001709 final ViewTreeObserver.OnDrawListener listener = this;
1710 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001711 public void run() {
1712 if (mWorkspace != null &&
1713 mWorkspace.getViewTreeObserver() != null) {
1714 mWorkspace.getViewTreeObserver().
1715 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001716 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001717 }
1718 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001719 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001720 }
1721 });
1722 }
1723 clearTypedText();
1724 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001725 }
1726
Adam Cohen091440a2015-03-18 14:16:05 -07001727 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 mHandler.removeMessages(ADVANCE_MSG);
1729 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1730 mHandler.sendMessageDelayed(msg, delay);
1731 mAutoAdvanceSentTime = System.currentTimeMillis();
1732 }
1733
Adam Cohen091440a2015-03-18 14:16:05 -07001734 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001735 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1736 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1737 mAutoAdvanceRunning = autoAdvanceRunning;
1738 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001739 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001740 sendAdvanceMessage(delay);
1741 } else {
1742 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001743 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1745 }
1746 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001747 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001748 }
1749 }
1750 }
1751
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001752 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1753
Adam Cohended9f8d2010-11-03 13:25:16 -07001754 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001755 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001756 if (msg.what == ADVANCE_MSG) {
1757 int i = 0;
1758 for (View key: mWidgetsToAdvance.keySet()) {
1759 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001760 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001762 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 public void run() {
1764 ((Advanceable) v).advance();
1765 }
1766 }, delay);
1767 }
1768 i++;
1769 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001770 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001771 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001772 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001773 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001774 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001775
Winsonc0b52fe2015-09-09 16:38:15 -07001776 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001777 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001778 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1779 if (v instanceof Advanceable) {
1780 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001781 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001782 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001783 }
1784 }
1785
Winsonc0b52fe2015-09-09 16:38:15 -07001786 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001787 if (mWidgetsToAdvance.containsKey(hostView)) {
1788 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001789 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001790 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001791 }
1792
Hyunyoung Song3f471442015-04-08 19:01:34 -07001793 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001794 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1795 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001796 }
1797
Winson Chunga6945242014-01-08 14:04:34 -08001798 public DragLayer getDragLayer() {
1799 return mDragLayer;
1800 }
1801
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001802 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001803 return mAppsView;
1804 }
1805
Hyunyoung Song3f471442015-04-08 19:01:34 -07001806 public WidgetsContainerView getWidgetsView() {
1807 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001808 }
1809
Winson Chunga6945242014-01-08 14:04:34 -08001810 public Workspace getWorkspace() {
1811 return mWorkspace;
1812 }
1813
1814 public Hotseat getHotseat() {
1815 return mHotseat;
1816 }
1817
Jorim Jaggid017f882014-01-14 17:08:48 -08001818 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001819 return mOverviewPanel;
1820 }
1821
Winson Chung006ee262015-08-03 14:40:11 -07001822 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001823 return mSearchDropTargetBar;
1824 }
1825
Tony Wickham34d2c912015-09-11 09:27:58 -07001826 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1827 return mAppInfoDropTargetBar;
1828 }
1829
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001830 public LauncherAppWidgetHost getAppWidgetHost() {
1831 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 }
Romain Guycbb89e42009-06-08 15:52:54 -07001833
Winson Chunga9abd0e2010-10-27 17:18:37 -07001834 public LauncherModel getModel() {
1835 return mModel;
1836 }
1837
Winson Chunga6945242014-01-08 14:04:34 -08001838 protected SharedPreferences getSharedPrefs() {
1839 return mSharedPrefs;
1840 }
1841
Adam Cohen2e6da152015-05-06 11:42:25 -07001842 public DeviceProfile getDeviceProfile() {
1843 return mDeviceProfile;
1844 }
1845
Bjorn Bringertc459e522013-06-07 19:36:01 +01001846 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001847 getWindow().closeAllPanels();
1848
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001849 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001850 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001851 }
1852
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001853 @Override
1854 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001855 long startTime = 0;
1856 if (DEBUG_RESUME_TIME) {
1857 startTime = System.currentTimeMillis();
1858 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001859 super.onNewIntent(intent);
1860
1861 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001862 Folder openFolder = mWorkspace.getOpenFolder();
1863 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1864 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1865 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1866 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1867 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001868 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001869 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001870
Adam Cohen6fecd412013-10-02 17:41:50 -07001871 if (mWorkspace == null) {
1872 // Can be cases where mWorkspace is null, this prevents a NPE
1873 return;
1874 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001875 // In all these cases, only animate if we're already on home
1876 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001877
Sunny Goyal935fca12015-10-13 10:19:01 -07001878 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001879 exitSpringLoadedDragMode();
1880
1881 // If we are already on home, then just animate back to the workspace,
1882 // otherwise, just wait until onResume to set the state back to Workspace
1883 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001884 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001885 } else {
1886 mOnResumeState = State.WORKSPACE;
1887 }
1888
1889 final View v = getWindow().peekDecorView();
1890 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001891 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001892 INPUT_METHOD_SERVICE);
1893 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1894 }
1895
Winson Chungb745afb2015-03-02 11:51:23 -08001896 // Reset the apps view
1897 if (!alreadyOnHome && mAppsView != null) {
1898 mAppsView.scrollToTop();
1899 }
1900
Hyunyoung Song3f471442015-04-08 19:01:34 -07001901 // Reset the widgets view
1902 if (!alreadyOnHome && mWidgetsView != null) {
1903 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001904 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001905
Adam Cohen9211d422014-10-07 18:14:53 -07001906 if (mLauncherCallbacks != null) {
1907 mLauncherCallbacks.onHomeIntent();
1908 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 }
Adam Cohened307df2013-10-02 09:37:31 -07001910
Adam Cohen9211d422014-10-07 18:14:53 -07001911 if (mLauncherCallbacks != null) {
1912 mLauncherCallbacks.onNewIntent(intent);
1913 }
Winson15f8b172015-08-19 11:02:39 -07001914
1915 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1916 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1917 // animation.
1918 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001919 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1920 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001921 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1922 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001923
1924 // We use this flag to suppress noisy callbacks above custom content state
1925 // from onResume.
1926 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001927 mWorkspace.post(new Runnable() {
1928 @Override
1929 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001930 if (mWorkspace != null) {
1931 mWorkspace.moveToDefaultScreen(true);
1932 }
Winson15f8b172015-08-19 11:02:39 -07001933 }
1934 });
1935 }
1936 }
1937
1938 if (DEBUG_RESUME_TIME) {
1939 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1940 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001941 }
1942
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001944 public void onRestoreInstanceState(Bundle state) {
1945 super.onRestoreInstanceState(state);
1946 for (int page: mSynchronouslyBoundPages) {
1947 mWorkspace.restoreInstanceStateForChild(page);
1948 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 }
1950
1951 @Override
1952 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001953 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001954 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1955 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001956 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001957 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958
Michael Jurka883f55b2010-10-21 15:47:14 -07001959 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal08442b82015-10-21 17:15:08 -07001960 Folder openFolder = mWorkspace.getOpenFolder();
1961 if (openFolder != null) {
1962 outState.putLong(RUNTIME_STATE_OPEN_FOLDER_ID, openFolder.mInfo.id);
1963 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964
Adam Cohendcd297f2013-06-18 13:13:40 -07001965 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001967 ContentValues itemValues = new ContentValues();
1968 mPendingAddInfo.writeToValues(itemValues);
1969 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001970 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001971 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 }
1973
Hyunyoung Song3f471442015-04-08 19:01:34 -07001974 // Save the current widgets tray?
1975 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001976
1977 if (mLauncherCallbacks != null) {
1978 mLauncherCallbacks.onSaveInstanceState(outState);
1979 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 }
1981
1982 @Override
1983 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001984 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001985
Winson Chunge7a03942011-08-05 15:05:12 -07001986 // Remove all pending runnables
1987 mHandler.removeMessages(ADVANCE_MSG);
1988 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001989 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001990
Winson Chungcd2b0142011-06-08 16:02:26 -07001991 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001992 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07001993
1994 // It's possible to receive onDestroy after a new Launcher activity has
1995 // been created. In this case, don't interfere with the new Launcher.
1996 if (mModel.isCurrentCallbacks(this)) {
1997 mModel.stopLoader();
1998 app.setLauncher(null);
1999 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002002 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002004 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002006 mAppWidgetHost = null;
2007
2008 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009
2010 TextKeyListener.getInstance().release();
2011
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002012 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002013
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002014 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002015 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002016 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002017 mWorkspace = null;
2018 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002019
Michael Jurka2ecf9952012-06-18 12:52:28 -07002020 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002021
2022 if (mLauncherCallbacks != null) {
2023 mLauncherCallbacks.onDestroy();
2024 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 }
2026
Adam Cohena9cf38f2011-05-02 15:36:58 -07002027 public DragController getDragController() {
2028 return mDragController;
2029 }
2030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 @Override
2032 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002033 onStartForResult(requestCode);
2034 super.startActivityForResult(intent, requestCode);
2035 }
2036
2037 @Override
2038 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2039 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2040 onStartForResult(requestCode);
2041 try {
2042 super.startIntentSenderForResult(intent, requestCode,
2043 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2044 } catch (IntentSender.SendIntentException e) {
2045 throw new ActivityNotFoundException();
2046 }
2047 }
2048
2049 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002050 if (requestCode >= 0) {
2051 setWaitingForResult(true);
2052 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 }
2054
Winson Chung70d72102011-08-12 11:24:35 -07002055 /**
2056 * Indicates that we want global search for this activity by setting the globalSearch
2057 * argument for {@link #startSearch} to true.
2058 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002060 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002062
Karl Rosaen138a0412009-04-23 19:00:21 -07002063 if (initialQuery == null) {
2064 // Use any text typed in the launcher as the initial query
2065 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002066 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 if (appSearchData == null) {
2068 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002069 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 }
Winson Chungadf0c182012-08-23 14:59:07 -07002071 Rect sourceBounds = new Rect();
2072 if (mSearchDropTargetBar != null) {
2073 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2074 }
Romain Guycbb89e42009-06-08 15:52:54 -07002075
Ian Parkinson047036e2014-09-01 15:40:53 +01002076 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002077 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002078 if (clearTextImmediately) {
2079 clearTypedText();
2080 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002081
2082 // We need to show the workspace after starting the search
2083 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002084 }
2085
Ian Parkinson047036e2014-09-01 15:40:53 +01002086 /**
2087 * Start a text search.
2088 *
2089 * @return {@code true} if the search will start immediately, so any further keypresses
2090 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2091 * to buffer keypresses.
2092 */
2093 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002094 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002095 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2096 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2097 sourceBounds);
2098 }
2099
Michael Jurkaa33411c2012-06-14 16:18:21 -07002100 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002101 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002102 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002103 }
2104
2105 /**
2106 * Starts the global search activity. This code is a copied from SearchManager
2107 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002108 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002109 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002110 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002111 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2112 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2113 if (globalSearchActivity == null) {
2114 Log.w(TAG, "No global search activity found.");
2115 return;
2116 }
2117 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2118 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2119 intent.setComponent(globalSearchActivity);
2120 // Make sure that we have a Bundle to put source in
2121 if (appSearchData == null) {
2122 appSearchData = new Bundle();
2123 } else {
2124 appSearchData = new Bundle(appSearchData);
2125 }
Adam Cohen9211d422014-10-07 18:14:53 -07002126 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002127 if (!appSearchData.containsKey("source")) {
2128 appSearchData.putString("source", getPackageName());
2129 }
2130 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2131 if (!TextUtils.isEmpty(initialQuery)) {
2132 intent.putExtra(SearchManager.QUERY, initialQuery);
2133 }
2134 if (selectInitialQuery) {
2135 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2136 }
2137 intent.setSourceBounds(sourceBounds);
2138 try {
2139 startActivity(intent);
2140 } catch (ActivityNotFoundException ex) {
2141 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 }
2144
Winson Chungbedf9232015-07-10 12:38:30 -07002145 public void startSearchFromAllApps(View v, Intent searchIntent, String searchQuery) {
2146 if (mLauncherCallbacks != null && mLauncherCallbacks.startSearchFromAllApps(searchQuery)) {
2147 return;
2148 }
2149
2150 // If not handled, then just start the provided search intent
2151 startActivitySafely(v, searchIntent, null);
2152 }
2153
Yura4f93ec62014-02-04 14:15:21 +00002154 public boolean isOnCustomContent() {
2155 return mWorkspace.isOnOrMovingToCustomContent();
2156 }
2157
Winson Chung70d72102011-08-12 11:24:35 -07002158 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002159 public boolean onPrepareOptionsMenu(Menu menu) {
2160 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002161 if (mLauncherCallbacks != null) {
2162 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2163 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002164 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002165 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002167 @Override
2168 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002169 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002170 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002171 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002172 }
2173
Joe Onorato9c1289c2009-08-17 11:03:03 -04002174 public boolean isWorkspaceLocked() {
2175 return mWorkspaceLoading || mWaitingForResult;
2176 }
2177
Adam Cohen517a7f52014-03-01 12:12:59 -08002178 public boolean isWorkspaceLoading() {
2179 return mWorkspaceLoading;
2180 }
2181
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002182 private void setWorkspaceLoading(boolean value) {
2183 boolean isLocked = isWorkspaceLocked();
2184 mWorkspaceLoading = value;
2185 if (isLocked != isWorkspaceLocked()) {
2186 onWorkspaceLockedChanged();
2187 }
2188 }
2189
2190 private void setWaitingForResult(boolean value) {
2191 boolean isLocked = isWorkspaceLocked();
2192 mWaitingForResult = value;
2193 if (isLocked != isWorkspaceLocked()) {
2194 onWorkspaceLockedChanged();
2195 }
2196 }
2197
Adam Cohen9211d422014-10-07 18:14:53 -07002198 protected void onWorkspaceLockedChanged() {
2199 if (mLauncherCallbacks != null) {
2200 mLauncherCallbacks.onWorkspaceLockedChanged();
2201 }
2202 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002203
Michael Jurka0280c3b2010-09-17 15:00:07 -07002204 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002205 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002206 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002207 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2208 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002209 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002210 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002211
Tony Wickhama0628cc2015-10-14 15:23:04 -07002212 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002213 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002214 if (LOGD) {
2215 Log.d(TAG, "Adding widget from drop");
2216 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002217 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2218 }
2219
Sunny Goyale6b63a32015-01-16 16:14:29 -08002220 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002221 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2222 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002223 if (appWidgetInfo.configure != null) {
2224 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002225 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002226
Bjorn Bringert7984c942009-12-09 15:38:25 +00002227 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002228 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2229 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2230
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002232 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002233 Runnable onComplete = new Runnable() {
2234 @Override
2235 public void run() {
2236 // Exit spring loaded mode if necessary after adding the widget
2237 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2238 null);
2239 }
2240 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002241 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002242 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002243 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002244 }
2245 }
Romain Guycbb89e42009-06-08 15:52:54 -07002246
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002247 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002248 // Close any folders that may be open.
2249 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002250 mWorkspace.moveToCustomContentScreen(animate);
2251 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002252
2253 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2254 int[] cell, int spanX, int spanY) {
2255 switch (info.itemType) {
2256 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2257 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2258 int span[] = new int[2];
2259 span[0] = spanX;
2260 span[1] = spanY;
2261 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2262 container, screenId, cell, span);
2263 break;
2264 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2265 processShortcutFromDrop(info.componentName, container, screenId, cell);
2266 break;
2267 default:
2268 throw new IllegalStateException("Unknown item type: " + info.itemType);
2269 }
2270 }
2271
Adam Cohenfbba09b2011-07-18 21:43:05 -07002272 /**
2273 * Process a shortcut drop.
2274 *
2275 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002276 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002277 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002278 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002279 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2280 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002281 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002282 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002283 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002284
2285 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002286 mPendingAddInfo.cellX = cell[0];
2287 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002288 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002289
2290 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2291 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002292 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002293 }
2294
Adam Cohenfbba09b2011-07-18 21:43:05 -07002295 /**
2296 * Process a widget drop.
2297 *
2298 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002299 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002300 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002301 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002302 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2303 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002304 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002305 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002306 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002307 mPendingAddInfo.minSpanX = info.minSpanX;
2308 mPendingAddInfo.minSpanY = info.minSpanY;
2309
Adam Cohenfbba09b2011-07-18 21:43:05 -07002310 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002311 mPendingAddInfo.cellX = cell[0];
2312 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002313 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002314 if (span != null) {
2315 mPendingAddInfo.spanX = span[0];
2316 mPendingAddInfo.spanY = span[1];
2317 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002318
Adam Cohened66b2b2012-01-23 17:28:51 -08002319 AppWidgetHostView hostView = info.boundWidget;
2320 int appWidgetId;
2321 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002322 // In the case where we've prebound the widget, we remove it from the DragLayer
2323 if (LOGD) {
2324 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2325 }
2326 getDragLayer().removeView(hostView);
2327
Adam Cohened66b2b2012-01-23 17:28:51 -08002328 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002329 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002330
2331 // Clear the boundWidget so that it doesn't get destroyed.
2332 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002333 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002334 // In this case, we either need to start an activity to get permission to bind
2335 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002336 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002337 Bundle options = info.bindOptions;
2338
Sunny Goyalffe83f12014-08-14 17:39:34 -07002339 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2340 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002341 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002342 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002343 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002344 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002345 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2346 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2347 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002348 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2349 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002350 // TODO: we need to make sure that this accounts for the options bundle.
2351 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002352 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2353 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002354 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002355 }
2356
Adam Cohendcd297f2013-06-18 13:13:40 -07002357 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002358 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002359 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002360 folderInfo.title = getText(R.string.folder_name);
2361
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002363 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2364 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002365 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366
2367 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002368 FolderIcon newFolder =
2369 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002370 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002371 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002372 // Force measure the new folder icon
2373 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2374 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002375 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376 }
Romain Guycbb89e42009-06-08 15:52:54 -07002377
Winsonc0b52fe2015-09-09 16:38:15 -07002378 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002379 * Unbinds the view for the specified item, and removes the item and all its children.
2380 *
2381 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002382 * @param itemInfo the {@link ItemInfo} for this view.
2383 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002384 */
Winson2949fb52015-09-24 09:56:11 -07002385 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002386 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002387 // Remove the shortcut from the folder before removing it from launcher
Winson2949fb52015-09-24 09:56:11 -07002388 FolderInfo folderInfo = sFolders.get(itemInfo.container);
2389 if (folderInfo != null) {
2390 folderInfo.remove((ShortcutInfo) itemInfo);
Winsonfa56b3f2015-09-14 12:01:13 -07002391 } else {
2392 mWorkspace.removeWorkspaceItem(v);
2393 }
Winsonc0b52fe2015-09-09 16:38:15 -07002394 if (deleteFromDb) {
2395 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2396 }
2397 } else if (itemInfo instanceof FolderInfo) {
2398 final FolderInfo folderInfo = (FolderInfo) itemInfo;
2399 unbindFolder(folderInfo);
2400 mWorkspace.removeWorkspaceItem(v);
2401 if (deleteFromDb) {
2402 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2403 }
2404 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2405 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002406 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002407 removeWidgetToAutoAdvance(widgetInfo.hostView);
2408 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002409 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002410 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002411 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002412
Winsonc0b52fe2015-09-09 16:38:15 -07002413 } else {
2414 return false;
2415 }
2416 return true;
2417 }
2418
2419 /**
2420 * Unbinds any launcher references to the folder.
2421 */
2422 private void unbindFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002423 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002424 }
2425
Winsonc0b52fe2015-09-09 16:38:15 -07002426 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002427 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002428 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002429 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002430 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002431 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002432 // Deleting an app widget ID is a void call but writes to disk before returning
2433 // to the caller...
2434 new AsyncTask<Void, Void, Void>() {
2435 public Void doInBackground(Void ... args) {
2436 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2437 return null;
2438 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002439 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002440 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002441 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002442 }
2443
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002444 @Override
2445 public boolean dispatchKeyEvent(KeyEvent event) {
2446 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2447 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002449 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002450 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002451 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002452 dumpState();
2453 return true;
2454 }
2455 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002456 }
2457 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2458 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002459 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002460 return true;
2461 }
2462 }
2463
2464 return super.dispatchKeyEvent(event);
2465 }
2466
Joe Onorato88ec0992009-11-19 13:16:06 -08002467 @Override
2468 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002469 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2470 return;
2471 }
2472
Sunny Goyal45478022015-06-08 16:52:41 -07002473 if (mDragController.isDragging()) {
2474 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002475 return;
2476 }
2477
Winson Chungb745afb2015-03-02 11:51:23 -08002478 if (isAppsViewVisible()) {
2479 showWorkspace(true);
2480 } else if (isWidgetsViewVisible()) {
2481 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002482 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002483 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002484 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002485 Folder openFolder = mWorkspace.getOpenFolder();
2486 if (openFolder.isEditingName()) {
2487 openFolder.dismissEditingName();
2488 } else {
2489 closeFolder();
2490 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002491 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002492 mWorkspace.exitWidgetResizeMode();
2493
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002494 // Back button is a no-op here, but give at least some feedback for the button press
2495 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002496 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002497 }
2498
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002499 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002500 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002501 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002502 @Override
2503 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002504 if (mAppWidgetHost != null) {
2505 mAppWidgetHost.startListening();
2506 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002507
2508 // Recreate the QSB, as the widget has been reset.
2509 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002510 }
2511
2512 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002513 * Launches the intent referred by the clicked shortcut.
2514 *
2515 * @param v The view representing the clicked shortcut.
2516 */
2517 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002518 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2519 // view has detached (it's possible for this to happen if the view is removed mid touch).
2520 if (v.getWindowToken() == null) {
2521 return;
2522 }
2523
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002524 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002525 return;
2526 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002527
Adam Cohen1697b792013-09-17 19:08:21 -07002528 if (v instanceof Workspace) {
2529 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002530 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002531 }
2532 return;
2533 }
2534
2535 if (v instanceof CellLayout) {
2536 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002537 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2538 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002539 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002540 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002541 }
2542
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002543 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002544 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002545 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002546 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002547 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002548 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002549 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002550 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002551 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002552 } else if (tag instanceof AppInfo) {
2553 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002554 } else if (tag instanceof LauncherAppWidgetInfo) {
2555 if (v instanceof PendingAppWidgetHostView) {
2556 onClickPendingWidget((PendingAppWidgetHostView) v);
2557 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002558 }
2559 }
2560
Sunny Goyal70660032015-05-14 00:07:08 -07002561 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002562 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002563 return false;
2564 }
2565
Michael Jurkaaf442092010-06-10 17:01:57 -07002566 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002567 * Event handler for the app widget view which has not fully restored.
2568 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002569 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002570 if (mIsSafeModeEnabled) {
2571 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2572 return;
2573 }
2574
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002575 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002576 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002577 int widgetId = info.appWidgetId;
2578 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2579 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002580 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2581 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002582 mPendingAddInfo.copyFrom(info);
2583 mPendingAddWidgetId = widgetId;
2584
Sunny Goyalffe83f12014-08-14 17:39:34 -07002585 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2586 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002587 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002588 } else if (info.installProgress < 0) {
2589 // The install has not been queued
2590 final String packageName = info.providerName.getPackageName();
2591 showBrokenAppInstallDialog(packageName,
2592 new DialogInterface.OnClickListener() {
2593 public void onClick(DialogInterface dialog, int id) {
2594 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2595 }
2596 });
2597 } else {
2598 // Download has started.
2599 final String packageName = info.providerName.getPackageName();
2600 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002601 }
2602 }
2603
2604 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002605 * Event handler for the "grid" button that appears on the home screen, which
2606 * enters all apps mode.
2607 *
2608 * @param v The view that was clicked.
2609 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002610 protected void onClickAllAppsButton(View v) {
2611 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002612 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002613 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002614 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002615
2616 if (mLauncherCallbacks != null) {
2617 mLauncherCallbacks.onClickAllAppsButton(v);
2618 }
Winson Chung76648c52015-07-10 14:33:23 -07002619 }
2620 }
2621
2622 protected void onLongClickAllAppsButton(View v) {
2623 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2624 if (!isAppsViewVisible()) {
2625 showAppsView(true /* animated */, false /* resetListToTop */,
2626 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002627 }
2628 }
2629
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002630 private void showBrokenAppInstallDialog(final String packageName,
2631 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002632 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002633 .setTitle(R.string.abandoned_promises_title)
2634 .setMessage(R.string.abandoned_promise_explanation)
2635 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2636 .setNeutralButton(R.string.abandoned_clean_this,
2637 new DialogInterface.OnClickListener() {
2638 public void onClick(DialogInterface dialog, int id) {
2639 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2640 mWorkspace.removeAbandonedPromise(packageName, user);
2641 }
2642 })
2643 .create().show();
2644 return;
2645 }
2646
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002647 /**
2648 * Event handler for an app shortcut click.
2649 *
2650 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2651 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002652 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002653 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2654 Object tag = v.getTag();
2655 if (!(tag instanceof ShortcutInfo)) {
2656 throw new IllegalArgumentException("Input must be a Shortcut");
2657 }
2658
2659 // Open shortcut
2660 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002661
2662 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002663 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2664 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002665 // Launch activity anyway, framework will tell the user why the app is suspended.
2666 } else {
2667 int error = R.string.activity_not_available;
2668 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2669 error = R.string.safemode_shortcut_error;
2670 }
2671 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2672 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002673 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002674 }
2675
Chris Wren40c5ed32014-06-24 18:24:23 -04002676 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002677 if ((v instanceof BubbleTextView)
2678 && shortcut.isPromise()
2679 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002680 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002681 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002682 new DialogInterface.OnClickListener() {
2683 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002684 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002685 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002686 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002687 return;
2688 }
2689
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002690 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002691 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002692
2693 if (mLauncherCallbacks != null) {
2694 mLauncherCallbacks.onClickAppShortcut(v);
2695 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002696 }
2697
Adam Cohen091440a2015-03-18 14:16:05 -07002698 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002699 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002700 final ShortcutInfo shortcut;
2701 final Intent intent;
2702 if (tag instanceof ShortcutInfo) {
2703 shortcut = (ShortcutInfo) tag;
2704 intent = shortcut.intent;
2705 int[] pos = new int[2];
2706 v.getLocationOnScreen(pos);
2707 intent.setSourceBounds(new Rect(pos[0], pos[1],
2708 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002709
Sunny Goyal508da152014-08-14 10:53:27 -07002710 } else if (tag instanceof AppInfo) {
2711 shortcut = null;
2712 intent = ((AppInfo) tag).intent;
2713 } else {
2714 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2715 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002716
2717 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002718 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002719
2720 if (success && v instanceof BubbleTextView) {
2721 mWaitingForResume = (BubbleTextView) v;
2722 mWaitingForResume.setStayPressed(true);
2723 }
2724 }
2725
2726 /**
2727 * Event handler for a folder icon click.
2728 *
2729 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2730 */
2731 protected void onClickFolderIcon(View v) {
2732 if (LOGD) Log.d(TAG, "onClickFolder");
2733 if (!(v instanceof FolderIcon)){
2734 throw new IllegalArgumentException("Input must be a FolderIcon");
2735 }
2736
2737 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002738 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002739 // Open the requested folder
Sunny Goyal08442b82015-10-21 17:15:08 -07002740 openFolder(folderIcon, true);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002741 }
Adam Cohen9211d422014-10-07 18:14:53 -07002742
2743 if (mLauncherCallbacks != null) {
2744 mLauncherCallbacks.onClickFolderIcon(v);
2745 }
Michael Jurka5130e402011-10-13 04:55:35 -07002746 }
2747
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002748 /**
2749 * Event handler for the (Add) Widgets button that appears after a long press
2750 * on the home screen.
2751 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002752 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002753 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002754 if (mIsSafeModeEnabled) {
2755 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2756 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002757 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002758 if (mLauncherCallbacks != null) {
2759 mLauncherCallbacks.onClickAddWidgetButton(view);
2760 }
Adam Cohen9211d422014-10-07 18:14:53 -07002761 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002762 }
2763
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002764 /**
2765 * Event handler for the wallpaper picker button that appears after a long press
2766 * on the home screen.
2767 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002768 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002769 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002770 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2771 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
2772 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
Sunny Goyal5abb9f82016-02-09 15:22:42 -08002773 .putExtra(WallpaperUtils.EXTRA_WALLPAPER_OFFSET, offset),
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002774 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002775
2776 if (mLauncherCallbacks != null) {
2777 mLauncherCallbacks.onClickWallpaperPicker(v);
2778 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002779 }
2780
2781 /**
2782 * Event handler for a click on the settings button that appears after a long press
2783 * on the home screen.
2784 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002785 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002786 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002787 if (mLauncherCallbacks != null) {
2788 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002789 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002790 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002791 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002792 }
2793
Adam Cohen61f560d2013-09-30 15:58:20 -07002794 public View.OnTouchListener getHapticFeedbackTouchListener() {
2795 if (mHapticFeedbackTouchListener == null) {
2796 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002797 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002798 @Override
2799 public boolean onTouch(View v, MotionEvent event) {
2800 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2801 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2802 }
2803 return false;
2804 }
2805 };
2806 }
2807 return mHapticFeedbackTouchListener;
2808 }
2809
Adam Cohen9211d422014-10-07 18:14:53 -07002810 public void onDragStarted(View view) {
2811 if (isOnCustomContent()) {
2812 // Custom content screen doesn't participate in drag and drop. If on custom
2813 // content screen, move to default.
2814 moveWorkspaceToDefaultScreen();
2815 }
2816
2817 if (mLauncherCallbacks != null) {
2818 mLauncherCallbacks.onDragStarted(view);
2819 }
2820 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002821
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002822 /**
2823 * Called when the user stops interacting with the launcher.
2824 * This implies that the user is now on the homescreen and is not doing housekeeping.
2825 */
Adam Cohen9211d422014-10-07 18:14:53 -07002826 protected void onInteractionEnd() {
2827 if (mLauncherCallbacks != null) {
2828 mLauncherCallbacks.onInteractionEnd();
2829 }
2830 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002831
2832 /**
2833 * Called when the user starts interacting with the launcher.
2834 * The possible interactions are:
2835 * - open all apps
2836 * - reorder an app shortcut, or a widget
2837 * - open the overview mode.
2838 * This is a good time to stop doing things that only make sense
2839 * when the user is on the homescreen and not doing housekeeping.
2840 */
Adam Cohen9211d422014-10-07 18:14:53 -07002841 protected void onInteractionBegin() {
2842 if (mLauncherCallbacks != null) {
2843 mLauncherCallbacks.onInteractionBegin();
2844 }
2845 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002846
Winson Chungcd99cd32015-04-29 11:03:24 -07002847 /** Updates the interaction state. */
2848 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002849 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002850 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002851 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2852 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002853 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002854 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002855 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002856 onInteractionEnd();
2857 }
2858 }
2859
Kenny Guyf07af7b2014-07-31 11:39:16 +01002860 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002861 try {
2862 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002863 launcherApps.showAppDetailsForProfile(componentName, user);
2864 } catch (SecurityException e) {
2865 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2866 Log.e(TAG, "Launcher does not have permission to launch settings");
2867 } catch (ActivityNotFoundException e) {
2868 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2869 Log.e(TAG, "Unable to launch settings");
2870 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002871 }
2872
Michael Jurka1e2f4652013-07-08 18:03:46 -07002873 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002874 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2875 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002876 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002877 // System applications cannot be installed. For now, show a toast explaining that.
2878 // We may give them the option of disabling apps this way.
2879 int messageId = R.string.uninstall_system_app_text;
2880 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002881 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002882 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002883 String packageName = componentName.getPackageName();
2884 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002885 Intent intent = new Intent(
2886 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002887 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2888 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002889 if (user != null) {
2890 user.addToIntent(intent, Intent.EXTRA_USER);
2891 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002892 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002893 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002894 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002895 }
2896
Winson Chung8f1eff72015-05-28 17:33:40 -07002897 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002898 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002900 // Only launch using the new animation if the shortcut has not opted out (this is a
2901 // private contract between launcher and may be ignored in the future).
2902 boolean useLaunchAnimation = (v != null) &&
2903 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002904 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2905 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002906
Kenny Guy1317e2d2014-05-08 18:52:50 +01002907 UserHandleCompat user = null;
2908 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2909 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2910 user = userManager.getUserForSerialNumber(serialNumber);
2911 }
2912
2913 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002914 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002915 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002916 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002917 int left = 0, top = 0;
2918 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2919 if (v instanceof TextView) {
2920 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002921 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2922 if (icon != null) {
2923 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002924 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002925 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002926 width = bounds.width();
2927 height = bounds.height();
2928 }
2929 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002930 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2931 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002932 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002933 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002934 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002935 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002936 // On L devices, we use the device default slide-up transition.
2937 // On L MR1 devices, we a custom version of the slide-up transition which
2938 // doesn't have the delay present in the device default.
2939 opts = ActivityOptions.makeCustomAnimation(this,
2940 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002941 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002942 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002943 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002944
2945 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2946 // Could be launching some bookkeeping activity
2947 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002948 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002949 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002950 launcherApps.startActivityForProfile(intent.getComponent(), user,
2951 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002952 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002953 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002954 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002955 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2956 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2957 // corresponding permission. Show the appropriate permission prompt if that
2958 // is the case.
2959 if (intent.getComponent() == null
2960 && Intent.ACTION_CALL.equals(intent.getAction())
2961 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2962 PackageManager.PERMISSION_GRANTED) {
2963 // TODO: Rename sPendingAddItem to a generic name.
2964 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2965 0, (ItemInfo) tag);
2966 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2967 REQUEST_PERMISSION_CALL_PHONE);
2968 return false;
2969 }
2970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002971 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002972 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002973 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002974 "or use the exported attribute for this activity. "
2975 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002976 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002977 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002978 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002979
Winson Chungbedf9232015-07-10 12:38:30 -07002980 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002981 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002982 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2983 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2984 return false;
2985 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002986 try {
2987 success = startActivity(v, intent, tag);
2988 } catch (ActivityNotFoundException e) {
2989 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2990 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2991 }
2992 return success;
2993 }
2994
Adam Cohen268c4752012-06-06 17:47:33 -07002995 /**
2996 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2997 * in the DragLayer in the exact absolute location of the original FolderIcon.
2998 */
2999 private void copyFolderIconToImage(FolderIcon fi) {
3000 final int width = fi.getMeasuredWidth();
3001 final int height = fi.getMeasuredHeight();
3002
3003 // Lazy load ImageView, Bitmap and Canvas
3004 if (mFolderIconImageView == null) {
3005 mFolderIconImageView = new ImageView(this);
3006 }
3007 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3008 mFolderIconBitmap.getHeight() != height) {
3009 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3010 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3011 }
3012
3013 DragLayer.LayoutParams lp;
3014 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3015 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3016 } else {
3017 lp = new DragLayer.LayoutParams(width, height);
3018 }
3019
Adam Cohen307fe232012-08-16 17:55:58 -07003020 // The layout from which the folder is being opened may be scaled, adjust the starting
3021 // view size by this scale factor.
3022 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003023 lp.customPosition = true;
3024 lp.x = mRectForFolderAnimation.left;
3025 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003026 lp.width = (int) (scale * width);
3027 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003028
3029 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3030 fi.draw(mFolderIconCanvas);
3031 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003032 if (fi.getFolder() != null) {
3033 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3034 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003035 }
Adam Cohen268c4752012-06-06 17:47:33 -07003036 // Just in case this image view is still in the drag layer from a previous animation,
3037 // we remove it and re-add it.
3038 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3039 mDragLayer.removeView(mFolderIconImageView);
3040 }
3041 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003042 if (fi.getFolder() != null) {
3043 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003044 }
Adam Cohen268c4752012-06-06 17:47:33 -07003045 }
3046
Sunny Goyal08442b82015-10-21 17:15:08 -07003047 private void growAndFadeOutFolderIcon(FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003048 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003049 FolderInfo info = (FolderInfo) fi.getTag();
3050 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3051 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003052 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3053 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003054 }
3055
Adam Cohen268c4752012-06-06 17:47:33 -07003056 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3057 copyFolderIconToImage(fi);
3058 fi.setVisibility(View.INVISIBLE);
3059
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003060 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3061 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003062 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003063 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3064 }
3065 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003066 oa.start();
Sunny Goyal08442b82015-10-21 17:15:08 -07003067 if (!animate) {
Tony Wickham112ac952015-11-12 12:31:50 -08003068 oa.end();
3069 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003070 }
3071
Sunny Goyal935fca12015-10-13 10:19:01 -07003072 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003073 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003074 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003075
Adam Cohen268c4752012-06-06 17:47:33 -07003076 // We remove and re-draw the FolderIcon in-case it has changed
3077 mDragLayer.removeView(mFolderIconImageView);
3078 copyFolderIconToImage(fi);
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003079 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003080 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003081 oa.addListener(new AnimatorListenerAdapter() {
3082 @Override
3083 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003084 if (cl != null) {
3085 cl.clearFolderLeaveBehind();
3086 // Remove the ImageView copy of the FolderIcon and make the original visible.
3087 mDragLayer.removeView(mFolderIconImageView);
3088 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003089 }
3090 }
3091 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003092 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003093 if (!animate) {
3094 oa.end();
3095 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003096 }
3097
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003098 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003099 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003100 * is animated relative to the specified View. If the View is null, no animation
3101 * is played.
3102 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003103 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003104 */
Sunny Goyal08442b82015-10-21 17:15:08 -07003105 public void openFolder(FolderIcon folderIcon, boolean animate) {
3106 animate &= !Utilities.isPowerSaverOn(this);
3107
Adam Cohenfb91f302012-06-11 15:45:18 -07003108 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003109 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3110 if (openFolder != null && openFolder != folder) {
3111 // Close any open folder before opening a folder.
3112 closeFolder();
3113 }
3114
Adam Cohena9cf38f2011-05-02 15:36:58 -07003115 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003116
Adam Cohena9cf38f2011-05-02 15:36:58 -07003117 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003118
Sunny Goyalf4066152015-04-15 09:42:19 -07003119 // While the folder is open, the position of the icon cannot change.
3120 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3121
Adam Cohen4554ee12011-08-03 16:13:21 -07003122 // Just verify that the folder hasn't already been added to the DragLayer.
3123 // There was a one-off crash where the folder had a parent already.
3124 if (folder.getParent() == null) {
3125 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003126 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003127 } else {
3128 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3129 folder.getParent() + ").");
3130 }
Sunny Goyal08442b82015-10-21 17:15:08 -07003131 if (animate) {
3132 folder.animateOpen();
3133 } else {
3134 folder.open();
3135 }
3136 growAndFadeOutFolderIcon(folderIcon, animate);
Winson Chung83ca4802013-04-12 15:10:52 -07003137
3138 // Notify the accessibility manager that this folder "window" has appeared and occluded
3139 // the workspace items
3140 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3141 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003142 }
3143
3144 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003145 closeFolder(true);
3146 }
3147
3148 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003149 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003150 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003151 if (folder.isEditingName()) {
3152 folder.dismissEditingName();
3153 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003154 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003155 }
3156 }
3157
Sunny Goyal935fca12015-10-13 10:19:01 -07003158 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003159 animate &= !Utilities.isPowerSaverOn(this);
3160
Adam Cohen4554ee12011-08-03 16:13:21 -07003161 folder.getInfo().opened = false;
3162
3163 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3164 if (parent != null) {
3165 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003166 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003167 if (fi != null) {
3168 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3169 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003170 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003171 if (animate) {
3172 folder.animateClosed();
3173 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003174 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003175 }
Winson Chung83ca4802013-04-12 15:10:52 -07003176
Sunny Goyal935fca12015-10-13 10:19:01 -07003177 // Notify the accessibility manager that this folder "window" has disappeared and no
3178 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003179 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003180 }
3181
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003182 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003183 if (!isDraggingEnabled()) return false;
3184 if (isWorkspaceLocked()) return false;
3185 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003186
Winson Chung76648c52015-07-10 14:33:23 -07003187 if (v == mAllAppsButton) {
3188 onLongClickAllAppsButton(v);
3189 return true;
3190 }
3191
Adam Cohen1697b792013-09-17 19:08:21 -07003192 if (v instanceof Workspace) {
3193 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003194 if (!mWorkspace.isTouchActive()) {
3195 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003196 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3197 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3198 return true;
3199 } else {
3200 return false;
3201 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003202 } else {
3203 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003204 }
Adam Cohen1697b792013-09-17 19:08:21 -07003205 }
3206
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003207 CellLayout.CellInfo longClickCellInfo = null;
3208 View itemUnderLongClick = null;
3209 if (v.getTag() instanceof ItemInfo) {
3210 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003211 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003212 itemUnderLongClick = longClickCellInfo.cell;
3213 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003214 }
3215
Winson Chung3d503fb2011-07-13 17:25:49 -07003216 // The hotseat touch handling does not go through Workspace, and we always allow long press
3217 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003218 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003219 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003220 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003221 // User long pressed on empty space
3222 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3223 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003224 if (mWorkspace.isInOverviewMode()) {
3225 mWorkspace.startReordering(v);
3226 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003227 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003229 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003230 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3231 mHotseat.getOrderInHotseat(
3232 longClickCellInfo.cellX,
3233 longClickCellInfo.cellY));
3234 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003235 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003236 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003237 }
3238 }
3239 }
3240 return true;
3241 }
3242
Winson Chung3d503fb2011-07-13 17:25:49 -07003243 boolean isHotseatLayout(View layout) {
3244 return mHotseat != null && layout != null &&
3245 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3246 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003247
Winson Chung3d503fb2011-07-13 17:25:49 -07003248 /**
3249 * Returns the CellLayout of the specified container at the specified screen.
3250 */
Sunny Goyal92820592015-03-02 11:31:35 -08003251 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003252 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3253 if (mHotseat != null) {
3254 return mHotseat.getLayout();
3255 } else {
3256 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003257 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003258 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003259 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003260 }
3261 }
3262
Winson Chungb745afb2015-03-02 11:51:23 -08003263 /**
3264 * For overridden classes.
3265 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003266 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003267 return isAppsViewVisible();
3268 }
3269
3270 public boolean isAppsViewVisible() {
3271 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3272 }
3273
3274 public boolean isWidgetsViewVisible() {
3275 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003276 }
3277
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003278 private void setWorkspaceBackground(int background) {
3279 switch (background) {
3280 case WORKSPACE_BACKGROUND_TRANSPARENT:
3281 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3282 break;
3283 case WORKSPACE_BACKGROUND_BLACK:
3284 getWindow().setBackgroundDrawable(null);
3285 break;
3286 default:
3287 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3288 }
Craig Mautner360310b2012-10-26 15:13:08 -07003289 }
3290
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003291 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003292 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3293 int curflags = getWindow().getAttributes().flags
3294 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3295 if (wpflags != curflags) {
3296 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3297 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003298 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003299 }
3300
Michael Jurkae326f182011-11-21 14:05:46 -08003301 @Override
3302 public void onTrimMemory(int level) {
3303 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003304 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3305 // The widget preview db can result in holding onto over
3306 // 3MB of memory for caching which isn't necessary.
3307 SQLiteDatabase.releaseMemory();
3308
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003309 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003310 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003311 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003312 if (mLauncherCallbacks != null) {
3313 mLauncherCallbacks.onTrimMemory(level);
3314 }
Michael Jurkae326f182011-11-21 14:05:46 -08003315 }
3316
Winson5c6bdbb2015-09-03 11:36:19 -07003317 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003318 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003319 }
3320
Winson5c6bdbb2015-09-03 11:36:19 -07003321 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003322 boolean changed = mState != State.WORKSPACE ||
3323 mWorkspace.getState() != Workspace.State.NORMAL;
3324 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003325 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003326 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003327 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003328
Michael Jurkab3e22d92011-10-31 15:58:33 -07003329 // Set focus to the AppsCustomize button
3330 if (mAllAppsButton != null) {
3331 mAllAppsButton.requestFocus();
3332 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003333 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003334
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003335 // Change the state *after* we've called all the transition code
3336 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003337
Winson Chung5fb63472011-02-02 17:03:37 -08003338 // Resume the auto-advance of widgets
3339 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003340 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003341
Winson Chung0f785722015-04-08 10:27:49 -07003342 if (changed) {
3343 // Send an accessibility event to announce the context change
3344 getWindow().getDecorView()
3345 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003346 }
Winson5c6bdbb2015-09-03 11:36:19 -07003347 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003348 }
3349
Winsone9f27272015-10-13 10:47:51 -07003350 /**
3351 * Shows the overview button.
3352 */
Adam Cohened307df2013-10-02 09:37:31 -07003353 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003354 showOverviewMode(animated, false);
3355 }
3356
3357 /**
3358 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3359 * onto one of the overview panel buttons.
3360 */
3361 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3362 Runnable postAnimRunnable = null;
3363 if (requestButtonFocus) {
3364 postAnimRunnable = new Runnable() {
3365 @Override
3366 public void run() {
3367 // Hitting the menu button when in touch mode does not trigger touch mode to
3368 // be disabled, so if requested, force focus on one of the overview panel
3369 // buttons.
3370 mOverviewPanel.requestFocusFromTouch();
3371 }
3372 };
3373 }
Adam Cohened307df2013-10-02 09:37:31 -07003374 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003375 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003376 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003377 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003378 }
3379
Winson Chungb745afb2015-03-02 11:51:23 -08003380 /**
3381 * Shows the apps view.
3382 */
Winson Chung76648c52015-07-10 14:33:23 -07003383 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3384 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003385 if (resetListToTop) {
3386 mAppsView.scrollToTop();
3387 }
Winson Chung4ac30062015-05-08 17:34:17 -07003388 if (updatePredictedApps) {
3389 tryAndUpdatePredictedApps();
3390 }
Winson Chung76648c52015-07-10 14:33:23 -07003391 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003392 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003393
Winson Chungb745afb2015-03-02 11:51:23 -08003394 /**
3395 * Shows the widgets view.
3396 */
3397 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003398 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003399 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003400 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003401 }
Winson Chung76648c52015-07-10 14:33:23 -07003402 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003403
3404 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003405 @Override
3406 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003407 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003408 }
3409 });
Winson Chungb745afb2015-03-02 11:51:23 -08003410 }
3411
3412 /**
3413 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003414 *
3415 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003416 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003417 // TODO: calling method should use the return value so that when {@code false} is returned
3418 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003419 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003420 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3421 mState != State.WIDGETS_SPRING_LOADED) {
3422 return false;
3423 }
3424 if (toState != State.APPS && toState != State.WIDGETS) {
3425 return false;
3426 }
Winson Chungb745afb2015-03-02 11:51:23 -08003427
3428 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003429 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3430 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003431 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003432 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003433 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003434
Michael Jurkab3e22d92011-10-31 15:58:33 -07003435 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003436 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003437
3438 // Pause the auto-advance of widgets until we are out of AllApps
3439 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003440 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003441 closeFolder();
3442
3443 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003444 getWindow().getDecorView()
3445 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003446 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003447 }
3448
Winson Chungcd99cd32015-04-29 11:03:24 -07003449 /**
3450 * Updates the workspace and interaction state on state change, and return the animation to this
3451 * new state.
3452 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003453 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003454 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003455 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003456 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003457 updateInteraction(fromState, toState);
3458 return anim;
3459 }
3460
Jun Mukaif0033da2015-08-04 18:34:30 -07003461 public void onLauncherClingShown() {
3462 // When a launcher cling appears, it should cover the underlying layers, so their focus
3463 // should be blocked.
3464 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3465 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3466 }
3467 }
3468
3469 public void onLauncherClingDismissed() {
3470 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3471 }
3472
Hyunyoung Song3f471442015-04-08 19:01:34 -07003473 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003474 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003475 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003476 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003477 }
Winson Chungb745afb2015-03-02 11:51:23 -08003478
Winson Chung006ee262015-08-03 14:40:11 -07003479 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003480 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003481 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003482
3483 if (isAppsViewVisible()) {
3484 mState = State.APPS_SPRING_LOADED;
3485 } else if (isWidgetsViewVisible()) {
3486 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003487 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003488 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003489 } else {
3490 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003491 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003492 }
Adam Cohen7777d962011-08-18 18:58:38 -07003493
Hyunyoung Song3f471442015-04-08 19:01:34 -07003494 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003495 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003496 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003497
Winson Chunge7a03942011-08-05 15:05:12 -07003498 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003499 @Override
3500 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003501 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003502 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3503 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003504 // Before we show workspace, hide all apps again because
3505 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3506 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003507 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003508 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003509 } else {
3510 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003511 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003512 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003513 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003514 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003515
Tony Wickhame0c33232016-02-08 11:37:04 -08003516 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003517 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3518 || mState == State.WIDGETS_SPRING_LOADED;
3519 }
3520
Michael Jurkad3ef3062010-11-23 16:23:58 -08003521 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003522 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003523 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003524 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003525 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003526 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003527 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3528 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003529 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003530 }
3531
Winson Chung4ac30062015-05-08 17:34:17 -07003532 /**
3533 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3534 * resumed.
3535 */
3536 private void tryAndUpdatePredictedApps() {
3537 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003538 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003539 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003540 mAppsView.setPredictedApps(apps);
3541 }
3542 }
3543 }
3544
Michael Jurkab3e22d92011-10-31 15:58:33 -07003545 void lockAllApps() {
3546 // TODO
3547 }
3548
3549 void unlockAllApps() {
3550 // TODO
3551 }
3552
Sunny Goyal594d76d2014-11-06 10:12:54 -08003553 protected void disableVoiceButtonProxy(boolean disable) {
3554 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003555 }
3556
Winsonf768d932015-09-25 16:12:35 -07003557 public boolean launcherCallbacksProvidesSearch() {
3558 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3559 }
3560
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003561 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003562 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003563 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003564 }
3565
Adam Cohen24ce0b32014-01-14 16:18:14 -08003566 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003567 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3568 if (searchProvider == null) {
3569 return null;
3570 }
3571
3572 Bundle opts = new Bundle();
3573 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003574 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003575
Tony Wickham3a3517f2015-10-06 11:27:04 -07003576 // Determine the min and max dimensions of the widget.
3577 LauncherAppState app = LauncherAppState.getInstance();
3578 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3579 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3580 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003581 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3582 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003583 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003584 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003585 int minWidth = maxWidth;
3586 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003587 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3588 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3589 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3590 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3591 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003592 }
3593 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3594 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3595 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3596 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003597 if (LOGD) {
3598 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3599 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3600 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003601
Tony Wickham775455c2015-10-16 09:49:32 -07003602 if (mLauncherCallbacks != null) {
3603 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3604 }
3605
Sunny Goyalf7258242015-10-19 16:59:07 -07003606 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003607 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003608 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003609 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003610 || (widgetInfo == null)
3611 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003612 // A valid widget is not already bound.
3613 if (widgetId > -1) {
3614 mAppWidgetHost.deleteAppWidgetId(widgetId);
3615 widgetId = -1;
3616 }
3617
3618 // Try to bind a new widget
3619 widgetId = mAppWidgetHost.allocateAppWidgetId();
3620
3621 if (!AppWidgetManagerCompat.getInstance(this)
3622 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3623 mAppWidgetHost.deleteAppWidgetId(widgetId);
3624 widgetId = -1;
3625 }
3626
Sunny Goyalf7258242015-10-19 16:59:07 -07003627 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003628 .putInt(QSB_WIDGET_ID, widgetId)
3629 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003630 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003631 }
3632
Sunny Goyal8d595092015-07-06 12:22:14 -07003633 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003634 if (widgetId != -1) {
3635 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003636 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003637 mQsb.updateAppWidgetOptions(opts);
3638 mQsb.setPadding(0, 0, 0, 0);
3639 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003640 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003641 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003642 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003643 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003644 }
3645
Sunny Goyal22235bc2015-04-03 09:23:43 -07003646 private void reinflateQSBIfNecessary() {
3647 if (mQsb instanceof LauncherAppWidgetHostView &&
3648 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3649 mSearchDropTargetBar.removeView(mQsb);
3650 mQsb = null;
3651 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3652 }
3653 }
3654
Michael Jurkad7c28052012-04-27 15:43:36 -07003655 @Override
3656 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003657 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003658 final List<CharSequence> text = event.getText();
3659 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003660 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003661 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003662 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003663 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003664 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003665 } else if (mWorkspace != null) {
3666 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003667 } else {
3668 text.add(getString(R.string.all_apps_home_button_label));
3669 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003670 return result;
3671 }
3672
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003673 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003674 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003675 */
Adam Cohen091440a2015-03-18 14:16:05 -07003676 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003677 @Override
3678 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003679 closeSystemDialogs();
3680 }
3681 }
3682
3683 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003684 * If the activity is currently paused, signal that we need to run the passed Runnable
3685 * in onResume.
3686 *
3687 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003688 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3689 * wrong when we're not running, and if the activity comes back to what the configuration was
3690 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003691 *
3692 * Implementation of the method from LauncherModel.Callbacks.
3693 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003694 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003695 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003696 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003697 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003698 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003699 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003700 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003701 }
3702 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003703 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003704 return true;
3705 } else {
3706 return false;
3707 }
3708 }
3709
Michael Jurkac402cd92013-05-20 15:49:32 +02003710 private boolean waitUntilResume(Runnable run) {
3711 return waitUntilResume(run, false);
3712 }
3713
Michael Jurka1e2f4652013-07-08 18:03:46 -07003714 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003715 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003716 }
3717
Michael Jurka7607c2f2013-04-03 14:33:19 -07003718 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003719 * If the activity is currently paused, signal that we need to re-run the loader
3720 * in onResume.
3721 *
3722 * This needs to be called from incoming places where resources might have been loaded
3723 * while we are paused. That is becaues the Configuration might be wrong
3724 * when we're not running, and if it comes back to what it was when we
3725 * were paused, we are not restarted.
3726 *
3727 * Implementation of the method from LauncherModel.Callbacks.
3728 *
3729 * @return true if we are currently paused. The caller might be able to
3730 * skip some work in that case since we will come back again.
3731 */
3732 public boolean setLoadOnResume() {
3733 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003734 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003735 mOnResumeNeedsLoad = true;
3736 return true;
3737 } else {
3738 return false;
3739 }
3740 }
3741
3742 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003743 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003744 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003745 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003746 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003747 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003748 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003749 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003750 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003751 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003752
Joe Onorato9c1289c2009-08-17 11:03:03 -04003753 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003754 * Clear any pending bind callbacks. This is called when is loader is planning to
3755 * perform a full rebind from scratch.
3756 */
3757 @Override
3758 public void clearPendingBinds() {
3759 mBindOnResumeCallbacks.clear();
3760 if (mPendingExecutor != null) {
3761 mPendingExecutor.markCompleted();
3762 mPendingExecutor = null;
3763 }
3764 }
3765
3766 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003767 * Refreshes the shortcuts shown on the workspace.
3768 *
3769 * Implementation of the method from LauncherModel.Callbacks.
3770 */
3771 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003772 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003773
Winson Chungd64d1762013-08-20 14:37:16 -07003774 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003775 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003776 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003777
Michael Jurka05bf644e2011-11-30 20:28:53 -08003778 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003779 if (mHotseat != null) {
3780 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003781 }
3782 }
3783
Adam Cohendcd297f2013-06-18 13:13:40 -07003784 @Override
3785 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003786 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003787
Adam Cohen5084cba2013-09-03 12:01:16 -07003788 // If there are no screens, we need to have an empty screen
3789 if (orderedScreenIds.size() == 0) {
3790 mWorkspace.addExtraEmptyScreen();
3791 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003792
3793 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003794 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003795 if (hasCustomContentToLeft()) {
3796 mWorkspace.createCustomContentContainer();
3797 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003798 }
Winson Chung64359a52013-07-08 17:17:08 -07003799 }
3800
3801 @Override
3802 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003803 int count = orderedScreenIds.size();
3804 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003805 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003806 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003807 }
3808
Winson Chungd64d1762013-08-20 14:37:16 -07003809 public void bindAppsAdded(final ArrayList<Long> newScreens,
3810 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003811 final ArrayList<ItemInfo> addAnimated,
3812 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003813 Runnable r = new Runnable() {
3814 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003815 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003816 }
3817 };
3818 if (waitUntilResume(r)) {
3819 return;
3820 }
3821
Winson Chungd64d1762013-08-20 14:37:16 -07003822 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003823 if (newScreens != null) {
3824 bindAddScreens(newScreens);
3825 }
Winson Chungd64d1762013-08-20 14:37:16 -07003826
3827 // We add the items without animation on non-visible pages, and with
3828 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003829 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003830 bindItems(addNotAnimated, 0,
3831 addNotAnimated.size(), false);
3832 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003833 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003834 bindItems(addAnimated, 0,
3835 addAnimated.size(), true);
3836 }
Winson Chungc58497e2013-09-03 17:48:37 -07003837
Winson Chung87412982013-10-03 18:34:14 -07003838 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003839 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003840
Winson Chungb745afb2015-03-02 11:51:23 -08003841 if (addedApps != null && mAppsView != null) {
3842 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003843 }
Winson Chungd64d1762013-08-20 14:37:16 -07003844 }
3845
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003846 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003847 * Bind the items start-end from the list.
3848 *
3849 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003850 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003851 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003852 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3853 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003854 Runnable r = new Runnable() {
3855 public void run() {
3856 bindItems(shortcuts, start, end, forceAnimateIcons);
3857 }
3858 };
3859 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003860 return;
3861 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003862
Winson Chungf0c6ae02012-03-21 16:10:31 -07003863 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003864 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3865 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003866 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003867 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003868 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003869 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003870 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003871
3872 // Short circuit if we are loading dock items for a configuration which has no dock
3873 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3874 mHotseat == null) {
3875 continue;
3876 }
3877
Sunny Goyal639e9062015-08-19 19:17:06 -07003878 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003879 switch (item.itemType) {
3880 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3881 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003882 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003883 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003884
Winson Chung64359a52013-07-08 17:17:08 -07003885 /*
3886 * TODO: FIX collision case
3887 */
Winson Chungce376632013-07-11 16:12:41 -07003888 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3889 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3890 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003891 View v = cl.getChildAt(item.cellX, item.cellY);
3892 Object tag = v.getTag();
3893 String desc = "Collision while binding workspace item: " + item
3894 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003895 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003896 throw (new RuntimeException(desc));
3897 } else {
3898 Log.d(TAG, desc);
3899 }
Winson Chungce376632013-07-11 16:12:41 -07003900 }
Winson Chung64359a52013-07-08 17:17:08 -07003901 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003902 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003903 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003904 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003905 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003906 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003907 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003908 default:
3909 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003910 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003911
3912 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3913 item.cellY, 1, 1);
3914 if (animateIcons) {
3915 // Animate all the applications up now
3916 view.setAlpha(0f);
3917 view.setScaleX(0f);
3918 view.setScaleY(0f);
3919 bounceAnims.add(createNewAppBounceAnimation(view, i));
3920 newShortcutsScreenId = item.screenId;
3921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003922 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003923
Winson Chung997a9232013-07-24 15:33:46 -07003924 if (animateIcons) {
3925 // Animate to the correct page
3926 if (newShortcutsScreenId > -1) {
3927 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003928 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003929 final Runnable startBounceAnimRunnable = new Runnable() {
3930 public void run() {
3931 anim.playTogether(bounceAnims);
3932 anim.start();
3933 }
3934 };
Winson Chung997a9232013-07-24 15:33:46 -07003935 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003936 // We post the animation slightly delayed to prevent slowdowns
3937 // when we are loading right after we return to launcher.
3938 mWorkspace.postDelayed(new Runnable() {
3939 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003940 if (mWorkspace != null) {
3941 mWorkspace.snapToPage(newScreenIndex);
3942 mWorkspace.postDelayed(startBounceAnimRunnable,
3943 NEW_APPS_ANIMATION_DELAY);
3944 }
Winson Chung94d67682013-09-25 16:29:40 -07003945 }
3946 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003947 } else {
3948 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003949 }
3950 }
Winson Chung64359a52013-07-08 17:17:08 -07003951 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003952 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003953 }
3954
Joe Onorato9c1289c2009-08-17 11:03:03 -04003955 /**
3956 * Implementation of the method from LauncherModel.Callbacks.
3957 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003958 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003959 Runnable r = new Runnable() {
3960 public void run() {
3961 bindFolders(folders);
3962 }
3963 };
3964 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003965 return;
3966 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003967 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003968 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003969
3970 /**
3971 * Add the views for a widget to the workspace.
3972 *
3973 * Implementation of the method from LauncherModel.Callbacks.
3974 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003975 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003976 Runnable r = new Runnable() {
3977 public void run() {
3978 bindAppWidget(item);
3979 }
3980 };
3981 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003982 return;
3983 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003984
Daniel Sandler843e8602010-06-07 14:59:01 -04003985 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3986 if (DEBUG_WIDGETS) {
3987 Log.d(TAG, "bindAppWidget: " + item);
3988 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003989 final Workspace workspace = mWorkspace;
3990
Adam Cohen59400422014-03-05 18:07:04 -08003991 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00003992 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08003993
Sunny Goyal9b4b0812014-10-08 10:47:28 -07003994 if (!mIsSafeModeEnabled
3995 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003996 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
3997
Sunny Goyalff572272014-07-23 13:58:07 -07003998 if (appWidgetInfo == null) {
3999 if (DEBUG_WIDGETS) {
4000 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4001 + " belongs to component " + item.providerName
4002 + ", as the povider is null");
4003 }
4004 LauncherModel.deleteItemFromDatabase(this, item);
4005 return;
4006 }
Sunny Goyalff572272014-07-23 13:58:07 -07004007
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004008 // If we do not have a valid id, try to bind an id.
4009 if ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0) {
4010 // Note: This assumes that the id remap broadcast is received before this step.
4011 // If that is not the case, the id remap will be ignored and user may see the
4012 // click to setup view.
4013 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
4014 pendingInfo.spanX = item.spanX;
4015 pendingInfo.spanY = item.spanY;
4016 pendingInfo.minSpanX = item.minSpanX;
4017 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08004018 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004019
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004020 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4021 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4022 newWidgetId, appWidgetInfo, options);
4023
4024 // TODO consider showing a permission dialog when the widget is clicked.
4025 if (!success) {
4026 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4027 if (DEBUG_WIDGETS) {
4028 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4029 + " belongs to component " + item.providerName
4030 + ", as the launcher is unable to bing a new widget id");
4031 }
4032 LauncherModel.deleteItemFromDatabase(this, item);
4033 return;
Sunny Goyalff572272014-07-23 13:58:07 -07004034 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004035
4036 item.appWidgetId = newWidgetId;
4037
4038 // If the widget has a configure activity, it is still needs to set it up, otherwise
4039 // the widget is ready to go.
4040 item.restoreStatus = (appWidgetInfo.configure == null)
4041 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4042 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4043
4044 LauncherModel.updateItemInDatabase(this, item);
4045 } else if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0)
4046 && (appWidgetInfo.configure == null)) {
4047 // If the ID is already valid, verify if we need to configure or not.
4048 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4049 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004050 }
Sunny Goyalff572272014-07-23 13:58:07 -07004051 }
4052
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004053 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004054 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004055 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004056 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4057 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004058 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004059
Sunny Goyal56c73602015-09-25 12:55:01 -07004060 // Verify that we own the widget
4061 AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4062 if (info == null || appWidgetInfo == null ||
4063 !info.provider.equals(appWidgetInfo.provider)) {
Hyunyoung Song70264a92016-02-03 15:28:47 -08004064 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId + " info=" + info
4065 + " appWidgetInfo=" + appWidgetInfo);
Sunny Goyal56c73602015-09-25 12:55:01 -07004066 deleteWidgetInfo(item);
4067 return;
4068 }
4069
Sunny Goyal651077b2014-06-30 14:15:31 -07004070 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004071 item.minSpanX = appWidgetInfo.minSpanX;
4072 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal651077b2014-06-30 14:15:31 -07004073 } else {
4074 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004075 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4076 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004077 view.updateIcon(mIconCache);
4078 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004079 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004080 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004081 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004082
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07004083 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004084 workspace.requestLayout();
4085
Daniel Sandler843e8602010-06-07 14:59:01 -04004086 if (DEBUG_WIDGETS) {
4087 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4088 + (SystemClock.uptimeMillis()-start) + "ms");
4089 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004090 }
4091
Sunny Goyalff572272014-07-23 13:58:07 -07004092 /**
4093 * Restores a pending widget.
4094 *
4095 * @param appWidgetId The app widget id
4096 * @param cellInfo The position on screen where to create the widget.
4097 */
4098 private void completeRestoreAppWidget(final int appWidgetId) {
4099 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4100 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4101 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4102 return;
4103 }
4104
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004105 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004106 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4107
4108 mWorkspace.reinflateWidgetsIfNecessary();
4109 LauncherModel.updateItemInDatabase(this, info);
4110 }
4111
Adam Cohen1462de32012-07-24 22:34:36 -07004112 public void onPageBoundSynchronously(int page) {
4113 mSynchronouslyBoundPages.add(page);
4114 }
4115
Sunny Goyal527c7d32015-08-28 15:19:36 -07004116 @Override
4117 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4118 if (mPendingExecutor != null) {
4119 mPendingExecutor.markCompleted();
4120 }
4121 mPendingExecutor = executor;
4122 executor.attachTo(this);
4123 }
4124
4125 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4126 if (mPendingExecutor == executor) {
4127 mPendingExecutor = null;
4128 }
4129 }
4130
Joe Onorato9c1289c2009-08-17 11:03:03 -04004131 /**
4132 * Callback saying that there aren't any more items to bind.
4133 *
4134 * Implementation of the method from LauncherModel.Callbacks.
4135 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004136 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004137 Runnable r = new Runnable() {
4138 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004139 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004140 }
4141 };
4142 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004143 return;
4144 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004145 if (mSavedState != null) {
4146 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004147 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004148 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004149
4150 long folderId = mSavedState.getLong(RUNTIME_STATE_OPEN_FOLDER_ID);
4151 if (folderId != 0) {
4152 View view = mWorkspace.getHomescreenIconByItemId(folderId);
4153 if (view instanceof FolderIcon) {
4154 FolderIcon icon = (FolderIcon) view;
4155 FolderInfo info = icon.getFolderInfo();
4156 long currentScreenId = mWorkspace.getScreenIdForPageIndex(
4157 mWorkspace.getNextPage());
4158 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
4159 || info.screenId == currentScreenId) {
4160 // We can show the folder
4161 openFolder(icon, false);
4162 } else {
4163 Launcher.addDumpLog(TAG, "Saved state contains folder " + info +
4164 " but current screen is " + currentScreenId);
4165 }
4166 }
4167 }
4168
Joe Onorato9c1289c2009-08-17 11:03:03 -04004169 mSavedState = null;
4170 }
4171
Adam Cohen1462de32012-07-24 22:34:36 -07004172 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004173
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004174 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004175 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004176
4177 // If we received the result of any pending adds while the loader was running (e.g. the
4178 // widget configuration forced an orientation change), process them now.
4179 if (sPendingAddItem != null) {
4180 final long screenId = completeAdd(sPendingAddItem);
4181
4182 // TODO: this moves the user to the page where the pending item was added. Ideally,
4183 // the screen would be guaranteed to exist after bind, and the page would be set through
4184 // the workspace restore process.
4185 mWorkspace.post(new Runnable() {
4186 @Override
4187 public void run() {
4188 mWorkspace.snapToScreenId(screenId);
4189 }
4190 });
4191 sPendingAddItem = null;
4192 }
4193
Sunny Goyal756adbc2015-04-16 15:20:51 -07004194 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004195
4196 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004197 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004198 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004199 }
4200
Adam Cohen3ed316a2014-07-23 18:21:20 -07004201 private void sendLoadingCompleteBroadcastIfNecessary() {
4202 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4203 String permission =
4204 getResources().getString(R.string.receive_first_load_broadcast_permission);
4205 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4206 sendBroadcast(intent, permission);
4207 SharedPreferences.Editor editor = mSharedPrefs.edit();
4208 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4209 editor.apply();
4210 }
4211 }
4212
Winson Chunga0b7e862013-09-05 16:03:15 -07004213 public boolean isAllAppsButtonRank(int rank) {
4214 if (mHotseat != null) {
4215 return mHotseat.isAllAppsButtonRank(rank);
4216 }
4217 return false;
4218 }
4219
Winson Chunga2413752012-04-03 14:22:34 -07004220 private boolean canRunNewAppsAnimation() {
4221 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004222 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4223 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004224 }
4225
Winson Chungc9168342013-06-26 14:54:55 -07004226 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004227 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004228 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4229 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004230 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004231 return bounceAnim;
4232 }
4233
Adam Cohen27772732013-11-11 14:00:56 +00004234 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004235 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004236 }
4237
Tony Wickham3a3517f2015-10-06 11:27:04 -07004238 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004239 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004240 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004241 }
4242
Tony Wickham55616cd2015-09-23 14:55:17 -07004243 public int getSearchBarHeight() {
4244 if (mLauncherCallbacks != null) {
4245 return mLauncherCallbacks.getSearchBarHeight();
4246 }
4247 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4248 }
4249
Winson Chung88fa7412015-08-03 14:25:28 -07004250 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004251 if (mSearchDropTargetBar == null) {
4252 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004253 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004254 if (mQsb != null) {
4255 mSearchDropTargetBar.removeView(mQsb);
4256 mQsb = null;
4257 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004258 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004259 }
4260
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004261 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004262 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4263 * multiple calls to bind the same list.)
4264 */
4265 @Thunk ArrayList<AppInfo> mTmpAppsList;
4266 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4267 public void run() {
4268 bindAllApplications(mTmpAppsList);
4269 mTmpAppsList = null;
4270 }
4271 };
4272
4273 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004274 * Add the icons for all apps.
4275 *
4276 * Implementation of the method from LauncherModel.Callbacks.
4277 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004278 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004279 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4280 mTmpAppsList = apps;
4281 return;
4282 }
4283
Winson Chungb745afb2015-03-02 11:51:23 -08004284 if (mAppsView != null) {
4285 mAppsView.setApps(apps);
4286 }
Adam Cohen9211d422014-10-07 18:14:53 -07004287 if (mLauncherCallbacks != null) {
4288 mLauncherCallbacks.bindAllApplications(apps);
4289 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004290 }
4291
4292 /**
4293 * A package was updated.
4294 *
4295 * Implementation of the method from LauncherModel.Callbacks.
4296 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004297 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004298 Runnable r = new Runnable() {
4299 public void run() {
4300 bindAppsUpdated(apps);
4301 }
4302 };
4303 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004304 return;
4305 }
4306
Winson Chungb745afb2015-03-02 11:51:23 -08004307 if (mAppsView != null) {
4308 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004309 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004310 }
4311
Sunny Goyal4390ace2014-10-13 11:33:11 -07004312 @Override
4313 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4314 Runnable r = new Runnable() {
4315 public void run() {
4316 bindWidgetsRestored(widgets);
4317 }
4318 };
4319 if (waitUntilResume(r)) {
4320 return;
4321 }
4322 mWorkspace.widgetsRestored(widgets);
4323 }
4324
Joe Onorato9c1289c2009-08-17 11:03:03 -04004325 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004326 * Some shortcuts were updated in the background.
4327 *
4328 * Implementation of the method from LauncherModel.Callbacks.
4329 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004330 @Override
4331 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4332 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004333 Runnable r = new Runnable() {
4334 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004335 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004336 }
4337 };
4338 if (waitUntilResume(r)) {
4339 return;
4340 }
4341
Sunny Goyal4390ace2014-10-13 11:33:11 -07004342 if (!updated.isEmpty()) {
4343 mWorkspace.updateShortcuts(updated);
4344 }
4345
4346 if (!removed.isEmpty()) {
4347 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4348 for (ShortcutInfo si : removed) {
4349 removedComponents.add(si.getTargetComponent());
4350 }
4351 mWorkspace.removeItemsByComponentName(removedComponents, user);
4352 // Notify the drag controller
4353 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004354 }
4355 }
4356
4357 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004358 * Update the state of a package, typically related to install state.
4359 *
4360 * Implementation of the method from LauncherModel.Callbacks.
4361 */
Sunny Goyale755d462014-07-22 13:48:29 -07004362 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004363 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4364 Runnable r = new Runnable() {
4365 public void run() {
4366 bindRestoreItemsChange(updates);
4367 }
4368 };
4369 if (waitUntilResume(r)) {
4370 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004371 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004372
Sunny Goyal756adbc2015-04-16 15:20:51 -07004373 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004374 }
4375
4376 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004377 * A package was uninstalled. We take both the super set of packageNames
4378 * in addition to specific applications to remove, the reason being that
4379 * this can be called when a package is updated as well. In that scenario,
4380 * we only remove specific components from the workspace, where as
4381 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004382 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004383 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004384 * Implementation of the method from LauncherModel.Callbacks.
4385 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004386 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004387 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004388 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004389 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004390 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004391 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004392 }
Winson Chungd64d1762013-08-20 14:37:16 -07004393 };
4394 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004395 return;
4396 }
4397
Sunny Goyal1a745e82014-10-02 15:58:31 -07004398 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004399 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4400 for (AppInfo info : appInfos) {
4401 removedComponents.add(info.componentName);
4402 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004403 if (!packageNames.isEmpty()) {
4404 mWorkspace.removeItemsByPackageName(packageNames, user);
4405 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004406 if (!removedComponents.isEmpty()) {
4407 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004408 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004409 // Notify the drag controller
4410 mDragController.onAppsRemoved(packageNames, removedComponents);
4411
Sunny Goyal1a745e82014-10-02 15:58:31 -07004412 } else {
4413 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004414 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004415
Winson Chungdf95eb12013-10-16 14:57:07 -07004416 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004417 if (mAppsView != null) {
4418 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004419 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004420 }
Joe Onoratobe386092009-11-17 17:32:16 -08004421
Michael Jurkac402cd92013-05-20 15:49:32 +02004422 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004423 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004424 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004425 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004426 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004427
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004428 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004429 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004430 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004431 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004432 return;
4433 }
4434
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004435 if (mWidgetsView != null && model != null) {
4436 mWidgetsView.addWidgets(model);
4437 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004438 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004439 }
4440
Winson Chung400438b2011-01-16 17:53:48 -08004441 private int mapConfigurationOriActivityInfoOri(int configOri) {
4442 final Display d = getWindowManager().getDefaultDisplay();
4443 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4444 switch (d.getRotation()) {
4445 case Surface.ROTATION_0:
4446 case Surface.ROTATION_180:
4447 // We are currently in the same basic orientation as the natural orientation
4448 naturalOri = configOri;
4449 break;
4450 case Surface.ROTATION_90:
4451 case Surface.ROTATION_270:
4452 // We are currently in the other basic orientation to the natural orientation
4453 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4454 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4455 break;
4456 }
4457
4458 int[] oriMap = {
4459 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4460 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4461 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4462 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4463 };
4464 // Since the map starts at portrait, we need to offset if this device's natural orientation
4465 // is landscape.
4466 int indexOffset = 0;
4467 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4468 indexOffset = 1;
4469 }
4470 return oriMap[(d.getRotation() + indexOffset) % 4];
4471 }
Adam Cohen446e9402011-09-15 18:21:21 -07004472
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004473 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004474 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004475 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004476 if (Utilities.ATLEAST_JB_MR2) {
4477 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4478 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004479 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4480 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004481 }
Winson Chung4b919f82012-05-01 10:44:08 -07004482 }
4483 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004484
Winson Chung4b919f82012-05-01 10:44:08 -07004485 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004486 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004487 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004488 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004489 } else {
4490 mHandler.postDelayed(new Runnable() {
4491 public void run() {
4492 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4493 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004494 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004495 }
Winson Chung4b919f82012-05-01 10:44:08 -07004496 }
Winson Chung400438b2011-01-16 17:53:48 -08004497 }
4498
Winson Chunge43a1e72014-01-15 10:33:02 -08004499 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004500 if (mLauncherCallbacks != null) {
4501 return mLauncherCallbacks.isLauncherPreinstalled();
4502 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004503 PackageManager pm = getPackageManager();
4504 try {
4505 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4506 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4507 return true;
4508 } else {
4509 return false;
4510 }
4511 } catch (NameNotFoundException e) {
4512 e.printStackTrace();
4513 return false;
4514 }
4515 }
4516
Adam Cohenea90f832014-05-21 15:03:34 -07004517 /**
4518 * This method indicates whether or not we should suggest default wallpaper dimensions
4519 * when our wallpaper cropper was not yet used to set a wallpaper.
4520 */
4521 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004522 if (mLauncherCallbacks != null) {
4523 return mLauncherCallbacks.overrideWallpaperDimensions();
4524 }
Adam Cohenea90f832014-05-21 15:03:34 -07004525 return true;
4526 }
4527
Adam Cohen432609a2014-03-13 17:03:22 -07004528 /**
4529 * To be overridden by subclasses to indicate that there is an activity to launch
4530 * before showing the standard launcher experience.
4531 */
4532 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004533 if (mLauncherCallbacks != null) {
4534 return mLauncherCallbacks.hasFirstRunActivity();
4535 }
Adam Cohen432609a2014-03-13 17:03:22 -07004536 return false;
4537 }
4538
4539 /**
4540 * To be overridden by subclasses to launch any first run activity
4541 */
4542 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004543 if (mLauncherCallbacks != null) {
4544 return mLauncherCallbacks.getFirstRunActivity();
4545 }
Adam Cohen432609a2014-03-13 17:03:22 -07004546 return null;
4547 }
4548
Winson Chunga6945242014-01-08 14:04:34 -08004549 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004550 return !ActivityManager.isRunningInTestHarness() &&
4551 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004552 }
4553
Adam Cohen4a9423d2014-03-28 14:22:31 -07004554 protected boolean hasRunFirstRunActivity() {
4555 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4556 }
4557
Adam Cohen432609a2014-03-13 17:03:22 -07004558 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004559 if (shouldRunFirstRunActivity() &&
4560 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004561 Intent firstRunIntent = getFirstRunActivity();
4562 if (firstRunIntent != null) {
4563 startActivity(firstRunIntent);
4564 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004565 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004566 }
4567 }
Adam Cohen432609a2014-03-13 17:03:22 -07004568 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004569 }
4570
4571 private void markFirstRunActivityShown() {
4572 SharedPreferences.Editor editor = mSharedPrefs.edit();
4573 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4574 editor.apply();
4575 }
4576
Adam Cohen432609a2014-03-13 17:03:22 -07004577 /**
4578 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4579 * screen that must be displayed and dismissed.
4580 */
4581 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004582 if (mLauncherCallbacks != null) {
4583 return mLauncherCallbacks.hasDismissableIntroScreen();
4584 }
Adam Cohen432609a2014-03-13 17:03:22 -07004585 return false;
4586 }
4587
4588 /**
4589 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4590 */
4591 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004592 if (mLauncherCallbacks != null) {
4593 return mLauncherCallbacks.getIntroScreen();
4594 }
Adam Cohen432609a2014-03-13 17:03:22 -07004595 return null;
4596 }
4597
4598 /**
4599 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4600 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4601 */
4602 private boolean shouldShowIntroScreen() {
4603 return hasDismissableIntroScreen() &&
4604 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4605 }
4606
4607 protected void showIntroScreen() {
4608 View introScreen = getIntroScreen();
4609 changeWallpaperVisiblity(false);
4610 if (introScreen != null) {
4611 mDragLayer.showOverlayView(introScreen);
4612 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004613 if (mLauncherOverlayContainer != null) {
4614 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4615 }
Adam Cohen432609a2014-03-13 17:03:22 -07004616 }
4617
4618 public void dismissIntroScreen() {
4619 markIntroScreenDismissed();
4620 if (showFirstRunActivity()) {
4621 // We delay hiding the intro view until the first run activity is showing. This
4622 // avoids a blip.
4623 mWorkspace.postDelayed(new Runnable() {
4624 @Override
4625 public void run() {
4626 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004627 if (mLauncherOverlayContainer != null) {
4628 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4629 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004630 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004631 }
4632 }, ACTIVITY_START_DELAY);
4633 } else {
4634 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004635 if (mLauncherOverlayContainer != null) {
4636 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4637 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004638 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004639 }
4640 changeWallpaperVisiblity(true);
4641 }
4642
4643 private void markIntroScreenDismissed() {
4644 SharedPreferences.Editor editor = mSharedPrefs.edit();
4645 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4646 editor.apply();
4647 }
4648
Adam Cohen091440a2015-03-18 14:16:05 -07004649 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004650 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4651 // on the device, then we always show the first run cling experience (or if there is no
4652 // launcher2). Otherwise, we prompt the user upon started for migration
4653 LauncherClings launcherClings = new LauncherClings(this);
4654 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004655 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004656 if (mModel.canMigrateFromOldLauncherDb(this)) {
4657 launcherClings.showMigrationCling();
4658 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004659 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004660 }
4661 }
4662 }
4663
Winson Chunga6945242014-01-08 14:04:34 -08004664 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004665 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4666 if (mHotseat != null) mHotseat.setAlpha(1f);
4667 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004668 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4669 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004670 }
4671
4672 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004673 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4674 if (mHotseat != null) mHotseat.setAlpha(0f);
4675 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004676 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4677 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004678 }
4679
Winson Chung5ffd51d2015-06-25 11:36:50 -07004680 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004681 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004682 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004683 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004684 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004685 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004686 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4687 if (userHandle != null) {
4688 user = UserHandleCompat.fromUser(userHandle);
4689 }
4690 }
4691 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004692 }
4693
4694 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004695 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004696 if (user == null) {
4697 user = UserHandleCompat.myUserHandle();
4698 }
4699
4700 // Called from search suggestion, add the profile extra to the intent to ensure that we
4701 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004702 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004703 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004704 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004705 return null;
4706 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004707 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004708 }
4709
Winson Chung5ffd51d2015-06-25 11:36:50 -07004710 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004711 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4712 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004713 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004714 UserHandleCompat.myUserHandle());
4715 }
4716
Winson Chung5ffd51d2015-06-25 11:36:50 -07004717 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004718 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4719 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004720 mWorkspace.onExternalDragStartedWithItem(dragView);
4721 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004722 }
4723
Winson Chung5ffd51d2015-06-25 11:36:50 -07004724 protected void moveWorkspaceToDefaultScreen() {
4725 mWorkspace.moveToDefaultScreen(false);
4726 }
4727
Anjali Koppalf5d29132014-02-28 13:33:27 -08004728 @Override
4729 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004730 if (mLauncherCallbacks != null) {
4731 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4732 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004733 }
4734
Winson Chung80baf5a2010-08-09 16:03:15 -07004735 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004736 * Returns a FastBitmapDrawable with the icon, accurately sized.
4737 */
4738 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4739 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4740 d.setFilterBitmap(true);
4741 resizeIconDrawable(d);
4742 return d;
4743 }
4744
4745 /**
4746 * Resizes an icon drawable to the correct icon size.
4747 */
Winson5fbe0742015-09-30 15:33:00 -07004748 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004749 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004750 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004751 }
4752
4753 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004754 * Prints out out state for debugging.
4755 */
4756 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004757 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004758 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004759 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4760 Log.d(TAG, "mRestoring=" + mRestoring);
4761 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004762 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004763 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004764 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004765
Daniel Sandler325dc232013-06-05 22:57:57 -04004766 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004767 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004768
4769 @Override
4770 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4771 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004772 // Dump workspace
4773 writer.println(prefix + "Workspace Items");
4774 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4775 writer.println(prefix + " Homescreen " + i);
4776
4777 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4778 for (int j = 0; j < layout.getChildCount(); j++) {
4779 Object tag = layout.getChildAt(j).getTag();
4780 if (tag != null) {
4781 writer.println(prefix + " " + tag.toString());
4782 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004783 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004784 }
Sunny Goyala1365452015-10-01 15:46:24 -07004785
4786 writer.println(prefix + " Hotseat");
4787 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4788 for (int j = 0; j < layout.getChildCount(); j++) {
4789 Object tag = layout.getChildAt(j).getTag();
4790 if (tag != null) {
4791 writer.println(prefix + " " + tag.toString());
4792 }
4793 }
4794
4795 synchronized (sDumpLogs) {
4796 writer.println();
4797 writer.println(prefix + "Debug logs");
4798 for (String log : sDumpLogs) {
4799 writer.println(prefix + " " + log);
4800 }
4801 }
4802
Adam Cohen9211d422014-10-07 18:14:53 -07004803 if (mLauncherCallbacks != null) {
4804 mLauncherCallbacks.dump(prefix, fd, writer, args);
4805 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004806 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004807
Sunny Goyala1365452015-10-01 15:46:24 -07004808 public static void addDumpLog(String tag, String log) {
4809 Log.d(tag, log);
4810 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004811 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004812 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004813 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004814 }
4815
Adam Cohen59400422014-03-05 18:07:04 -08004816 public static CustomAppWidget getCustomAppWidget(String name) {
4817 return sCustomAppWidgets.get(name);
4818 }
4819
4820 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4821 return sCustomAppWidgets;
4822 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004823}
Michael Jurka2763be32011-02-24 11:19:57 -08004824
Dan Sandlerd5024042014-01-09 15:01:33 -05004825interface DebugIntents {
4826 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4827 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004828}