blob: 7330712f87bf94d1675a265a5febf99b0b71b918 [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;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700110import com.android.launcher3.model.WidgetsModel;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700111import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700112import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700113import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700114import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700115import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700116import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700117import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700118import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700119
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700120import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700121import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700122import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700124import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700127import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700128import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130/**
131 * Default launcher application.
132 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100133public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700134 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chung006ee262015-08-03 14:40:11 -0700135 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700136 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700137 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
Daniel Sandlerf061f822013-06-27 13:59:36 -0400139 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700140 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700141 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700143
Dan Sandlerd5024042014-01-09 15:01:33 -0500144 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700147 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700148 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700149 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Michael Jurka8b805b12012-04-18 14:23:14 -0700151 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700152 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700153
Sunny Goyal28c6b962015-10-12 11:42:05 -0700154 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
155
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700156 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
157 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
158 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
159
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700160 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
161
Mathew Inwood876a8462013-06-14 14:12:41 +0100162 /**
163 * IntentStarter uses request codes starting with this. This must be greater than all activity
164 * request codes used internally.
165 */
166 protected static final int REQUEST_LAST = 100;
167
Michael Jurka0a457bf2012-11-19 14:05:05 -0800168 // To turn on these properties, type
169 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800170 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171
Winson Chung2672ff92012-05-04 16:22:30 -0700172 // The Intent extra that defines whether to ignore the launch animation
173 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400174 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700175
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: int
177 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700178 // Type: int
179 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal08442b82015-10-21 17:15:08 -0700180 // Type: long
181 private static final String RUNTIME_STATE_OPEN_FOLDER_ID = "launcher.open_folder_id";
Sunny Goyal756cd262015-08-20 12:33:21 -0700182 // Type: Content Values / parcelable
183 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700184 // Type: parcelable
185 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000186 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800187 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188
Adam Cohen432609a2014-03-13 17:03:22 -0700189 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800190 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
191
Adam Cohen3ed316a2014-07-23 18:21:20 -0700192 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
193 static final String ACTION_FIRST_LOAD_COMPLETE =
194 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
195
Sunny Goyal594d76d2014-11-06 10:12:54 -0800196 private static final String QSB_WIDGET_ID = "qsb_widget_id";
197 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
198
Winson Chunga6945242014-01-08 14:04:34 -0800199 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
200
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700202 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
203 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700204
Adam Cohen091440a2015-03-18 14:16:05 -0700205 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700206 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700208 private boolean mIsSafeModeEnabled;
209
Adam Cohenc2d6e892014-10-16 09:49:24 -0700210 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
211 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700212 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700213
Joe Onorato9c1289c2009-08-17 11:03:03 -0400214 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700215 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
216 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700217 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
Winson Chunga2413752012-04-03 14:22:34 -0700219 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700220 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
221 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700222 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700223
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800224 private final BroadcastReceiver mCloseSystemDialogsReceiver
225 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800226
Adam Cohen091440a2015-03-18 14:16:05 -0700227 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700228 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800229 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700230 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800231 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700232
233 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700234
Sunny Goyalffe83f12014-08-14 17:39:34 -0700235 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700236 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700237
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700238 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800239 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800240 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700241
Michael Jurka0280c3b2010-09-17 15:00:07 -0700242 private int[] mTmpAddItemCellCoordinates = new int[2];
243
Sunny Goyal316490e2015-06-02 09:38:28 -0700244 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800245 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700246
Michael Jurka838a4ca2011-02-07 13:33:06 -0800247 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700248 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700249
Winson Chungc51db6a2011-10-05 11:44:49 -0700250 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700251 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700252
253 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700254 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700255
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700256 // Main container view and the model for the widget tray screen.
257 @Thunk WidgetsContainerView mWidgetsView;
258 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700259
Sunny Goyal594d76d2014-11-06 10:12:54 -0800260 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700263 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
264 // scroll issues (because the workspace may not have been measured yet) and extra work.
265 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
266 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267
268 private SpannableStringBuilder mDefaultKeySsb = null;
269
Adam Cohen091440a2015-03-18 14:16:05 -0700270 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400271
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800272 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 private boolean mRestoring;
274 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700275 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276
Michael Jurka1e2f4652013-07-08 18:03:46 -0700277 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700278 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700279 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700280
Joe Onorato9c1289c2009-08-17 11:03:03 -0400281 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800282 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700283 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800284 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700285 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800286 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400287
Sunny Goyal639e9062015-08-19 19:17:06 -0700288 private LauncherClings mClings;
289
Sunny Goyale2df0622015-04-24 11:27:00 -0700290 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700291
Adam Cohen61f560d2013-09-30 15:58:20 -0700292 private View.OnTouchListener mHapticFeedbackTouchListener;
293
Adam Cohended9f8d2010-11-03 13:25:16 -0700294 // Related to the auto-advancing of widgets
295 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700296 private static final int ADVANCE_INTERVAL = 20000;
297 private static final int ADVANCE_STAGGER = 250;
298
299 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700300 private long mAutoAdvanceSentTime;
301 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700302 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700303
Winson Chung400438b2011-01-16 17:53:48 -0800304 // Determines how long to wait after a rotation before restoring the screen orientation to
305 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700306 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800307
Adam Cohen091440a2015-03-18 14:16:05 -0700308 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700309
Adam Cohen1462de32012-07-24 22:34:36 -0700310 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700311 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700312
Sunny Goyala1365452015-10-01 15:46:24 -0700313 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
314 private static final Date sDateStamp = new Date();
315 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700316 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700317
Winson Chung46353de2012-02-16 14:05:10 -0800318 // We only want to get the SharedPreferences once since it does an FS stat each time we get
319 // it from the context.
320 private SharedPreferences mSharedPrefs;
321
Winson Chungf0c6ae02012-03-21 16:10:31 -0700322 // Holds the page that we need to animate to, and the icon views that we need to animate up
323 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700324 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700325 private Bitmap mFolderIconBitmap;
326 private Canvas mFolderIconCanvas;
327 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700328
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700329 private DeviceProfile mDeviceProfile;
330
Adam Cohen4b66bf32015-09-18 12:15:19 -0700331 private boolean mMoveToDefaultScreenFromNewIntent;
332
Winson Chung13eb5272015-05-11 16:30:13 -0700333 // This is set to the view that launched the activity that navigated the user away from
334 // launcher. Since there is no callback for when the activity has finished launching, enable
335 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800336 private BubbleTextView mWaitingForResume;
337
Adam Cohen59400422014-03-05 18:07:04 -0800338 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
339 new HashMap<String, CustomAppWidget>();
340
Adam Cohen59400422014-03-05 18:07:04 -0800341 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700342 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
343 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800344 }
345 }
346
Adam Cohen091440a2015-03-18 14:16:05 -0700347 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700348 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700349 if (mWorkspace != null) {
350 mWorkspace.buildPageHardwareLayers();
351 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700352 }
353 };
354
Adam Cohendb364c32014-05-20 14:23:40 -0700355 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800356
Adam Cohen091440a2015-03-18 14:16:05 -0700357 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800358 int requestCode;
359 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700360 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700361 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800362 int cellX;
363 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700364 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 }
366
Daniel Sandlerff02d492013-08-05 02:12:05 -0400367 private Stats mStats;
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700368 FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700369 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400370
371 @Thunk void setOrientation() {
372 if (mRotationEnabled) {
373 unlockScreenOrientation(true);
374 } else {
375 setRequestedOrientation(
376 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700377 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400378 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700379
Sunny Goyal7779d622015-06-11 16:18:39 -0700380 private Runnable mUpdateOrientationRunnable = new Runnable() {
381 public void run() {
382 setOrientation();
383 }
384 };
385
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800386 @Override
387 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700388 if (DEBUG_STRICT_MODE) {
389 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
390 .detectDiskReads()
391 .detectDiskWrites()
392 .detectNetwork() // or .detectAll() for all detectable problems
393 .penaltyLog()
394 .build());
395 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
396 .detectLeakedSqlLiteObjects()
397 .detectLeakedClosableObjects()
398 .penaltyLog()
399 .penaltyDeath()
400 .build());
401 }
402
Adam Cohen9211d422014-10-07 18:14:53 -0700403 if (mLauncherCallbacks != null) {
404 mLauncherCallbacks.preOnCreate();
405 }
406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400408
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400409 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700410
Adam Cohen2e6da152015-05-06 11:42:25 -0700411 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700412 mDeviceProfile = getResources().getConfiguration().orientation
413 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700414 app.getInvariantDeviceProfile().landscapeProfile
415 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700416
Sunny Goyalf7258242015-10-19 16:59:07 -0700417 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700418 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800419 mModel = app.setLauncher(this);
420 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700421
Joe Onorato41a12d22009-10-31 18:30:00 -0400422 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700423 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700424
Daniel Sandlerff02d492013-08-05 02:12:05 -0400425 mStats = new Stats(this);
426
Sunny Goyalffe83f12014-08-14 17:39:34 -0700427 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700428
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700429 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
430 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700431
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700432 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
433 // this also ensures that any synchronous binding below doesn't re-trigger another
434 // LauncherModel load.
435 mPaused = false;
436
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200438 android.os.Debug.startMethodTracing(
439 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 }
441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700443
Tony Wickhameef44322015-10-20 13:24:36 -0700444 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
445 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700447 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448
Joe Onorato7c312c12009-08-13 21:36:53 -0700449 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700450
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 mSavedState = savedInstanceState;
452 restoreState(mSavedState);
453
454 if (PROFILE_STARTUP) {
455 android.os.Debug.stopMethodTracing();
456 }
457
458 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700459 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700460 // If the user leaves launcher, then we should just load items asynchronously when
461 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700462 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 } else {
464 // We only load the page synchronously if the user rotates (or triggers a
465 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700466 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700467 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800468 }
469
470 // For handling default keys
471 mDefaultKeySsb = new SpannableStringBuilder();
472 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800473
474 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
475 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800476
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700477 mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
478 // In case we are on a device with locked rotation, we should look at preferences to check
479 // if the user has specifically allowed rotation.
480 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700481 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700482 }
483
484 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
485 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400486 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700487
Adam Cohen9211d422014-10-07 18:14:53 -0700488 if (mLauncherCallbacks != null) {
489 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700490 if (mLauncherCallbacks.hasLauncherOverlay()) {
491 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700492 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
493 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
494 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700495 mWorkspace.setLauncherOverlay(mLauncherOverlay);
496 }
Adam Cohen9211d422014-10-07 18:14:53 -0700497 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700498
499 if (shouldShowIntroScreen()) {
500 showIntroScreen();
501 } else {
502 showFirstRunActivity();
503 showFirstRunClings();
504 }
Adam Cohen9211d422014-10-07 18:14:53 -0700505 }
506
Sunny Goyal7779d622015-06-11 16:18:39 -0700507 @Override
508 public void onSettingsChanged(String settings, boolean value) {
509 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
510 mRotationEnabled = value;
511 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
512 mUpdateOrientationRunnable.run();
513 }
514 }
515 }
516
Adam Cohen9211d422014-10-07 18:14:53 -0700517 private LauncherCallbacks mLauncherCallbacks;
518
519 public void onPostCreate(Bundle savedInstanceState) {
520 super.onPostCreate(savedInstanceState);
521 if (mLauncherCallbacks != null) {
522 mLauncherCallbacks.onPostCreate(savedInstanceState);
523 }
524 }
525
526 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
527 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700528 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700529 private boolean mWorkspaceImportanceStored = false;
530 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700531 private int mWorkspaceImportanceForAccessibility =
532 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
533 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
534
535 @Override
536 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700537 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700538 return;
539 }
540 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700541 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700542 if (mWorkspace != null) {
543 mWorkspaceImportanceForAccessibility =
544 mWorkspace.getImportantForAccessibility();
545 mWorkspace.setImportantForAccessibility(
546 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
547 mWorkspaceImportanceStored = true;
548 }
549 if (mHotseat != null) {
550 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
551 mHotseat.setImportantForAccessibility(
552 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
553 mHotseatImportanceStored = true;
554 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700555 }
556
557 @Override
558 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700559 if (mWorkspaceImportanceStored && mWorkspace != null) {
560 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
561 }
562 if (mHotseatImportanceStored && mHotseat != null) {
563 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
564 }
565 mWorkspaceImportanceStored = false;
566 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700567 }
568 });
Adam Cohen9211d422014-10-07 18:14:53 -0700569 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700570 }
571
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700572 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700573 public void onLauncherProviderChange() {
574 if (mLauncherCallbacks != null) {
575 mLauncherCallbacks.onLauncherProviderChange();
576 }
577 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700578
Winson Chungef7f8742015-06-04 17:18:17 -0700579 /**
580 * Updates the bounds of all the overlays to match the new fixed bounds.
581 */
582 public void updateOverlayBounds(Rect newBounds) {
583 mAppsView.setSearchBarBounds(newBounds);
584 mWidgetsView.setSearchBarBounds(newBounds);
585 }
586
Adam Cohen9211d422014-10-07 18:14:53 -0700587 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700588 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700589 if (mLauncherCallbacks != null) {
590 return mLauncherCallbacks.hasCustomContentToLeft();
591 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700592 return false;
593 }
594
Dave Hawkeya8881582013-09-17 15:55:33 -0600595 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500596 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600597 * {@link #addToCustomContentPage}. This will only be invoked if
598 * {@link #hasCustomContentToLeft()} is {@code true}.
599 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500600 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700601 if (mLauncherCallbacks != null) {
602 mLauncherCallbacks.populateCustomContentContainer();
603 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600604 }
605
606 /**
607 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
608 * ensure the custom content page is added or removed if necessary.
609 */
610 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600611 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600612 // Not bound yet, wait for bindScreens to be called.
613 return;
614 }
615
616 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
617 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500618 mWorkspace.createCustomContentContainer();
619 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600620 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
621 mWorkspace.removeCustomContentPage();
622 }
623 }
624
Anton Hanssona2f665f2013-09-26 12:18:32 +0100625 public Stats getStats() {
626 return mStats;
627 }
628
Hyunyoung Song3f471442015-04-08 19:01:34 -0700629 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700630 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
631 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700632 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700633 }
634
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000635 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700636 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
637 // This cast is safe as long as the id < 0x00FFFFFF
638 // Since we jail all the dynamically generated views, there should be no clashes
639 // with any other views.
640 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000641 }
642
643 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700644 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
645 * a configuration step, this allows the proper animations to run after other transitions.
646 */
Adam Cohendb364c32014-05-20 14:23:40 -0700647 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700648 long screenId = args.screenId;
649 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
650 // When the screen id represents an actual screen (as opposed to a rank) we make sure
651 // that the drop page actually exists.
652 screenId = ensurePendingDropLayoutExists(args.screenId);
653 }
Adam Cohendb364c32014-05-20 14:23:40 -0700654
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800655 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800656 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700657 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700658 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700659 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800660 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700661 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700662 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700663 case REQUEST_RECONFIGURE_APPWIDGET:
664 completeRestoreAppWidget(args.appWidgetId);
665 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800666 }
Michael Jurka27614d22012-04-02 06:40:22 -0700667 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
668 // if you turned the screen off and then back while in All Apps, Launcher would not
669 // return to the workspace. Clearing mAddInfo.container here fixes this issue
670 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700671 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800672 }
673
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800674 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700675 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700676 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700677 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700678 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800679 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700680
Adam Cohenad4e15c2013-10-17 16:21:35 -0700681 Runnable exitSpringLoaded = new Runnable() {
682 @Override
683 public void run() {
684 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
685 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
686 }
687 };
688
Michael Jurka8b805b12012-04-18 14:23:14 -0700689 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700690 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700691 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700692 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
693 if (resultCode == RESULT_CANCELED) {
694 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700695 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700696 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700697 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800698 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700699 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700700
701 // When the user has granted permission to bind widgets, we should check to see if
702 // we can inflate the default search bar widget.
703 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700704 }
705 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200706 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
707 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700708 // User could have free-scrolled between pages before picking a wallpaper; make sure
709 // we move to the closest one now.
710 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700711 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200712 }
713 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700714 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200715
Adam Cohened66b2b2012-01-23 17:28:51 -0800716 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700717 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700718
Adam Cohendb364c32014-05-20 14:23:40 -0700719 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800720 // We have special handling for widgets
721 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800722 final int appWidgetId;
723 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
724 : -1;
725 if (widgetId < 0) {
726 appWidgetId = pendingAddWidgetId;
727 } else {
728 appWidgetId = widgetId;
729 }
730
Adam Cohenad4e15c2013-10-17 16:21:35 -0700731 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800732 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700733 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
734 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700735 result = RESULT_CANCELED;
736 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700737 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700738 @Override
739 public void run() {
740 exitSpringLoadedDragModeDelayed(false, 0, null);
741 }
742 };
Adam Cohendb364c32014-05-20 14:23:40 -0700743 if (workspaceLocked) {
744 // No need to remove the empty screen if we're mid-binding, as the
745 // the bind will not add the empty screen.
746 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
747 } else {
748 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
749 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
750 }
Winson Chung5aaab772012-04-27 15:24:02 -0700751 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700752 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700753 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
754 // When the screen id represents an actual screen (as opposed to a rank)
755 // we make sure that the drop page actually exists.
756 mPendingAddInfo.screenId =
757 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
758 }
Adam Cohendb364c32014-05-20 14:23:40 -0700759 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
760
761 dropLayout.setDropPending(true);
762 final Runnable onComplete = new Runnable() {
763 @Override
764 public void run() {
765 completeTwoStageWidgetDrop(resultCode, appWidgetId);
766 dropLayout.setDropPending(false);
767 }
768 };
769 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
770 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
771 } else {
772 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
773 mPendingAddInfo);
774 sPendingAddItem = args;
775 }
Winson Chung5aaab772012-04-27 15:24:02 -0700776 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800777 return;
778 }
779
Sunny Goyalff572272014-07-23 13:58:07 -0700780 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
781 if (resultCode == RESULT_OK) {
782 // Update the widget view.
783 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
784 pendingAddWidgetId, mPendingAddInfo);
785 if (workspaceLocked) {
786 sPendingAddItem = args;
787 } else {
788 completeAdd(args);
789 }
790 }
791 // Leave the widget in the pending state if the user canceled the configure.
792 return;
793 }
794
Sunny Goyalaad90582015-07-09 14:22:50 -0700795 if (requestCode == REQUEST_CREATE_SHORTCUT) {
796 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
797 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
798 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
799 mPendingAddInfo);
800 if (isWorkspaceLocked()) {
801 sPendingAddItem = args;
802 } else {
803 completeAdd(args);
804 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
805 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
806 }
807 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700808 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
809 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800812 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800813
814 }
815
816 @Override
817 protected void onActivityResult(
818 final int requestCode, final int resultCode, final Intent data) {
819 handleActivityResult(requestCode, resultCode, data);
820 if (mLauncherCallbacks != null) {
821 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
822 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800823 }
824
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600825 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700826 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600827 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700828 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
829 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
830 View v = null;
831 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
832 if (layout != null) {
833 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
834 }
835 Intent intent = sPendingAddItem.intent;
836 sPendingAddItem = null;
837 if (grantResults.length > 0
838 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
839 startActivity(v, intent, null);
840 } else {
841 // TODO: Show a snack bar with link to settings
842 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
843 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
844 }
845 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600846 if (mLauncherCallbacks != null) {
847 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
848 grantResults);
849 }
850 }
851
Adam Cohendb364c32014-05-20 14:23:40 -0700852 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
853 appWidgetId, ItemInfo info) {
854 PendingAddArguments args = new PendingAddArguments();
855 args.requestCode = requestCode;
856 args.intent = data;
857 args.container = info.container;
858 args.screenId = info.screenId;
859 args.cellX = info.cellX;
860 args.cellY = info.cellY;
861 args.appWidgetId = appWidgetId;
862 return args;
863 }
864
865 /**
866 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
867 *
868 * @param screenId the screen id to check
869 * @return the new screen, or screenId if it exists
870 */
871 private long ensurePendingDropLayoutExists(long screenId) {
872 CellLayout dropLayout =
873 (CellLayout) mWorkspace.getScreenWithId(screenId);
874 if (dropLayout == null) {
875 // it's possible that the add screen was removed because it was
876 // empty and a re-bind occurred
877 mWorkspace.addExtraEmptyScreen();
878 return mWorkspace.commitExtraEmptyScreen();
879 } else {
880 return screenId;
881 }
882 }
883
Adam Cohen091440a2015-03-18 14:16:05 -0700884 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800885 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800886 Runnable onCompleteRunnable = null;
887 int animationType = 0;
888
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700889 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800890 if (resultCode == RESULT_OK) {
891 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
892 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700893 mPendingAddWidgetInfo);
894 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800895 onCompleteRunnable = new Runnable() {
896 @Override
897 public void run() {
898 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700899 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700900 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
901 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800902 }
903 };
904 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800905 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800906 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800907 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700908 if (mDragLayer.getAnimatedView() != null) {
909 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
910 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
911 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700912 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700913 // The animated view may be null in the case of a rotation during widget configuration
914 onCompleteRunnable.run();
915 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 }
917
918 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700919 protected void onStop() {
920 super.onStop();
921 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700922
923 if (mLauncherCallbacks != null) {
924 mLauncherCallbacks.onStop();
925 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700926 }
927
928 @Override
929 protected void onStart() {
930 super.onStart();
931 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700932
933 if (mLauncherCallbacks != null) {
934 mLauncherCallbacks.onStart();
935 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700936 }
937
938 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200940 long startTime = 0;
941 if (DEBUG_RESUME_TIME) {
942 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400943 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200944 }
Adam Cohen9211d422014-10-07 18:14:53 -0700945
946 if (mLauncherCallbacks != null) {
947 mLauncherCallbacks.preOnResume();
948 }
949
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700951
Winson Chung4a2afa32012-07-19 14:53:05 -0700952 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700953 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700954 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800955 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700956 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700957 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700958 // view after launching an app, as they may be depending on the UI to be static to
959 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700960 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700961 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800962 } else if (mOnResumeState == State.WIDGETS) {
963 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700964 }
965 mOnResumeState = State.NONE;
966
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700967 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -0700968 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
969 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -0700970
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800971 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700972 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700973 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700974 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400975 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700976 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700978 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200979 // We might have postponed some bind calls until onResume (see waitUntilResume) --
980 // execute them here
981 long startTimeCallbacks = 0;
982 if (DEBUG_RESUME_TIME) {
983 startTimeCallbacks = System.currentTimeMillis();
984 }
985
Michael Jurka1e2f4652013-07-08 18:03:46 -0700986 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
987 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200988 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700989 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200990 if (DEBUG_RESUME_TIME) {
991 Log.d(TAG, "Time spent processing callbacks in onResume: " +
992 (System.currentTimeMillis() - startTimeCallbacks));
993 }
Michael Jurka447bf842013-05-15 14:52:15 +0200994 }
Michael Jurka54554252013-08-01 12:52:23 +0200995 if (mOnResumeCallbacks.size() > 0) {
996 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
997 mOnResumeCallbacks.get(i).run();
998 }
999 mOnResumeCallbacks.clear();
1000 }
Winson Chunge4e50662012-01-23 14:45:13 -08001001
1002 // Reset the pressed state of icons that were locked in the press state while activities
1003 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001004 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001005 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001006 mWaitingForResume.setStayPressed(false);
1007 }
Winson Chung82963d52013-10-09 11:20:57 -07001008
Adam Cohen06dff352012-06-01 17:17:08 -07001009 // It is possible that widgets can receive updates while launcher is not in the foreground.
1010 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1011 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1012 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001013 if (!isWorkspaceLoading()) {
1014 getWorkspace().reinflateWidgetsIfNecessary();
1015 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001016 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001017
Michael Jurka447bf842013-05-15 14:52:15 +02001018 if (DEBUG_RESUME_TIME) {
1019 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1020 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001021
Adam Cohen4b66bf32015-09-18 12:15:19 -07001022 // We want to suppress callbacks about CustomContent being shown if we have just received
1023 // onNewIntent while the user was present within launcher. In that case, we post a call
1024 // to move the user to the main screen (which will occur after onResume). We don't want to
1025 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1026 // suppress here.
1027 if (mWorkspace.getCustomContentCallbacks() != null
1028 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001029 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001030 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001031 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1032 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001033 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001034 }
1035 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001036 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001037 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001038 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001039
Sunny Goyal756adbc2015-04-16 15:20:51 -07001040 if (!isWorkspaceLoading()) {
1041 // Process any items that were added while Launcher was away.
1042 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1043 }
Adam Cohen9211d422014-10-07 18:14:53 -07001044
1045 if (mLauncherCallbacks != null) {
1046 mLauncherCallbacks.onResume();
1047 }
Adam Cohen06dff352012-06-01 17:17:08 -07001048 }
1049
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001051 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001052 // Ensure that items added to Launcher are queued until Launcher returns
1053 InstallShortcutReceiver.enableInstallQueue();
1054
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001055 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001056 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001057 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001058 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001059
1060 // We call onHide() aggressively. The custom content callbacks should be able to
1061 // debounce excess onHide calls.
1062 if (mWorkspace.getCustomContentCallbacks() != null) {
1063 mWorkspace.getCustomContentCallbacks().onHide();
1064 }
Romain Guycbb89e42009-06-08 15:52:54 -07001065
Adam Cohen9211d422014-10-07 18:14:53 -07001066 if (mLauncherCallbacks != null) {
1067 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001068 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001069 }
1070
1071 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001072 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1073 // by a onResume or by scrolling otherwise.
1074 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001075
1076 // Custom content is completely hidden
1077 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001078
1079 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1080 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001081
1082 // Indicates whether the user is allowed to scroll away from the custom content.
1083 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001084 }
1085
Adam Cohenc2d6e892014-10-16 09:49:24 -07001086 public interface LauncherOverlay {
1087
1088 /**
1089 * Touch interaction leading to overscroll has begun
1090 */
1091 public void onScrollInteractionBegin();
1092
1093 /**
1094 * Touch interaction related to overscroll has ended
1095 */
1096 public void onScrollInteractionEnd();
1097
1098 /**
1099 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1100 * screen (or in the case of RTL, the rightmost screen).
1101 */
1102 public void onScrollChange(int progress, boolean rtl);
1103
1104 /**
1105 * Screen has stopped scrolling
1106 */
1107 public void onScrollSettled();
1108
1109 /**
1110 * This method can be called by the Launcher in order to force the LauncherOverlay
1111 * to exit fully immersive mode.
1112 */
1113 public void forceExitFullImmersion();
1114 }
1115
Jun Mukai8af0cd82015-05-12 12:32:12 -07001116 public interface LauncherSearchCallbacks {
1117 /**
1118 * Called when the search overlay is shown.
1119 */
1120 public void onSearchOverlayOpened();
1121
1122 /**
1123 * Called when the search overlay is dismissed.
1124 */
1125 public void onSearchOverlayClosed();
1126 }
1127
Adam Cohenc2d6e892014-10-16 09:49:24 -07001128 public interface LauncherOverlayCallbacks {
1129 /**
1130 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1131 * however it doesn't modify any state within the launcher.
1132 */
1133 public boolean canEnterFullImmersion();
1134
1135 /**
1136 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1137 * eg. by occupying the full screen and handling all touch events.
1138 *
1139 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1140 * case, Launcher will modify any necessary state and assumes the overlay is
1141 * handling all interaction. If false, the LauncherOverlay should cancel any
1142 *
1143 */
1144 public boolean enterFullImmersion();
1145
1146 /**
1147 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1148 * full control over UI and state.
1149 */
1150 public void exitFullImmersion();
1151 }
1152
1153 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1154
1155 @Override
1156 public boolean canEnterFullImmersion() {
1157 return mState == State.WORKSPACE;
1158 }
1159
1160 @Override
1161 public boolean enterFullImmersion() {
1162 if (mState == State.WORKSPACE) {
1163 // When fully immersed, disregard any touches which fall through.
1164 mDragLayer.setBlockTouch(true);
1165 return true;
1166 }
1167 return false;
1168 }
1169
1170 @Override
1171 public void exitFullImmersion() {
1172 mDragLayer.setBlockTouch(false);
1173 }
1174 }
1175
Jorim Jaggid017f882014-01-14 17:08:48 -08001176 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001177 if (mLauncherCallbacks != null) {
1178 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001179 } else {
1180 // On devices with a locked orientation, we will at least have the allow rotation
1181 // setting.
1182 return !Utilities.isRotationAllowedForDevice(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001183 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001184 }
1185
Adam Cohen9211d422014-10-07 18:14:53 -07001186 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001187 CustomContentCallbacks callbacks, String description) {
1188 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001189 }
1190
Adam Cohenedb40762013-07-18 16:45:45 -07001191 // The custom content needs to offset its content to account for the QSB
1192 public int getTopOffsetForCustomContent() {
1193 return mWorkspace.getPaddingTop();
1194 }
1195
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001196 @Override
1197 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001198 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001199 if (mModel.isCurrentCallbacks(this)) {
1200 mModel.stopLoader();
1201 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001202 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1203
Romain Guy13c2e7b2010-03-10 19:45:00 -08001204 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001205 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001206
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001207 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001208 @Override
1209 public void onWindowFocusChanged(boolean hasFocus) {
1210 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001211 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001212
1213 if (mLauncherCallbacks != null) {
1214 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1215 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001216 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001217
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 private boolean acceptFilter() {
1219 final InputMethodManager inputManager = (InputMethodManager)
1220 getSystemService(Context.INPUT_METHOD_SERVICE);
1221 return !inputManager.isFullscreenMode();
1222 }
1223
1224 @Override
1225 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001226 final int uniChar = event.getUnicodeChar();
1227 final boolean handled = super.onKeyDown(keyCode, event);
1228 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1229 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1231 keyCode, event);
1232 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001233 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001234 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001235 // showSearchDialog()
1236 // If there are multiple keystrokes before the search dialog takes focus,
1237 // onSearchRequested() will be called for every keystroke,
1238 // but it is idempotent, so it's fine.
1239 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001240 }
1241 }
1242
Joe Onorato8a9625e2010-01-28 15:55:35 -08001243 // Eat the long press event so the keyboard doesn't come up.
1244 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1245 return true;
1246 }
1247
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 return handled;
1249 }
1250
Winson46163472015-09-22 17:31:56 -07001251 @Override
1252 public boolean onKeyUp(int keyCode, KeyEvent event) {
1253 if (keyCode == KeyEvent.KEYCODE_MENU) {
1254 // Ignore the menu key if we are currently dragging or are on the custom content screen
1255 if (!isOnCustomContent() && !mDragController.isDragging()) {
1256 // Close any open folders
1257 closeFolder();
1258
1259 // Stop resizing any widgets
1260 mWorkspace.exitWidgetResizeMode();
1261
1262 // Show the overview mode if we are on the workspace
1263 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1264 !mWorkspace.isSwitchingState()) {
1265 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001266 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001267 }
1268 }
1269 return true;
1270 }
1271 return super.onKeyUp(keyCode, event);
1272 }
1273
Karl Rosaen138a0412009-04-23 19:00:21 -07001274 private String getTypedText() {
1275 return mDefaultKeySsb.toString();
1276 }
1277
1278 private void clearTypedText() {
1279 mDefaultKeySsb.clear();
1280 mDefaultKeySsb.clearSpans();
1281 Selection.setSelection(mDefaultKeySsb, 0);
1282 }
1283
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001285 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1286 * State
1287 */
1288 private static State intToState(int stateOrdinal) {
1289 State state = State.WORKSPACE;
1290 final State[] stateValues = State.values();
1291 for (int i = 0; i < stateValues.length; i++) {
1292 if (stateValues[i].ordinal() == stateOrdinal) {
1293 state = stateValues[i];
1294 break;
1295 }
1296 }
1297 return state;
1298 }
1299
1300 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 * Restores the previous state, if it exists.
1302 *
1303 * @param savedState The previous state.
1304 */
1305 private void restoreState(Bundle savedState) {
1306 if (savedState == null) {
1307 return;
1308 }
1309
Michael Jurka883f55b2010-10-21 15:47:14 -07001310 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001311 if (state == State.APPS || state == State.WIDGETS) {
1312 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001313 }
1314
Adam Cohen21cd0022013-10-09 18:57:02 -07001315 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1316 PagedView.INVALID_RESTORE_PAGE);
1317 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001318 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 }
1320
Sunny Goyal756cd262015-08-20 12:33:21 -07001321 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1322 if (itemValues != null) {
1323 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001324 AppWidgetProviderInfo info = savedState.getParcelable(
1325 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001326 mPendingAddWidgetInfo = info == null ?
1327 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1328
Adam Cohen4637b5a2013-11-04 18:21:24 -08001329 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001330 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 mRestoring = true;
1332 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333 }
1334
1335 /**
1336 * Finds all the views we need and configure them properly.
1337 */
1338 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001339 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001340
Craig Mautner360310b2012-10-26 15:13:08 -07001341 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001342 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001343 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1344 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001345 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001346 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001347
John Spurlock77e1f472013-09-11 10:09:51 -04001348 mLauncherView.setSystemUiVisibility(
1349 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001350 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351
Winson Chung4c98d922011-05-31 16:50:48 -07001352 // Setup the drag layer
1353 mDragLayer.setup(this, dragController);
1354
Winson Chung3d503fb2011-07-13 17:25:49 -07001355 // Setup the hotseat
1356 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1357 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001358 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001359 }
1360
Winsone9f27272015-10-13 10:47:51 -07001361 // Setup the overview panel
1362 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001363
Winson Chung4c98d922011-05-31 16:50:48 -07001364 // Setup the workspace
1365 mWorkspace.setHapticFeedbackEnabled(false);
1366 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001367 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001368 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001369
Tony Wickham34d2c912015-09-11 09:27:58 -07001370 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001371 mSearchDropTargetBar = (SearchDropTargetBar)
1372 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001373 // Get the app info bar
1374 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1375 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001376
Winson Chungef7f8742015-06-04 17:18:17 -07001377 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001378 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001379 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001380 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1381 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1382 } else {
1383 mAppsView.setSearchBarController(new DefaultAppSearchController());
1384 }
Craig Mautner360310b2012-10-26 15:13:08 -07001385
Winson Chung3d503fb2011-07-13 17:25:49 -07001386 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001387 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001388 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001389 dragController.setMoveTarget(mWorkspace);
1390 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001391 if (mSearchDropTargetBar != null) {
1392 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001393 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001394 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001395 if (mAppInfoDropTargetBar != null) {
1396 mAppInfoDropTargetBar.setup(this, dragController);
1397 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001398
Sunny Goyal322d5562015-06-25 19:35:49 -07001399 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1400 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001401 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402 }
1403
Winsone9f27272015-10-13 10:47:51 -07001404 private void setupOverviewPanel() {
1405 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1406
1407 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1408 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1409 @Override
1410 public boolean onLongClick(View v) {
1411 return v.performClick();
1412 }
1413 };
1414
1415 // Bind wallpaper button actions
1416 View wallpaperButton = findViewById(R.id.wallpaper_button);
1417 wallpaperButton.setOnClickListener(new OnClickListener() {
1418 @Override
1419 public void onClick(View view) {
1420 if (!mWorkspace.isSwitchingState()) {
1421 onClickWallpaperPicker(view);
1422 }
1423 }
1424 });
1425 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1426 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1427
1428 // Bind widget button actions
1429 mWidgetsButton = findViewById(R.id.widget_button);
1430 mWidgetsButton.setOnClickListener(new OnClickListener() {
1431 @Override
1432 public void onClick(View view) {
1433 if (!mWorkspace.isSwitchingState()) {
1434 onClickAddWidgetButton(view);
1435 }
1436 }
1437 });
1438 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1439 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1440
1441 // Bind settings actions
1442 View settingsButton = findViewById(R.id.settings_button);
1443 boolean hasSettings = hasSettings();
1444 if (hasSettings) {
1445 settingsButton.setOnClickListener(new OnClickListener() {
1446 @Override
1447 public void onClick(View view) {
1448 if (!mWorkspace.isSwitchingState()) {
1449 onClickSettingsButton(view);
1450 }
1451 }
1452 });
1453 settingsButton.setOnLongClickListener(performClickOnLongClick);
1454 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1455 } else {
1456 settingsButton.setVisibility(View.GONE);
1457 }
1458
1459 mOverviewPanel.setAlpha(0f);
1460 }
1461
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001463 * Sets the all apps button. This method is called from {@link Hotseat}.
1464 */
1465 public void setAllAppsButton(View allAppsButton) {
1466 mAllAppsButton = allAppsButton;
1467 }
1468
1469 public View getAllAppsButton() {
1470 return mAllAppsButton;
1471 }
1472
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001473 public View getWidgetsButton() {
1474 return mWidgetsButton;
1475 }
1476
Anjali Koppal5ad44842014-03-10 20:34:39 -07001477 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 * Creates a view representing a shortcut.
1479 *
1480 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001482 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001483 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 }
1485
1486 /**
1487 * Creates a view representing a shortcut inflated from the specified resource.
1488 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 * @param parent The group the shortcut belongs to.
1490 * @param info The data structure describing the shortcut.
1491 *
1492 * @return A View inflated from layoutResId.
1493 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001494 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001495 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001496 parent, false);
1497 favorite.applyFromShortcutInfo(info, mIconCache);
1498 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001500 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 return favorite;
1502 }
1503
1504 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 * Add a shortcut to the workspace.
1506 *
1507 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001509 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001510 int cellY) {
1511 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001512 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001513
Sunny Goyal5c97f512015-05-19 16:03:28 -07001514 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001515 if (info == null) {
1516 return;
1517 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001518 final View view = createShortcut(info);
1519
Sunny Goyal5c97f512015-05-19 16:03:28 -07001520 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001521 // First we check if we already know the exact location where we want to add this item.
1522 if (cellX >= 0 && cellY >= 0) {
1523 cellXY[0] = cellX;
1524 cellXY[1] = cellY;
1525 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001526
1527 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001528 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001529 true, null,null)) {
1530 return;
1531 }
1532 DragObject dragObject = new DragObject();
1533 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001534 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1535 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001536 return;
1537 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001538 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001539 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001540 }
1541
1542 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001543 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001544 return;
1545 }
1546
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001547 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548
1549 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001550 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001551 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 }
1553 }
1554
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001556 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001558 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 */
Adam Cohen091440a2015-03-18 14:16:05 -07001560 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001561 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1562
1563 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001564 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001565 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1566 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001567 }
Romain Guycbb89e42009-06-08 15:52:54 -07001568
Adam Cohen59400422014-03-05 18:07:04 -08001569 if (appWidgetInfo.isCustomWidget) {
1570 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001571 }
1572
Adam Cohen59400422014-03-05 18:07:04 -08001573 LauncherAppWidgetInfo launcherInfo;
1574 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1575 launcherInfo.spanX = info.spanX;
1576 launcherInfo.spanY = info.spanY;
1577 launcherInfo.minSpanX = info.minSpanX;
1578 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001579 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001580
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001582 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001583
1584 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001585 if (hostView == null) {
1586 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001587 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1588 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001589 } else {
1590 // The AppWidgetHostView has already been inflated and instantiated
1591 launcherInfo.hostView = hostView;
1592 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001593 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001594 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001596 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 }
Romain Guycbb89e42009-06-08 15:52:54 -07001598
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001599 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1600 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1601 item.hostView.setTag(item);
1602 item.onBindAppWidget(this);
1603
1604 item.hostView.setFocusable(true);
1605 item.hostView.setOnFocusChangeListener(mFocusHandler);
1606
1607 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1608 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1609
1610 if (!item.isCustomWidget()) {
1611 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1612 }
1613 }
1614
Adam Cohended9f8d2010-11-03 13:25:16 -07001615 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1616 @Override
1617 public void onReceive(Context context, Intent intent) {
1618 final String action = intent.getAction();
1619 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1620 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001621 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001622 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001623
Winson Chungc100e8e2011-08-09 16:02:43 -07001624 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001625 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001626 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001627 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001628 if (!showWorkspace(false)) {
1629 // If we are already on the workspace, then manually reset all apps
1630 mAppsView.reset();
1631 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001632 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001633 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1634 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001635 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001636 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1637 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001638 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001639 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1640 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1641 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001642 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001643 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1644 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001645 }
1646 }
1647 };
1648
1649 @Override
1650 public void onAttachedToWindow() {
1651 super.onAttachedToWindow();
1652
1653 // Listen for broadcasts related to user-presence
1654 final IntentFilter filter = new IntentFilter();
1655 filter.addAction(Intent.ACTION_SCREEN_OFF);
1656 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001657 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001658 if (ENABLE_DEBUG_INTENTS) {
1659 filter.addAction(DebugIntents.DELETE_DATABASE);
1660 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1661 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001662 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001663 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001664 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001665 mVisible = true;
1666 }
1667
1668 @Override
1669 public void onDetachedFromWindow() {
1670 super.onDetachedFromWindow();
1671 mVisible = false;
1672
Adam Cohend113e0c2010-11-11 10:48:05 -08001673 if (mAttached) {
1674 unregisterReceiver(mReceiver);
1675 mAttached = false;
1676 }
Winson Chungb745afb2015-03-02 11:51:23 -08001677 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001678 }
1679
1680 public void onWindowVisibilityChanged(int visibility) {
1681 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001682 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001683 // The following code used to be in onResume, but it turns out onResume is called when
1684 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1685 // is a more appropriate event to handle
1686 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001687 if (!mWorkspaceLoading) {
1688 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001689 // We want to let Launcher draw itself at least once before we force it to build
1690 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001691 // apps is nice and speedy.
1692 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001693 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001694 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001695 if (mStarted) return;
1696 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001697 // We delay the layer building a bit in order to give
1698 // other message processing a time to run. In particular
1699 // this avoids a delay in hiding the IME if it was
1700 // currently shown, because doing that may involve
1701 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001702 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001703 final ViewTreeObserver.OnDrawListener listener = this;
1704 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001705 public void run() {
1706 if (mWorkspace != null &&
1707 mWorkspace.getViewTreeObserver() != null) {
1708 mWorkspace.getViewTreeObserver().
1709 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001710 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001711 }
1712 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001713 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001714 }
1715 });
1716 }
1717 clearTypedText();
1718 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001719 }
1720
Adam Cohen091440a2015-03-18 14:16:05 -07001721 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001722 mHandler.removeMessages(ADVANCE_MSG);
1723 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1724 mHandler.sendMessageDelayed(msg, delay);
1725 mAutoAdvanceSentTime = System.currentTimeMillis();
1726 }
1727
Adam Cohen091440a2015-03-18 14:16:05 -07001728 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001729 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1730 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1731 mAutoAdvanceRunning = autoAdvanceRunning;
1732 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001733 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001734 sendAdvanceMessage(delay);
1735 } else {
1736 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001737 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001738 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1739 }
1740 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001741 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001742 }
1743 }
1744 }
1745
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001746 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1747
Adam Cohended9f8d2010-11-03 13:25:16 -07001748 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001749 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001750 if (msg.what == ADVANCE_MSG) {
1751 int i = 0;
1752 for (View key: mWidgetsToAdvance.keySet()) {
1753 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001754 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001755 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001756 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001757 public void run() {
1758 ((Advanceable) v).advance();
1759 }
1760 }, delay);
1761 }
1762 i++;
1763 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001764 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001765 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001766 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001768 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001769
Winsonc0b52fe2015-09-09 16:38:15 -07001770 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001771 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001772 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1773 if (v instanceof Advanceable) {
1774 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001775 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001776 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001777 }
1778 }
1779
Winsonc0b52fe2015-09-09 16:38:15 -07001780 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001781 if (mWidgetsToAdvance.containsKey(hostView)) {
1782 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001783 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001784 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001785 }
1786
Hyunyoung Song3f471442015-04-08 19:01:34 -07001787 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001788 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1789 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001790 }
1791
Winson Chunga6945242014-01-08 14:04:34 -08001792 public DragLayer getDragLayer() {
1793 return mDragLayer;
1794 }
1795
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001796 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001797 return mAppsView;
1798 }
1799
Hyunyoung Song3f471442015-04-08 19:01:34 -07001800 public WidgetsContainerView getWidgetsView() {
1801 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001802 }
1803
Winson Chunga6945242014-01-08 14:04:34 -08001804 public Workspace getWorkspace() {
1805 return mWorkspace;
1806 }
1807
1808 public Hotseat getHotseat() {
1809 return mHotseat;
1810 }
1811
Jorim Jaggid017f882014-01-14 17:08:48 -08001812 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001813 return mOverviewPanel;
1814 }
1815
Winson Chung006ee262015-08-03 14:40:11 -07001816 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001817 return mSearchDropTargetBar;
1818 }
1819
Tony Wickham34d2c912015-09-11 09:27:58 -07001820 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1821 return mAppInfoDropTargetBar;
1822 }
1823
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001824 public LauncherAppWidgetHost getAppWidgetHost() {
1825 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001826 }
Romain Guycbb89e42009-06-08 15:52:54 -07001827
Winson Chunga9abd0e2010-10-27 17:18:37 -07001828 public LauncherModel getModel() {
1829 return mModel;
1830 }
1831
Winson Chunga6945242014-01-08 14:04:34 -08001832 protected SharedPreferences getSharedPrefs() {
1833 return mSharedPrefs;
1834 }
1835
Adam Cohen2e6da152015-05-06 11:42:25 -07001836 public DeviceProfile getDeviceProfile() {
1837 return mDeviceProfile;
1838 }
1839
Bjorn Bringertc459e522013-06-07 19:36:01 +01001840 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001841 getWindow().closeAllPanels();
1842
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001843 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001844 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001845 }
1846
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 @Override
1848 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001849 long startTime = 0;
1850 if (DEBUG_RESUME_TIME) {
1851 startTime = System.currentTimeMillis();
1852 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001853 super.onNewIntent(intent);
1854
1855 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001856 Folder openFolder = mWorkspace.getOpenFolder();
1857 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1858 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1859 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1860 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1861 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001862 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001863 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001864
Adam Cohen6fecd412013-10-02 17:41:50 -07001865 if (mWorkspace == null) {
1866 // Can be cases where mWorkspace is null, this prevents a NPE
1867 return;
1868 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001869 // In all these cases, only animate if we're already on home
1870 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001871
Sunny Goyal935fca12015-10-13 10:19:01 -07001872 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001873 exitSpringLoadedDragMode();
1874
1875 // If we are already on home, then just animate back to the workspace,
1876 // otherwise, just wait until onResume to set the state back to Workspace
1877 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001878 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001879 } else {
1880 mOnResumeState = State.WORKSPACE;
1881 }
1882
1883 final View v = getWindow().peekDecorView();
1884 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001885 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001886 INPUT_METHOD_SERVICE);
1887 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1888 }
1889
Winson Chungb745afb2015-03-02 11:51:23 -08001890 // Reset the apps view
1891 if (!alreadyOnHome && mAppsView != null) {
1892 mAppsView.scrollToTop();
1893 }
1894
Hyunyoung Song3f471442015-04-08 19:01:34 -07001895 // Reset the widgets view
1896 if (!alreadyOnHome && mWidgetsView != null) {
1897 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001898 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001899
Adam Cohen9211d422014-10-07 18:14:53 -07001900 if (mLauncherCallbacks != null) {
1901 mLauncherCallbacks.onHomeIntent();
1902 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 }
Adam Cohened307df2013-10-02 09:37:31 -07001904
Adam Cohen9211d422014-10-07 18:14:53 -07001905 if (mLauncherCallbacks != null) {
1906 mLauncherCallbacks.onNewIntent(intent);
1907 }
Winson15f8b172015-08-19 11:02:39 -07001908
1909 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1910 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1911 // animation.
1912 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001913 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1914 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001915 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1916 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001917
1918 // We use this flag to suppress noisy callbacks above custom content state
1919 // from onResume.
1920 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001921 mWorkspace.post(new Runnable() {
1922 @Override
1923 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001924 if (mWorkspace != null) {
1925 mWorkspace.moveToDefaultScreen(true);
1926 }
Winson15f8b172015-08-19 11:02:39 -07001927 }
1928 });
1929 }
1930 }
1931
1932 if (DEBUG_RESUME_TIME) {
1933 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1934 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001935 }
1936
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001937 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001938 public void onRestoreInstanceState(Bundle state) {
1939 super.onRestoreInstanceState(state);
1940 for (int page: mSynchronouslyBoundPages) {
1941 mWorkspace.restoreInstanceStateForChild(page);
1942 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944
1945 @Override
1946 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001947 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001948 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1949 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001950 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001951 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952
Michael Jurka883f55b2010-10-21 15:47:14 -07001953 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal08442b82015-10-21 17:15:08 -07001954 Folder openFolder = mWorkspace.getOpenFolder();
1955 if (openFolder != null) {
1956 outState.putLong(RUNTIME_STATE_OPEN_FOLDER_ID, openFolder.mInfo.id);
1957 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958
Adam Cohendcd297f2013-06-18 13:13:40 -07001959 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001960 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001961 ContentValues itemValues = new ContentValues();
1962 mPendingAddInfo.writeToValues(itemValues);
1963 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001964 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001965 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 }
1967
Hyunyoung Song3f471442015-04-08 19:01:34 -07001968 // Save the current widgets tray?
1969 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001970
1971 if (mLauncherCallbacks != null) {
1972 mLauncherCallbacks.onSaveInstanceState(outState);
1973 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001974 }
1975
1976 @Override
1977 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001978 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001979
Winson Chunge7a03942011-08-05 15:05:12 -07001980 // Remove all pending runnables
1981 mHandler.removeMessages(ADVANCE_MSG);
1982 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001983 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001984
Winson Chungcd2b0142011-06-08 16:02:26 -07001985 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001986 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07001987
1988 // It's possible to receive onDestroy after a new Launcher activity has
1989 // been created. In this case, don't interfere with the new Launcher.
1990 if (mModel.isCurrentCallbacks(this)) {
1991 mModel.stopLoader();
1992 app.setLauncher(null);
1993 }
Winson Chungcd2b0142011-06-08 16:02:26 -07001994
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001996 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001998 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002000 mAppWidgetHost = null;
2001
2002 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003
2004 TextKeyListener.getInstance().release();
2005
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002006 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002007
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002008 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002009 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002010 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002011 mWorkspace = null;
2012 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002013
Michael Jurka2ecf9952012-06-18 12:52:28 -07002014 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002015
2016 if (mLauncherCallbacks != null) {
2017 mLauncherCallbacks.onDestroy();
2018 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 }
2020
Adam Cohena9cf38f2011-05-02 15:36:58 -07002021 public DragController getDragController() {
2022 return mDragController;
2023 }
2024
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 @Override
2026 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002027 onStartForResult(requestCode);
2028 super.startActivityForResult(intent, requestCode);
2029 }
2030
2031 @Override
2032 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2033 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2034 onStartForResult(requestCode);
2035 try {
2036 super.startIntentSenderForResult(intent, requestCode,
2037 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2038 } catch (IntentSender.SendIntentException e) {
2039 throw new ActivityNotFoundException();
2040 }
2041 }
2042
2043 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002044 if (requestCode >= 0) {
2045 setWaitingForResult(true);
2046 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 }
2048
Winson Chung70d72102011-08-12 11:24:35 -07002049 /**
2050 * Indicates that we want global search for this activity by setting the globalSearch
2051 * argument for {@link #startSearch} to true.
2052 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002054 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002056
Karl Rosaen138a0412009-04-23 19:00:21 -07002057 if (initialQuery == null) {
2058 // Use any text typed in the launcher as the initial query
2059 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 if (appSearchData == null) {
2062 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002063 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002064 }
Winson Chungadf0c182012-08-23 14:59:07 -07002065 Rect sourceBounds = new Rect();
2066 if (mSearchDropTargetBar != null) {
2067 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2068 }
Romain Guycbb89e42009-06-08 15:52:54 -07002069
Ian Parkinson047036e2014-09-01 15:40:53 +01002070 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002071 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002072 if (clearTextImmediately) {
2073 clearTypedText();
2074 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002075
2076 // We need to show the workspace after starting the search
2077 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002078 }
2079
Ian Parkinson047036e2014-09-01 15:40:53 +01002080 /**
2081 * Start a text search.
2082 *
2083 * @return {@code true} if the search will start immediately, so any further keypresses
2084 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2085 * to buffer keypresses.
2086 */
2087 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002088 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002089 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2090 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2091 sourceBounds);
2092 }
2093
Michael Jurkaa33411c2012-06-14 16:18:21 -07002094 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002095 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002096 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002097 }
2098
2099 /**
2100 * Starts the global search activity. This code is a copied from SearchManager
2101 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002102 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002103 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002104 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002105 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2106 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2107 if (globalSearchActivity == null) {
2108 Log.w(TAG, "No global search activity found.");
2109 return;
2110 }
2111 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2112 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2113 intent.setComponent(globalSearchActivity);
2114 // Make sure that we have a Bundle to put source in
2115 if (appSearchData == null) {
2116 appSearchData = new Bundle();
2117 } else {
2118 appSearchData = new Bundle(appSearchData);
2119 }
Adam Cohen9211d422014-10-07 18:14:53 -07002120 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002121 if (!appSearchData.containsKey("source")) {
2122 appSearchData.putString("source", getPackageName());
2123 }
2124 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2125 if (!TextUtils.isEmpty(initialQuery)) {
2126 intent.putExtra(SearchManager.QUERY, initialQuery);
2127 }
2128 if (selectInitialQuery) {
2129 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2130 }
2131 intent.setSourceBounds(sourceBounds);
2132 try {
2133 startActivity(intent);
2134 } catch (ActivityNotFoundException ex) {
2135 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2136 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137 }
2138
Winson Chungbedf9232015-07-10 12:38:30 -07002139 public void startSearchFromAllApps(View v, Intent searchIntent, String searchQuery) {
2140 if (mLauncherCallbacks != null && mLauncherCallbacks.startSearchFromAllApps(searchQuery)) {
2141 return;
2142 }
2143
2144 // If not handled, then just start the provided search intent
2145 startActivitySafely(v, searchIntent, null);
2146 }
2147
Yura4f93ec62014-02-04 14:15:21 +00002148 public boolean isOnCustomContent() {
2149 return mWorkspace.isOnOrMovingToCustomContent();
2150 }
2151
Winson Chung70d72102011-08-12 11:24:35 -07002152 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002153 public boolean onPrepareOptionsMenu(Menu menu) {
2154 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002155 if (mLauncherCallbacks != null) {
2156 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2157 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002158 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002159 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002160
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002161 @Override
2162 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002163 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002164 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002165 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002166 }
2167
Joe Onorato9c1289c2009-08-17 11:03:03 -04002168 public boolean isWorkspaceLocked() {
2169 return mWorkspaceLoading || mWaitingForResult;
2170 }
2171
Adam Cohen517a7f52014-03-01 12:12:59 -08002172 public boolean isWorkspaceLoading() {
2173 return mWorkspaceLoading;
2174 }
2175
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002176 private void setWorkspaceLoading(boolean value) {
2177 boolean isLocked = isWorkspaceLocked();
2178 mWorkspaceLoading = value;
2179 if (isLocked != isWorkspaceLocked()) {
2180 onWorkspaceLockedChanged();
2181 }
2182 }
2183
2184 private void setWaitingForResult(boolean value) {
2185 boolean isLocked = isWorkspaceLocked();
2186 mWaitingForResult = value;
2187 if (isLocked != isWorkspaceLocked()) {
2188 onWorkspaceLockedChanged();
2189 }
2190 }
2191
Adam Cohen9211d422014-10-07 18:14:53 -07002192 protected void onWorkspaceLockedChanged() {
2193 if (mLauncherCallbacks != null) {
2194 mLauncherCallbacks.onWorkspaceLockedChanged();
2195 }
2196 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002197
Michael Jurka0280c3b2010-09-17 15:00:07 -07002198 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002199 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002200 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002201 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2202 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002203 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002204 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002205
Tony Wickhama0628cc2015-10-14 15:23:04 -07002206 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002207 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002208 if (LOGD) {
2209 Log.d(TAG, "Adding widget from drop");
2210 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002211 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2212 }
2213
Sunny Goyale6b63a32015-01-16 16:14:29 -08002214 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002215 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2216 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002217 if (appWidgetInfo.configure != null) {
2218 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002219 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002220
Bjorn Bringert7984c942009-12-09 15:38:25 +00002221 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002222 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2223 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2224
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002225 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002226 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002227 Runnable onComplete = new Runnable() {
2228 @Override
2229 public void run() {
2230 // Exit spring loaded mode if necessary after adding the widget
2231 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2232 null);
2233 }
2234 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002235 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002236 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002237 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 }
2239 }
Romain Guycbb89e42009-06-08 15:52:54 -07002240
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002241 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002242 // Close any folders that may be open.
2243 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002244 mWorkspace.moveToCustomContentScreen(animate);
2245 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002246
2247 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2248 int[] cell, int spanX, int spanY) {
2249 switch (info.itemType) {
2250 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2251 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2252 int span[] = new int[2];
2253 span[0] = spanX;
2254 span[1] = spanY;
2255 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2256 container, screenId, cell, span);
2257 break;
2258 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2259 processShortcutFromDrop(info.componentName, container, screenId, cell);
2260 break;
2261 default:
2262 throw new IllegalStateException("Unknown item type: " + info.itemType);
2263 }
2264 }
2265
Adam Cohenfbba09b2011-07-18 21:43:05 -07002266 /**
2267 * Process a shortcut drop.
2268 *
2269 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002270 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002271 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002272 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002273 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2274 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002275 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002276 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002277 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002278
2279 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002280 mPendingAddInfo.cellX = cell[0];
2281 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002282 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002283
2284 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2285 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002286 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002287 }
2288
Adam Cohenfbba09b2011-07-18 21:43:05 -07002289 /**
2290 * Process a widget drop.
2291 *
2292 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002293 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002294 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002295 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002296 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2297 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002298 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002299 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002300 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002301 mPendingAddInfo.minSpanX = info.minSpanX;
2302 mPendingAddInfo.minSpanY = info.minSpanY;
2303
Adam Cohenfbba09b2011-07-18 21:43:05 -07002304 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002305 mPendingAddInfo.cellX = cell[0];
2306 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002307 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002308 if (span != null) {
2309 mPendingAddInfo.spanX = span[0];
2310 mPendingAddInfo.spanY = span[1];
2311 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002312
Adam Cohened66b2b2012-01-23 17:28:51 -08002313 AppWidgetHostView hostView = info.boundWidget;
2314 int appWidgetId;
2315 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002316 // In the case where we've prebound the widget, we remove it from the DragLayer
2317 if (LOGD) {
2318 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2319 }
2320 getDragLayer().removeView(hostView);
2321
Adam Cohened66b2b2012-01-23 17:28:51 -08002322 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002323 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002324
2325 // Clear the boundWidget so that it doesn't get destroyed.
2326 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002327 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002328 // In this case, we either need to start an activity to get permission to bind
2329 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002330 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002331 Bundle options = info.bindOptions;
2332
Sunny Goyalffe83f12014-08-14 17:39:34 -07002333 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2334 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002335 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002336 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002337 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002338 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002339 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2340 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2341 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002342 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2343 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002344 // TODO: we need to make sure that this accounts for the options bundle.
2345 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002346 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2347 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002348 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002349 }
2350
Adam Cohendcd297f2013-06-18 13:13:40 -07002351 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002352 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002353 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 folderInfo.title = getText(R.string.folder_name);
2355
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002356 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002357 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2358 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002359 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002360
2361 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002362 FolderIcon newFolder =
2363 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002364 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002365 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002366 // Force measure the new folder icon
2367 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2368 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002369 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 }
Romain Guycbb89e42009-06-08 15:52:54 -07002371
Winsonc0b52fe2015-09-09 16:38:15 -07002372 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002373 * Unbinds the view for the specified item, and removes the item and all its children.
2374 *
2375 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002376 * @param itemInfo the {@link ItemInfo} for this view.
2377 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002378 */
Winson2949fb52015-09-24 09:56:11 -07002379 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002380 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002381 // Remove the shortcut from the folder before removing it from launcher
Winson2949fb52015-09-24 09:56:11 -07002382 FolderInfo folderInfo = sFolders.get(itemInfo.container);
2383 if (folderInfo != null) {
2384 folderInfo.remove((ShortcutInfo) itemInfo);
Winsonfa56b3f2015-09-14 12:01:13 -07002385 } else {
2386 mWorkspace.removeWorkspaceItem(v);
2387 }
Winsonc0b52fe2015-09-09 16:38:15 -07002388 if (deleteFromDb) {
2389 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2390 }
2391 } else if (itemInfo instanceof FolderInfo) {
2392 final FolderInfo folderInfo = (FolderInfo) itemInfo;
2393 unbindFolder(folderInfo);
2394 mWorkspace.removeWorkspaceItem(v);
2395 if (deleteFromDb) {
2396 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2397 }
2398 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2399 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002400 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002401 removeWidgetToAutoAdvance(widgetInfo.hostView);
2402 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002403 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002404 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002405 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002406
Winsonc0b52fe2015-09-09 16:38:15 -07002407 } else {
2408 return false;
2409 }
2410 return true;
2411 }
2412
2413 /**
2414 * Unbinds any launcher references to the folder.
2415 */
2416 private void unbindFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002417 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002418 }
2419
Winsonc0b52fe2015-09-09 16:38:15 -07002420 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002421 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002422 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002423 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002424 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002425 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002426 // Deleting an app widget ID is a void call but writes to disk before returning
2427 // to the caller...
2428 new AsyncTask<Void, Void, Void>() {
2429 public Void doInBackground(Void ... args) {
2430 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2431 return null;
2432 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002433 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002434 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002435 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002436 }
2437
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002438 @Override
2439 public boolean dispatchKeyEvent(KeyEvent event) {
2440 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2441 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002442 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002443 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002444 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002445 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002446 dumpState();
2447 return true;
2448 }
2449 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002450 }
2451 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2452 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002453 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002454 return true;
2455 }
2456 }
2457
2458 return super.dispatchKeyEvent(event);
2459 }
2460
Joe Onorato88ec0992009-11-19 13:16:06 -08002461 @Override
2462 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002463 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2464 return;
2465 }
2466
Sunny Goyal45478022015-06-08 16:52:41 -07002467 if (mDragController.isDragging()) {
2468 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002469 return;
2470 }
2471
Winson Chungb745afb2015-03-02 11:51:23 -08002472 if (isAppsViewVisible()) {
2473 showWorkspace(true);
2474 } else if (isWidgetsViewVisible()) {
2475 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002476 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002477 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002478 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002479 Folder openFolder = mWorkspace.getOpenFolder();
2480 if (openFolder.isEditingName()) {
2481 openFolder.dismissEditingName();
2482 } else {
2483 closeFolder();
2484 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002485 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002486 mWorkspace.exitWidgetResizeMode();
2487
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002488 // Back button is a no-op here, but give at least some feedback for the button press
2489 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002490 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002491 }
2492
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002493 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002494 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002495 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002496 @Override
2497 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002498 if (mAppWidgetHost != null) {
2499 mAppWidgetHost.startListening();
2500 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002501
2502 // Recreate the QSB, as the widget has been reset.
2503 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002504 }
2505
2506 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002507 * Launches the intent referred by the clicked shortcut.
2508 *
2509 * @param v The view representing the clicked shortcut.
2510 */
2511 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002512 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2513 // view has detached (it's possible for this to happen if the view is removed mid touch).
2514 if (v.getWindowToken() == null) {
2515 return;
2516 }
2517
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002518 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002519 return;
2520 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002521
Adam Cohen1697b792013-09-17 19:08:21 -07002522 if (v instanceof Workspace) {
2523 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002524 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002525 }
2526 return;
2527 }
2528
2529 if (v instanceof CellLayout) {
2530 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002531 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2532 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002533 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002534 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002535 }
2536
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002537 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002538 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002539 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002540 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002541 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002542 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002543 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002544 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002545 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002546 } else if (tag instanceof AppInfo) {
2547 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002548 } else if (tag instanceof LauncherAppWidgetInfo) {
2549 if (v instanceof PendingAppWidgetHostView) {
2550 onClickPendingWidget((PendingAppWidgetHostView) v);
2551 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552 }
2553 }
2554
Sunny Goyal70660032015-05-14 00:07:08 -07002555 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002556 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002557 return false;
2558 }
2559
Michael Jurkaaf442092010-06-10 17:01:57 -07002560 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002561 * Event handler for the app widget view which has not fully restored.
2562 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002563 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002564 if (mIsSafeModeEnabled) {
2565 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2566 return;
2567 }
2568
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002569 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002570 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002571 int widgetId = info.appWidgetId;
2572 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2573 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002574 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2575 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002576 mPendingAddInfo.copyFrom(info);
2577 mPendingAddWidgetId = widgetId;
2578
Sunny Goyalffe83f12014-08-14 17:39:34 -07002579 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2580 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002581 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002582 } else if (info.installProgress < 0) {
2583 // The install has not been queued
2584 final String packageName = info.providerName.getPackageName();
2585 showBrokenAppInstallDialog(packageName,
2586 new DialogInterface.OnClickListener() {
2587 public void onClick(DialogInterface dialog, int id) {
2588 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2589 }
2590 });
2591 } else {
2592 // Download has started.
2593 final String packageName = info.providerName.getPackageName();
2594 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002595 }
2596 }
2597
2598 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002599 * Event handler for the "grid" button that appears on the home screen, which
2600 * enters all apps mode.
2601 *
2602 * @param v The view that was clicked.
2603 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002604 protected void onClickAllAppsButton(View v) {
2605 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002606 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002607 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002608 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002609
2610 if (mLauncherCallbacks != null) {
2611 mLauncherCallbacks.onClickAllAppsButton(v);
2612 }
Winson Chung76648c52015-07-10 14:33:23 -07002613 }
2614 }
2615
2616 protected void onLongClickAllAppsButton(View v) {
2617 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2618 if (!isAppsViewVisible()) {
2619 showAppsView(true /* animated */, false /* resetListToTop */,
2620 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002621 }
2622 }
2623
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002624 private void showBrokenAppInstallDialog(final String packageName,
2625 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002626 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002627 .setTitle(R.string.abandoned_promises_title)
2628 .setMessage(R.string.abandoned_promise_explanation)
2629 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2630 .setNeutralButton(R.string.abandoned_clean_this,
2631 new DialogInterface.OnClickListener() {
2632 public void onClick(DialogInterface dialog, int id) {
2633 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2634 mWorkspace.removeAbandonedPromise(packageName, user);
2635 }
2636 })
2637 .create().show();
2638 return;
2639 }
2640
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002641 /**
2642 * Event handler for an app shortcut click.
2643 *
2644 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2645 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002646 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002647 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2648 Object tag = v.getTag();
2649 if (!(tag instanceof ShortcutInfo)) {
2650 throw new IllegalArgumentException("Input must be a Shortcut");
2651 }
2652
2653 // Open shortcut
2654 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002655
2656 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002657 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2658 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002659 // Launch activity anyway, framework will tell the user why the app is suspended.
2660 } else {
2661 int error = R.string.activity_not_available;
2662 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2663 error = R.string.safemode_shortcut_error;
2664 }
2665 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2666 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002667 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002668 }
2669
Chris Wren40c5ed32014-06-24 18:24:23 -04002670 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002671 if ((v instanceof BubbleTextView)
2672 && shortcut.isPromise()
2673 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002674 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002675 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002676 new DialogInterface.OnClickListener() {
2677 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002678 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002679 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002680 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002681 return;
2682 }
2683
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002684 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002685 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002686
2687 if (mLauncherCallbacks != null) {
2688 mLauncherCallbacks.onClickAppShortcut(v);
2689 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002690 }
2691
Adam Cohen091440a2015-03-18 14:16:05 -07002692 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002693 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002694 final ShortcutInfo shortcut;
2695 final Intent intent;
2696 if (tag instanceof ShortcutInfo) {
2697 shortcut = (ShortcutInfo) tag;
2698 intent = shortcut.intent;
2699 int[] pos = new int[2];
2700 v.getLocationOnScreen(pos);
2701 intent.setSourceBounds(new Rect(pos[0], pos[1],
2702 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002703
Sunny Goyal508da152014-08-14 10:53:27 -07002704 } else if (tag instanceof AppInfo) {
2705 shortcut = null;
2706 intent = ((AppInfo) tag).intent;
2707 } else {
2708 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2709 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002710
2711 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002712 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002713
2714 if (success && v instanceof BubbleTextView) {
2715 mWaitingForResume = (BubbleTextView) v;
2716 mWaitingForResume.setStayPressed(true);
2717 }
2718 }
2719
2720 /**
2721 * Event handler for a folder icon click.
2722 *
2723 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2724 */
2725 protected void onClickFolderIcon(View v) {
2726 if (LOGD) Log.d(TAG, "onClickFolder");
2727 if (!(v instanceof FolderIcon)){
2728 throw new IllegalArgumentException("Input must be a FolderIcon");
2729 }
2730
2731 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002732 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002733 // Open the requested folder
Sunny Goyal08442b82015-10-21 17:15:08 -07002734 openFolder(folderIcon, true);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002735 }
Adam Cohen9211d422014-10-07 18:14:53 -07002736
2737 if (mLauncherCallbacks != null) {
2738 mLauncherCallbacks.onClickFolderIcon(v);
2739 }
Michael Jurka5130e402011-10-13 04:55:35 -07002740 }
2741
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002742 /**
2743 * Event handler for the (Add) Widgets button that appears after a long press
2744 * on the home screen.
2745 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002746 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002747 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002748 if (mIsSafeModeEnabled) {
2749 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2750 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002751 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002752 if (mLauncherCallbacks != null) {
2753 mLauncherCallbacks.onClickAddWidgetButton(view);
2754 }
Adam Cohen9211d422014-10-07 18:14:53 -07002755 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002756 }
2757
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002758 /**
2759 * Event handler for the wallpaper picker button that appears after a long press
2760 * on the home screen.
2761 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002762 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002763 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002764 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2765 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
2766 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
2767 .putExtra(WallpaperPickerActivity.EXTRA_WALLPAPER_OFFSET, offset),
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002768 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002769
2770 if (mLauncherCallbacks != null) {
2771 mLauncherCallbacks.onClickWallpaperPicker(v);
2772 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002773 }
2774
2775 /**
2776 * Event handler for a click on the settings button that appears after a long press
2777 * on the home screen.
2778 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002779 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002780 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002781 if (mLauncherCallbacks != null) {
2782 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002783 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002784 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002785 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002786 }
2787
Adam Cohen61f560d2013-09-30 15:58:20 -07002788 public View.OnTouchListener getHapticFeedbackTouchListener() {
2789 if (mHapticFeedbackTouchListener == null) {
2790 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002791 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002792 @Override
2793 public boolean onTouch(View v, MotionEvent event) {
2794 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2795 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2796 }
2797 return false;
2798 }
2799 };
2800 }
2801 return mHapticFeedbackTouchListener;
2802 }
2803
Adam Cohen9211d422014-10-07 18:14:53 -07002804 public void onDragStarted(View view) {
2805 if (isOnCustomContent()) {
2806 // Custom content screen doesn't participate in drag and drop. If on custom
2807 // content screen, move to default.
2808 moveWorkspaceToDefaultScreen();
2809 }
2810
2811 if (mLauncherCallbacks != null) {
2812 mLauncherCallbacks.onDragStarted(view);
2813 }
2814 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002815
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002816 /**
2817 * Called when the user stops interacting with the launcher.
2818 * This implies that the user is now on the homescreen and is not doing housekeeping.
2819 */
Adam Cohen9211d422014-10-07 18:14:53 -07002820 protected void onInteractionEnd() {
2821 if (mLauncherCallbacks != null) {
2822 mLauncherCallbacks.onInteractionEnd();
2823 }
2824 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002825
2826 /**
2827 * Called when the user starts interacting with the launcher.
2828 * The possible interactions are:
2829 * - open all apps
2830 * - reorder an app shortcut, or a widget
2831 * - open the overview mode.
2832 * This is a good time to stop doing things that only make sense
2833 * when the user is on the homescreen and not doing housekeeping.
2834 */
Adam Cohen9211d422014-10-07 18:14:53 -07002835 protected void onInteractionBegin() {
2836 if (mLauncherCallbacks != null) {
2837 mLauncherCallbacks.onInteractionBegin();
2838 }
2839 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002840
Winson Chungcd99cd32015-04-29 11:03:24 -07002841 /** Updates the interaction state. */
2842 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002843 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002844 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002845 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2846 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002847 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002848 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002849 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002850 onInteractionEnd();
2851 }
2852 }
2853
Kenny Guyf07af7b2014-07-31 11:39:16 +01002854 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002855 try {
2856 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002857 launcherApps.showAppDetailsForProfile(componentName, user);
2858 } catch (SecurityException e) {
2859 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2860 Log.e(TAG, "Launcher does not have permission to launch settings");
2861 } catch (ActivityNotFoundException e) {
2862 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2863 Log.e(TAG, "Unable to launch settings");
2864 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002865 }
2866
Michael Jurka1e2f4652013-07-08 18:03:46 -07002867 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002868 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2869 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002870 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002871 // System applications cannot be installed. For now, show a toast explaining that.
2872 // We may give them the option of disabling apps this way.
2873 int messageId = R.string.uninstall_system_app_text;
2874 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002875 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002876 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002877 String packageName = componentName.getPackageName();
2878 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002879 Intent intent = new Intent(
2880 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002881 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2882 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002883 if (user != null) {
2884 user.addToIntent(intent, Intent.EXTRA_USER);
2885 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002886 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002887 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002888 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002889 }
2890
Winson Chung8f1eff72015-05-28 17:33:40 -07002891 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002892 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002893 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002894 // Only launch using the new animation if the shortcut has not opted out (this is a
2895 // private contract between launcher and may be ignored in the future).
2896 boolean useLaunchAnimation = (v != null) &&
2897 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002898 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2899 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002900
Kenny Guy1317e2d2014-05-08 18:52:50 +01002901 UserHandleCompat user = null;
2902 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2903 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2904 user = userManager.getUserForSerialNumber(serialNumber);
2905 }
2906
2907 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002908 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002909 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002910 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002911 int left = 0, top = 0;
2912 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2913 if (v instanceof TextView) {
2914 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002915 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2916 if (icon != null) {
2917 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002918 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002919 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002920 width = bounds.width();
2921 height = bounds.height();
2922 }
2923 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002924 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2925 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002926 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002927 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002928 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002929 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002930 // On L devices, we use the device default slide-up transition.
2931 // On L MR1 devices, we a custom version of the slide-up transition which
2932 // doesn't have the delay present in the device default.
2933 opts = ActivityOptions.makeCustomAnimation(this,
2934 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002935 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002936 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002937 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002938
2939 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2940 // Could be launching some bookkeeping activity
2941 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002942 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002943 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002944 launcherApps.startActivityForProfile(intent.getComponent(), user,
2945 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002946 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002947 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002948 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002949 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2950 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2951 // corresponding permission. Show the appropriate permission prompt if that
2952 // is the case.
2953 if (intent.getComponent() == null
2954 && Intent.ACTION_CALL.equals(intent.getAction())
2955 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2956 PackageManager.PERMISSION_GRANTED) {
2957 // TODO: Rename sPendingAddItem to a generic name.
2958 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2959 0, (ItemInfo) tag);
2960 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2961 REQUEST_PERMISSION_CALL_PHONE);
2962 return false;
2963 }
2964 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002965 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002966 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002967 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002968 "or use the exported attribute for this activity. "
2969 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002970 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002971 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002972 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002973
Winson Chungbedf9232015-07-10 12:38:30 -07002974 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002975 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002976 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2977 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2978 return false;
2979 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002980 try {
2981 success = startActivity(v, intent, tag);
2982 } catch (ActivityNotFoundException e) {
2983 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2984 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2985 }
2986 return success;
2987 }
2988
Adam Cohen268c4752012-06-06 17:47:33 -07002989 /**
2990 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2991 * in the DragLayer in the exact absolute location of the original FolderIcon.
2992 */
2993 private void copyFolderIconToImage(FolderIcon fi) {
2994 final int width = fi.getMeasuredWidth();
2995 final int height = fi.getMeasuredHeight();
2996
2997 // Lazy load ImageView, Bitmap and Canvas
2998 if (mFolderIconImageView == null) {
2999 mFolderIconImageView = new ImageView(this);
3000 }
3001 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3002 mFolderIconBitmap.getHeight() != height) {
3003 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3004 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3005 }
3006
3007 DragLayer.LayoutParams lp;
3008 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3009 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3010 } else {
3011 lp = new DragLayer.LayoutParams(width, height);
3012 }
3013
Adam Cohen307fe232012-08-16 17:55:58 -07003014 // The layout from which the folder is being opened may be scaled, adjust the starting
3015 // view size by this scale factor.
3016 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003017 lp.customPosition = true;
3018 lp.x = mRectForFolderAnimation.left;
3019 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003020 lp.width = (int) (scale * width);
3021 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003022
3023 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3024 fi.draw(mFolderIconCanvas);
3025 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003026 if (fi.getFolder() != null) {
3027 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3028 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003029 }
Adam Cohen268c4752012-06-06 17:47:33 -07003030 // Just in case this image view is still in the drag layer from a previous animation,
3031 // we remove it and re-add it.
3032 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3033 mDragLayer.removeView(mFolderIconImageView);
3034 }
3035 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003036 if (fi.getFolder() != null) {
3037 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003038 }
Adam Cohen268c4752012-06-06 17:47:33 -07003039 }
3040
Sunny Goyal08442b82015-10-21 17:15:08 -07003041 private void growAndFadeOutFolderIcon(FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003042 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003043 FolderInfo info = (FolderInfo) fi.getTag();
3044 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3045 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003046 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3047 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003048 }
3049
Adam Cohen268c4752012-06-06 17:47:33 -07003050 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3051 copyFolderIconToImage(fi);
3052 fi.setVisibility(View.INVISIBLE);
3053
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003054 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3055 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003056 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003057 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3058 }
3059 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003060 oa.start();
Sunny Goyal08442b82015-10-21 17:15:08 -07003061 if (!animate) {
Tony Wickham112ac952015-11-12 12:31:50 -08003062 oa.end();
3063 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003064 }
3065
Sunny Goyal935fca12015-10-13 10:19:01 -07003066 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003067 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003068 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003069
Adam Cohen268c4752012-06-06 17:47:33 -07003070 // We remove and re-draw the FolderIcon in-case it has changed
3071 mDragLayer.removeView(mFolderIconImageView);
3072 copyFolderIconToImage(fi);
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003073 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003074 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003075 oa.addListener(new AnimatorListenerAdapter() {
3076 @Override
3077 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003078 if (cl != null) {
3079 cl.clearFolderLeaveBehind();
3080 // Remove the ImageView copy of the FolderIcon and make the original visible.
3081 mDragLayer.removeView(mFolderIconImageView);
3082 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003083 }
3084 }
3085 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003086 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003087 if (!animate) {
3088 oa.end();
3089 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003090 }
3091
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003092 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003093 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003094 * is animated relative to the specified View. If the View is null, no animation
3095 * is played.
3096 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003097 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003098 */
Sunny Goyal08442b82015-10-21 17:15:08 -07003099 public void openFolder(FolderIcon folderIcon, boolean animate) {
3100 animate &= !Utilities.isPowerSaverOn(this);
3101
Adam Cohenfb91f302012-06-11 15:45:18 -07003102 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003103 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3104 if (openFolder != null && openFolder != folder) {
3105 // Close any open folder before opening a folder.
3106 closeFolder();
3107 }
3108
Adam Cohena9cf38f2011-05-02 15:36:58 -07003109 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003110
Adam Cohena9cf38f2011-05-02 15:36:58 -07003111 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003112
Sunny Goyalf4066152015-04-15 09:42:19 -07003113 // While the folder is open, the position of the icon cannot change.
3114 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3115
Adam Cohen4554ee12011-08-03 16:13:21 -07003116 // Just verify that the folder hasn't already been added to the DragLayer.
3117 // There was a one-off crash where the folder had a parent already.
3118 if (folder.getParent() == null) {
3119 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003120 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003121 } else {
3122 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3123 folder.getParent() + ").");
3124 }
Sunny Goyal08442b82015-10-21 17:15:08 -07003125 if (animate) {
3126 folder.animateOpen();
3127 } else {
3128 folder.open();
3129 }
3130 growAndFadeOutFolderIcon(folderIcon, animate);
Winson Chung83ca4802013-04-12 15:10:52 -07003131
3132 // Notify the accessibility manager that this folder "window" has appeared and occluded
3133 // the workspace items
3134 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3135 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003136 }
3137
3138 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003139 closeFolder(true);
3140 }
3141
3142 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003143 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003144 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003145 if (folder.isEditingName()) {
3146 folder.dismissEditingName();
3147 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003148 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003149 }
3150 }
3151
Sunny Goyal935fca12015-10-13 10:19:01 -07003152 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003153 animate &= !Utilities.isPowerSaverOn(this);
3154
Adam Cohen4554ee12011-08-03 16:13:21 -07003155 folder.getInfo().opened = false;
3156
3157 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3158 if (parent != null) {
3159 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003160 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003161 if (fi != null) {
3162 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3163 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003164 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003165 if (animate) {
3166 folder.animateClosed();
3167 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003168 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003169 }
Winson Chung83ca4802013-04-12 15:10:52 -07003170
Sunny Goyal935fca12015-10-13 10:19:01 -07003171 // Notify the accessibility manager that this folder "window" has disappeared and no
3172 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003173 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003174 }
3175
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003176 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003177 if (!isDraggingEnabled()) return false;
3178 if (isWorkspaceLocked()) return false;
3179 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003180
Winson Chung76648c52015-07-10 14:33:23 -07003181 if (v == mAllAppsButton) {
3182 onLongClickAllAppsButton(v);
3183 return true;
3184 }
3185
Adam Cohen1697b792013-09-17 19:08:21 -07003186 if (v instanceof Workspace) {
3187 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003188 if (!mWorkspace.isTouchActive()) {
3189 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003190 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3191 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3192 return true;
3193 } else {
3194 return false;
3195 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003196 } else {
3197 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003198 }
Adam Cohen1697b792013-09-17 19:08:21 -07003199 }
3200
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003201 CellLayout.CellInfo longClickCellInfo = null;
3202 View itemUnderLongClick = null;
3203 if (v.getTag() instanceof ItemInfo) {
3204 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003205 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003206 itemUnderLongClick = longClickCellInfo.cell;
3207 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003208 }
3209
Winson Chung3d503fb2011-07-13 17:25:49 -07003210 // The hotseat touch handling does not go through Workspace, and we always allow long press
3211 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003212 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003213 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003214 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003215 // User long pressed on empty space
3216 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3217 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003218 if (mWorkspace.isInOverviewMode()) {
3219 mWorkspace.startReordering(v);
3220 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003221 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003223 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003224 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3225 mHotseat.getOrderInHotseat(
3226 longClickCellInfo.cellX,
3227 longClickCellInfo.cellY));
3228 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003229 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003230 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003231 }
3232 }
3233 }
3234 return true;
3235 }
3236
Winson Chung3d503fb2011-07-13 17:25:49 -07003237 boolean isHotseatLayout(View layout) {
3238 return mHotseat != null && layout != null &&
3239 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3240 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003241
Winson Chung3d503fb2011-07-13 17:25:49 -07003242 /**
3243 * Returns the CellLayout of the specified container at the specified screen.
3244 */
Sunny Goyal92820592015-03-02 11:31:35 -08003245 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003246 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3247 if (mHotseat != null) {
3248 return mHotseat.getLayout();
3249 } else {
3250 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003251 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003252 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003253 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003254 }
3255 }
3256
Winson Chungb745afb2015-03-02 11:51:23 -08003257 /**
3258 * For overridden classes.
3259 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003260 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003261 return isAppsViewVisible();
3262 }
3263
3264 public boolean isAppsViewVisible() {
3265 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3266 }
3267
3268 public boolean isWidgetsViewVisible() {
3269 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003270 }
3271
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003272 private void setWorkspaceBackground(int background) {
3273 switch (background) {
3274 case WORKSPACE_BACKGROUND_TRANSPARENT:
3275 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3276 break;
3277 case WORKSPACE_BACKGROUND_BLACK:
3278 getWindow().setBackgroundDrawable(null);
3279 break;
3280 default:
3281 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3282 }
Craig Mautner360310b2012-10-26 15:13:08 -07003283 }
3284
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003285 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003286 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3287 int curflags = getWindow().getAttributes().flags
3288 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3289 if (wpflags != curflags) {
3290 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3291 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003292 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003293 }
3294
Michael Jurkae326f182011-11-21 14:05:46 -08003295 @Override
3296 public void onTrimMemory(int level) {
3297 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003298 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3299 // The widget preview db can result in holding onto over
3300 // 3MB of memory for caching which isn't necessary.
3301 SQLiteDatabase.releaseMemory();
3302
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003303 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003304 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003305 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003306 if (mLauncherCallbacks != null) {
3307 mLauncherCallbacks.onTrimMemory(level);
3308 }
Michael Jurkae326f182011-11-21 14:05:46 -08003309 }
3310
Winson5c6bdbb2015-09-03 11:36:19 -07003311 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003312 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003313 }
3314
Winson5c6bdbb2015-09-03 11:36:19 -07003315 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003316 boolean changed = mState != State.WORKSPACE ||
3317 mWorkspace.getState() != Workspace.State.NORMAL;
3318 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003319 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003320 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003321 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003322
Michael Jurkab3e22d92011-10-31 15:58:33 -07003323 // Set focus to the AppsCustomize button
3324 if (mAllAppsButton != null) {
3325 mAllAppsButton.requestFocus();
3326 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003327 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003328
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003329 // Change the state *after* we've called all the transition code
3330 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003331
Winson Chung5fb63472011-02-02 17:03:37 -08003332 // Resume the auto-advance of widgets
3333 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003334 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003335
Winson Chung0f785722015-04-08 10:27:49 -07003336 if (changed) {
3337 // Send an accessibility event to announce the context change
3338 getWindow().getDecorView()
3339 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003340 }
Winson5c6bdbb2015-09-03 11:36:19 -07003341 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003342 }
3343
Winsone9f27272015-10-13 10:47:51 -07003344 /**
3345 * Shows the overview button.
3346 */
Adam Cohened307df2013-10-02 09:37:31 -07003347 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003348 showOverviewMode(animated, false);
3349 }
3350
3351 /**
3352 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3353 * onto one of the overview panel buttons.
3354 */
3355 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3356 Runnable postAnimRunnable = null;
3357 if (requestButtonFocus) {
3358 postAnimRunnable = new Runnable() {
3359 @Override
3360 public void run() {
3361 // Hitting the menu button when in touch mode does not trigger touch mode to
3362 // be disabled, so if requested, force focus on one of the overview panel
3363 // buttons.
3364 mOverviewPanel.requestFocusFromTouch();
3365 }
3366 };
3367 }
Adam Cohened307df2013-10-02 09:37:31 -07003368 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003369 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003370 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003371 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003372 }
3373
Winson Chungb745afb2015-03-02 11:51:23 -08003374 /**
3375 * Shows the apps view.
3376 */
Winson Chung76648c52015-07-10 14:33:23 -07003377 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3378 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003379 if (resetListToTop) {
3380 mAppsView.scrollToTop();
3381 }
Winson Chung4ac30062015-05-08 17:34:17 -07003382 if (updatePredictedApps) {
3383 tryAndUpdatePredictedApps();
3384 }
Winson Chung76648c52015-07-10 14:33:23 -07003385 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003386 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003387
Winson Chungb745afb2015-03-02 11:51:23 -08003388 /**
3389 * Shows the widgets view.
3390 */
3391 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003392 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003393 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003394 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003395 }
Winson Chung76648c52015-07-10 14:33:23 -07003396 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003397
3398 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003399 @Override
3400 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003401 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003402 }
3403 });
Winson Chungb745afb2015-03-02 11:51:23 -08003404 }
3405
3406 /**
3407 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003408 *
3409 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003410 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003411 // TODO: calling method should use the return value so that when {@code false} is returned
3412 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003413 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003414 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3415 mState != State.WIDGETS_SPRING_LOADED) {
3416 return false;
3417 }
3418 if (toState != State.APPS && toState != State.WIDGETS) {
3419 return false;
3420 }
Winson Chungb745afb2015-03-02 11:51:23 -08003421
3422 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003423 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3424 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003425 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003426 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003427 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003428
Michael Jurkab3e22d92011-10-31 15:58:33 -07003429 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003430 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003431
3432 // Pause the auto-advance of widgets until we are out of AllApps
3433 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003434 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003435 closeFolder();
3436
3437 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003438 getWindow().getDecorView()
3439 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003440 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003441 }
3442
Winson Chungcd99cd32015-04-29 11:03:24 -07003443 /**
3444 * Updates the workspace and interaction state on state change, and return the animation to this
3445 * new state.
3446 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003447 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003448 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003449 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003450 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003451 updateInteraction(fromState, toState);
3452 return anim;
3453 }
3454
Jun Mukaif0033da2015-08-04 18:34:30 -07003455 public void onLauncherClingShown() {
3456 // When a launcher cling appears, it should cover the underlying layers, so their focus
3457 // should be blocked.
3458 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3459 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3460 }
3461 }
3462
3463 public void onLauncherClingDismissed() {
3464 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3465 }
3466
Hyunyoung Song3f471442015-04-08 19:01:34 -07003467 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003468 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003469 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003470 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003471 }
Winson Chungb745afb2015-03-02 11:51:23 -08003472
Winson Chung006ee262015-08-03 14:40:11 -07003473 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003474 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003475 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003476
3477 if (isAppsViewVisible()) {
3478 mState = State.APPS_SPRING_LOADED;
3479 } else if (isWidgetsViewVisible()) {
3480 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003481 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003482 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003483 } else {
3484 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003485 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003486 }
Adam Cohen7777d962011-08-18 18:58:38 -07003487
Hyunyoung Song3f471442015-04-08 19:01:34 -07003488 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003489 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003490 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003491
Winson Chunge7a03942011-08-05 15:05:12 -07003492 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003493 @Override
3494 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003495 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003496 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3497 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003498 // Before we show workspace, hide all apps again because
3499 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3500 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003501 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003502 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003503 } else {
3504 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003505 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003506 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003507 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003508 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003509
Tony Wickhame0c33232016-02-08 11:37:04 -08003510 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003511 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3512 || mState == State.WIDGETS_SPRING_LOADED;
3513 }
3514
Michael Jurkad3ef3062010-11-23 16:23:58 -08003515 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003516 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003517 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003518 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003519 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003520 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003521 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3522 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003523 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003524 }
3525
Winson Chung4ac30062015-05-08 17:34:17 -07003526 /**
3527 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3528 * resumed.
3529 */
3530 private void tryAndUpdatePredictedApps() {
3531 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003532 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003533 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003534 mAppsView.setPredictedApps(apps);
3535 }
3536 }
3537 }
3538
Michael Jurkab3e22d92011-10-31 15:58:33 -07003539 void lockAllApps() {
3540 // TODO
3541 }
3542
3543 void unlockAllApps() {
3544 // TODO
3545 }
3546
Sunny Goyal594d76d2014-11-06 10:12:54 -08003547 protected void disableVoiceButtonProxy(boolean disable) {
3548 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003549 }
3550
Winsonf768d932015-09-25 16:12:35 -07003551 public boolean launcherCallbacksProvidesSearch() {
3552 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3553 }
3554
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003555 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003556 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003557 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003558 }
3559
Adam Cohen24ce0b32014-01-14 16:18:14 -08003560 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003561 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3562 if (searchProvider == null) {
3563 return null;
3564 }
3565
3566 Bundle opts = new Bundle();
3567 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003568 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003569
Tony Wickham3a3517f2015-10-06 11:27:04 -07003570 // Determine the min and max dimensions of the widget.
3571 LauncherAppState app = LauncherAppState.getInstance();
3572 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3573 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3574 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003575 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3576 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003577 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003578 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003579 int minWidth = maxWidth;
3580 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003581 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3582 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3583 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3584 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3585 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003586 }
3587 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3588 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3589 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3590 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003591 if (LOGD) {
3592 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3593 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3594 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003595
Tony Wickham775455c2015-10-16 09:49:32 -07003596 if (mLauncherCallbacks != null) {
3597 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3598 }
3599
Sunny Goyalf7258242015-10-19 16:59:07 -07003600 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003601 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003602 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003603 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003604 || (widgetInfo == null)
3605 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003606 // A valid widget is not already bound.
3607 if (widgetId > -1) {
3608 mAppWidgetHost.deleteAppWidgetId(widgetId);
3609 widgetId = -1;
3610 }
3611
3612 // Try to bind a new widget
3613 widgetId = mAppWidgetHost.allocateAppWidgetId();
3614
3615 if (!AppWidgetManagerCompat.getInstance(this)
3616 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3617 mAppWidgetHost.deleteAppWidgetId(widgetId);
3618 widgetId = -1;
3619 }
3620
Sunny Goyalf7258242015-10-19 16:59:07 -07003621 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003622 .putInt(QSB_WIDGET_ID, widgetId)
3623 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003624 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003625 }
3626
Sunny Goyal8d595092015-07-06 12:22:14 -07003627 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003628 if (widgetId != -1) {
3629 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003630 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003631 mQsb.updateAppWidgetOptions(opts);
3632 mQsb.setPadding(0, 0, 0, 0);
3633 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003634 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003635 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003636 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003637 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003638 }
3639
Sunny Goyal22235bc2015-04-03 09:23:43 -07003640 private void reinflateQSBIfNecessary() {
3641 if (mQsb instanceof LauncherAppWidgetHostView &&
3642 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3643 mSearchDropTargetBar.removeView(mQsb);
3644 mQsb = null;
3645 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3646 }
3647 }
3648
Michael Jurkad7c28052012-04-27 15:43:36 -07003649 @Override
3650 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003651 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003652 final List<CharSequence> text = event.getText();
3653 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003654 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003655 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003656 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003657 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003658 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003659 } else if (mWorkspace != null) {
3660 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003661 } else {
3662 text.add(getString(R.string.all_apps_home_button_label));
3663 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003664 return result;
3665 }
3666
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003667 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003668 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003669 */
Adam Cohen091440a2015-03-18 14:16:05 -07003670 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003671 @Override
3672 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003673 closeSystemDialogs();
3674 }
3675 }
3676
3677 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003678 * If the activity is currently paused, signal that we need to run the passed Runnable
3679 * in onResume.
3680 *
3681 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003682 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3683 * wrong when we're not running, and if the activity comes back to what the configuration was
3684 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003685 *
3686 * Implementation of the method from LauncherModel.Callbacks.
3687 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003688 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003689 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003690 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003691 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003692 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003693 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003694 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003695 }
3696 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003697 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003698 return true;
3699 } else {
3700 return false;
3701 }
3702 }
3703
Michael Jurkac402cd92013-05-20 15:49:32 +02003704 private boolean waitUntilResume(Runnable run) {
3705 return waitUntilResume(run, false);
3706 }
3707
Michael Jurka1e2f4652013-07-08 18:03:46 -07003708 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003709 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003710 }
3711
Michael Jurka7607c2f2013-04-03 14:33:19 -07003712 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003713 * If the activity is currently paused, signal that we need to re-run the loader
3714 * in onResume.
3715 *
3716 * This needs to be called from incoming places where resources might have been loaded
3717 * while we are paused. That is becaues the Configuration might be wrong
3718 * when we're not running, and if it comes back to what it was when we
3719 * were paused, we are not restarted.
3720 *
3721 * Implementation of the method from LauncherModel.Callbacks.
3722 *
3723 * @return true if we are currently paused. The caller might be able to
3724 * skip some work in that case since we will come back again.
3725 */
3726 public boolean setLoadOnResume() {
3727 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003728 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003729 mOnResumeNeedsLoad = true;
3730 return true;
3731 } else {
3732 return false;
3733 }
3734 }
3735
3736 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003738 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003739 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003740 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003741 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003742 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003743 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003744 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003745 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003746
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003748 * Clear any pending bind callbacks. This is called when is loader is planning to
3749 * perform a full rebind from scratch.
3750 */
3751 @Override
3752 public void clearPendingBinds() {
3753 mBindOnResumeCallbacks.clear();
3754 if (mPendingExecutor != null) {
3755 mPendingExecutor.markCompleted();
3756 mPendingExecutor = null;
3757 }
3758 }
3759
3760 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003761 * Refreshes the shortcuts shown on the workspace.
3762 *
3763 * Implementation of the method from LauncherModel.Callbacks.
3764 */
3765 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003766 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003767
Winson Chungd64d1762013-08-20 14:37:16 -07003768 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003769 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003770 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003771
Michael Jurka05bf644e2011-11-30 20:28:53 -08003772 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003773 if (mHotseat != null) {
3774 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003775 }
3776 }
3777
Adam Cohendcd297f2013-06-18 13:13:40 -07003778 @Override
3779 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003780 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003781
Adam Cohen5084cba2013-09-03 12:01:16 -07003782 // If there are no screens, we need to have an empty screen
3783 if (orderedScreenIds.size() == 0) {
3784 mWorkspace.addExtraEmptyScreen();
3785 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003786
3787 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003788 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003789 if (hasCustomContentToLeft()) {
3790 mWorkspace.createCustomContentContainer();
3791 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003792 }
Winson Chung64359a52013-07-08 17:17:08 -07003793 }
3794
3795 @Override
3796 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003797 int count = orderedScreenIds.size();
3798 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003799 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003800 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003801 }
3802
Winson Chungd64d1762013-08-20 14:37:16 -07003803 public void bindAppsAdded(final ArrayList<Long> newScreens,
3804 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003805 final ArrayList<ItemInfo> addAnimated,
3806 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003807 Runnable r = new Runnable() {
3808 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003809 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003810 }
3811 };
3812 if (waitUntilResume(r)) {
3813 return;
3814 }
3815
Winson Chungd64d1762013-08-20 14:37:16 -07003816 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003817 if (newScreens != null) {
3818 bindAddScreens(newScreens);
3819 }
Winson Chungd64d1762013-08-20 14:37:16 -07003820
3821 // We add the items without animation on non-visible pages, and with
3822 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003823 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003824 bindItems(addNotAnimated, 0,
3825 addNotAnimated.size(), false);
3826 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003827 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003828 bindItems(addAnimated, 0,
3829 addAnimated.size(), true);
3830 }
Winson Chungc58497e2013-09-03 17:48:37 -07003831
Winson Chung87412982013-10-03 18:34:14 -07003832 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003833 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003834
Winson Chungb745afb2015-03-02 11:51:23 -08003835 if (addedApps != null && mAppsView != null) {
3836 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003837 }
Winson Chungd64d1762013-08-20 14:37:16 -07003838 }
3839
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003840 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003841 * Bind the items start-end from the list.
3842 *
3843 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003844 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003845 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003846 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3847 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003848 Runnable r = new Runnable() {
3849 public void run() {
3850 bindItems(shortcuts, start, end, forceAnimateIcons);
3851 }
3852 };
3853 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003854 return;
3855 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003856
Winson Chungf0c6ae02012-03-21 16:10:31 -07003857 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003858 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3859 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003860 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003861 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003862 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003863 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003864 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003865
3866 // Short circuit if we are loading dock items for a configuration which has no dock
3867 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3868 mHotseat == null) {
3869 continue;
3870 }
3871
Sunny Goyal639e9062015-08-19 19:17:06 -07003872 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003873 switch (item.itemType) {
3874 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3875 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003876 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003877 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003878
Winson Chung64359a52013-07-08 17:17:08 -07003879 /*
3880 * TODO: FIX collision case
3881 */
Winson Chungce376632013-07-11 16:12:41 -07003882 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3883 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3884 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003885 View v = cl.getChildAt(item.cellX, item.cellY);
3886 Object tag = v.getTag();
3887 String desc = "Collision while binding workspace item: " + item
3888 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003889 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003890 throw (new RuntimeException(desc));
3891 } else {
3892 Log.d(TAG, desc);
3893 }
Winson Chungce376632013-07-11 16:12:41 -07003894 }
Winson Chung64359a52013-07-08 17:17:08 -07003895 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003896 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003897 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003898 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003899 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003900 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003901 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003902 default:
3903 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003904 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003905
3906 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3907 item.cellY, 1, 1);
3908 if (animateIcons) {
3909 // Animate all the applications up now
3910 view.setAlpha(0f);
3911 view.setScaleX(0f);
3912 view.setScaleY(0f);
3913 bounceAnims.add(createNewAppBounceAnimation(view, i));
3914 newShortcutsScreenId = item.screenId;
3915 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003916 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003917
Winson Chung997a9232013-07-24 15:33:46 -07003918 if (animateIcons) {
3919 // Animate to the correct page
3920 if (newShortcutsScreenId > -1) {
3921 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003922 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003923 final Runnable startBounceAnimRunnable = new Runnable() {
3924 public void run() {
3925 anim.playTogether(bounceAnims);
3926 anim.start();
3927 }
3928 };
Winson Chung997a9232013-07-24 15:33:46 -07003929 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003930 // We post the animation slightly delayed to prevent slowdowns
3931 // when we are loading right after we return to launcher.
3932 mWorkspace.postDelayed(new Runnable() {
3933 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003934 if (mWorkspace != null) {
3935 mWorkspace.snapToPage(newScreenIndex);
3936 mWorkspace.postDelayed(startBounceAnimRunnable,
3937 NEW_APPS_ANIMATION_DELAY);
3938 }
Winson Chung94d67682013-09-25 16:29:40 -07003939 }
3940 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003941 } else {
3942 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003943 }
3944 }
Winson Chung64359a52013-07-08 17:17:08 -07003945 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003946 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003947 }
3948
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 /**
3950 * Implementation of the method from LauncherModel.Callbacks.
3951 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003952 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003953 Runnable r = new Runnable() {
3954 public void run() {
3955 bindFolders(folders);
3956 }
3957 };
3958 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003959 return;
3960 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003961 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003963
3964 /**
3965 * Add the views for a widget to the workspace.
3966 *
3967 * Implementation of the method from LauncherModel.Callbacks.
3968 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003969 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003970 Runnable r = new Runnable() {
3971 public void run() {
3972 bindAppWidget(item);
3973 }
3974 };
3975 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003976 return;
3977 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003978
Daniel Sandler843e8602010-06-07 14:59:01 -04003979 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3980 if (DEBUG_WIDGETS) {
3981 Log.d(TAG, "bindAppWidget: " + item);
3982 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003983 final Workspace workspace = mWorkspace;
3984
Adam Cohen59400422014-03-05 18:07:04 -08003985 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00003986 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08003987
Sunny Goyal9b4b0812014-10-08 10:47:28 -07003988 if (!mIsSafeModeEnabled
3989 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003990 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
3991
Sunny Goyalff572272014-07-23 13:58:07 -07003992 if (appWidgetInfo == null) {
3993 if (DEBUG_WIDGETS) {
3994 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3995 + " belongs to component " + item.providerName
3996 + ", as the povider is null");
3997 }
3998 LauncherModel.deleteItemFromDatabase(this, item);
3999 return;
4000 }
Sunny Goyalff572272014-07-23 13:58:07 -07004001
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004002 // If we do not have a valid id, try to bind an id.
4003 if ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0) {
4004 // Note: This assumes that the id remap broadcast is received before this step.
4005 // If that is not the case, the id remap will be ignored and user may see the
4006 // click to setup view.
4007 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
4008 pendingInfo.spanX = item.spanX;
4009 pendingInfo.spanY = item.spanY;
4010 pendingInfo.minSpanX = item.minSpanX;
4011 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08004012 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004013
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004014 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4015 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4016 newWidgetId, appWidgetInfo, options);
4017
4018 // TODO consider showing a permission dialog when the widget is clicked.
4019 if (!success) {
4020 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4021 if (DEBUG_WIDGETS) {
4022 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4023 + " belongs to component " + item.providerName
4024 + ", as the launcher is unable to bing a new widget id");
4025 }
4026 LauncherModel.deleteItemFromDatabase(this, item);
4027 return;
Sunny Goyalff572272014-07-23 13:58:07 -07004028 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004029
4030 item.appWidgetId = newWidgetId;
4031
4032 // If the widget has a configure activity, it is still needs to set it up, otherwise
4033 // the widget is ready to go.
4034 item.restoreStatus = (appWidgetInfo.configure == null)
4035 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4036 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4037
4038 LauncherModel.updateItemInDatabase(this, item);
4039 } else if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0)
4040 && (appWidgetInfo.configure == null)) {
4041 // If the ID is already valid, verify if we need to configure or not.
4042 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4043 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004044 }
Sunny Goyalff572272014-07-23 13:58:07 -07004045 }
4046
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004047 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004048 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004049 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004050 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4051 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004052 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004053
Sunny Goyal56c73602015-09-25 12:55:01 -07004054 // Verify that we own the widget
4055 AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4056 if (info == null || appWidgetInfo == null ||
4057 !info.provider.equals(appWidgetInfo.provider)) {
Hyunyoung Song70264a92016-02-03 15:28:47 -08004058 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId + " info=" + info
4059 + " appWidgetInfo=" + appWidgetInfo);
Sunny Goyal56c73602015-09-25 12:55:01 -07004060 deleteWidgetInfo(item);
4061 return;
4062 }
4063
Sunny Goyal651077b2014-06-30 14:15:31 -07004064 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004065 item.minSpanX = appWidgetInfo.minSpanX;
4066 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal651077b2014-06-30 14:15:31 -07004067 } else {
4068 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004069 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4070 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004071 view.updateIcon(mIconCache);
4072 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004073 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004074 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004075 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004076
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07004077 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004078 workspace.requestLayout();
4079
Daniel Sandler843e8602010-06-07 14:59:01 -04004080 if (DEBUG_WIDGETS) {
4081 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4082 + (SystemClock.uptimeMillis()-start) + "ms");
4083 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004084 }
4085
Sunny Goyalff572272014-07-23 13:58:07 -07004086 /**
4087 * Restores a pending widget.
4088 *
4089 * @param appWidgetId The app widget id
4090 * @param cellInfo The position on screen where to create the widget.
4091 */
4092 private void completeRestoreAppWidget(final int appWidgetId) {
4093 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4094 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4095 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4096 return;
4097 }
4098
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004099 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004100 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4101
4102 mWorkspace.reinflateWidgetsIfNecessary();
4103 LauncherModel.updateItemInDatabase(this, info);
4104 }
4105
Adam Cohen1462de32012-07-24 22:34:36 -07004106 public void onPageBoundSynchronously(int page) {
4107 mSynchronouslyBoundPages.add(page);
4108 }
4109
Sunny Goyal527c7d32015-08-28 15:19:36 -07004110 @Override
4111 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4112 if (mPendingExecutor != null) {
4113 mPendingExecutor.markCompleted();
4114 }
4115 mPendingExecutor = executor;
4116 executor.attachTo(this);
4117 }
4118
4119 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4120 if (mPendingExecutor == executor) {
4121 mPendingExecutor = null;
4122 }
4123 }
4124
Joe Onorato9c1289c2009-08-17 11:03:03 -04004125 /**
4126 * Callback saying that there aren't any more items to bind.
4127 *
4128 * Implementation of the method from LauncherModel.Callbacks.
4129 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004130 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004131 Runnable r = new Runnable() {
4132 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004133 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004134 }
4135 };
4136 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004137 return;
4138 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 if (mSavedState != null) {
4140 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004141 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004142 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004143
4144 long folderId = mSavedState.getLong(RUNTIME_STATE_OPEN_FOLDER_ID);
4145 if (folderId != 0) {
4146 View view = mWorkspace.getHomescreenIconByItemId(folderId);
4147 if (view instanceof FolderIcon) {
4148 FolderIcon icon = (FolderIcon) view;
4149 FolderInfo info = icon.getFolderInfo();
4150 long currentScreenId = mWorkspace.getScreenIdForPageIndex(
4151 mWorkspace.getNextPage());
4152 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
4153 || info.screenId == currentScreenId) {
4154 // We can show the folder
4155 openFolder(icon, false);
4156 } else {
4157 Launcher.addDumpLog(TAG, "Saved state contains folder " + info +
4158 " but current screen is " + currentScreenId);
4159 }
4160 }
4161 }
4162
Joe Onorato9c1289c2009-08-17 11:03:03 -04004163 mSavedState = null;
4164 }
4165
Adam Cohen1462de32012-07-24 22:34:36 -07004166 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004167
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004168 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004169 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004170
4171 // If we received the result of any pending adds while the loader was running (e.g. the
4172 // widget configuration forced an orientation change), process them now.
4173 if (sPendingAddItem != null) {
4174 final long screenId = completeAdd(sPendingAddItem);
4175
4176 // TODO: this moves the user to the page where the pending item was added. Ideally,
4177 // the screen would be guaranteed to exist after bind, and the page would be set through
4178 // the workspace restore process.
4179 mWorkspace.post(new Runnable() {
4180 @Override
4181 public void run() {
4182 mWorkspace.snapToScreenId(screenId);
4183 }
4184 });
4185 sPendingAddItem = null;
4186 }
4187
Sunny Goyal756adbc2015-04-16 15:20:51 -07004188 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004189
4190 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004191 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004192 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004193 }
4194
Adam Cohen3ed316a2014-07-23 18:21:20 -07004195 private void sendLoadingCompleteBroadcastIfNecessary() {
4196 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4197 String permission =
4198 getResources().getString(R.string.receive_first_load_broadcast_permission);
4199 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4200 sendBroadcast(intent, permission);
4201 SharedPreferences.Editor editor = mSharedPrefs.edit();
4202 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4203 editor.apply();
4204 }
4205 }
4206
Winson Chunga0b7e862013-09-05 16:03:15 -07004207 public boolean isAllAppsButtonRank(int rank) {
4208 if (mHotseat != null) {
4209 return mHotseat.isAllAppsButtonRank(rank);
4210 }
4211 return false;
4212 }
4213
Winson Chunga2413752012-04-03 14:22:34 -07004214 private boolean canRunNewAppsAnimation() {
4215 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004216 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4217 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004218 }
4219
Winson Chungc9168342013-06-26 14:54:55 -07004220 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004221 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004222 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4223 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004224 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004225 return bounceAnim;
4226 }
4227
Adam Cohen27772732013-11-11 14:00:56 +00004228 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004229 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004230 }
4231
Tony Wickham3a3517f2015-10-06 11:27:04 -07004232 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004233 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004234 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004235 }
4236
Tony Wickham55616cd2015-09-23 14:55:17 -07004237 public int getSearchBarHeight() {
4238 if (mLauncherCallbacks != null) {
4239 return mLauncherCallbacks.getSearchBarHeight();
4240 }
4241 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4242 }
4243
Winson Chung88fa7412015-08-03 14:25:28 -07004244 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004245 if (mSearchDropTargetBar == null) {
4246 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004247 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004248 if (mQsb != null) {
4249 mSearchDropTargetBar.removeView(mQsb);
4250 mQsb = null;
4251 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004252 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004253 }
4254
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004255 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004256 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4257 * multiple calls to bind the same list.)
4258 */
4259 @Thunk ArrayList<AppInfo> mTmpAppsList;
4260 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4261 public void run() {
4262 bindAllApplications(mTmpAppsList);
4263 mTmpAppsList = null;
4264 }
4265 };
4266
4267 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004268 * Add the icons for all apps.
4269 *
4270 * Implementation of the method from LauncherModel.Callbacks.
4271 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004272 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004273 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4274 mTmpAppsList = apps;
4275 return;
4276 }
4277
Winson Chungb745afb2015-03-02 11:51:23 -08004278 if (mAppsView != null) {
4279 mAppsView.setApps(apps);
4280 }
Adam Cohen9211d422014-10-07 18:14:53 -07004281 if (mLauncherCallbacks != null) {
4282 mLauncherCallbacks.bindAllApplications(apps);
4283 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004284 }
4285
4286 /**
4287 * A package was updated.
4288 *
4289 * Implementation of the method from LauncherModel.Callbacks.
4290 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004291 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004292 Runnable r = new Runnable() {
4293 public void run() {
4294 bindAppsUpdated(apps);
4295 }
4296 };
4297 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004298 return;
4299 }
4300
Winson Chungb745afb2015-03-02 11:51:23 -08004301 if (mAppsView != null) {
4302 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004303 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004304 }
4305
Sunny Goyal4390ace2014-10-13 11:33:11 -07004306 @Override
4307 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4308 Runnable r = new Runnable() {
4309 public void run() {
4310 bindWidgetsRestored(widgets);
4311 }
4312 };
4313 if (waitUntilResume(r)) {
4314 return;
4315 }
4316 mWorkspace.widgetsRestored(widgets);
4317 }
4318
Joe Onorato9c1289c2009-08-17 11:03:03 -04004319 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004320 * Some shortcuts were updated in the background.
4321 *
4322 * Implementation of the method from LauncherModel.Callbacks.
4323 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004324 @Override
4325 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4326 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004327 Runnable r = new Runnable() {
4328 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004329 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004330 }
4331 };
4332 if (waitUntilResume(r)) {
4333 return;
4334 }
4335
Sunny Goyal4390ace2014-10-13 11:33:11 -07004336 if (!updated.isEmpty()) {
4337 mWorkspace.updateShortcuts(updated);
4338 }
4339
4340 if (!removed.isEmpty()) {
4341 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4342 for (ShortcutInfo si : removed) {
4343 removedComponents.add(si.getTargetComponent());
4344 }
4345 mWorkspace.removeItemsByComponentName(removedComponents, user);
4346 // Notify the drag controller
4347 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004348 }
4349 }
4350
4351 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004352 * Update the state of a package, typically related to install state.
4353 *
4354 * Implementation of the method from LauncherModel.Callbacks.
4355 */
Sunny Goyale755d462014-07-22 13:48:29 -07004356 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004357 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4358 Runnable r = new Runnable() {
4359 public void run() {
4360 bindRestoreItemsChange(updates);
4361 }
4362 };
4363 if (waitUntilResume(r)) {
4364 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004365 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004366
Sunny Goyal756adbc2015-04-16 15:20:51 -07004367 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004368 }
4369
4370 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004371 * A package was uninstalled. We take both the super set of packageNames
4372 * in addition to specific applications to remove, the reason being that
4373 * this can be called when a package is updated as well. In that scenario,
4374 * we only remove specific components from the workspace, where as
4375 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004376 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004377 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004378 * Implementation of the method from LauncherModel.Callbacks.
4379 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004380 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004381 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004382 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004383 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004384 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004385 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004386 }
Winson Chungd64d1762013-08-20 14:37:16 -07004387 };
4388 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004389 return;
4390 }
4391
Sunny Goyal1a745e82014-10-02 15:58:31 -07004392 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004393 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4394 for (AppInfo info : appInfos) {
4395 removedComponents.add(info.componentName);
4396 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004397 if (!packageNames.isEmpty()) {
4398 mWorkspace.removeItemsByPackageName(packageNames, user);
4399 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004400 if (!removedComponents.isEmpty()) {
4401 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004402 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004403 // Notify the drag controller
4404 mDragController.onAppsRemoved(packageNames, removedComponents);
4405
Sunny Goyal1a745e82014-10-02 15:58:31 -07004406 } else {
4407 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004408 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004409
Winson Chungdf95eb12013-10-16 14:57:07 -07004410 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004411 if (mAppsView != null) {
4412 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004413 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004414 }
Joe Onoratobe386092009-11-17 17:32:16 -08004415
Michael Jurkac402cd92013-05-20 15:49:32 +02004416 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004417 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004418 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004419 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004420 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004421
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004422 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004423 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004424 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004425 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004426 return;
4427 }
4428
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004429 if (mWidgetsView != null && model != null) {
4430 mWidgetsView.addWidgets(model);
4431 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004432 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004433 }
4434
Winson Chung400438b2011-01-16 17:53:48 -08004435 private int mapConfigurationOriActivityInfoOri(int configOri) {
4436 final Display d = getWindowManager().getDefaultDisplay();
4437 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4438 switch (d.getRotation()) {
4439 case Surface.ROTATION_0:
4440 case Surface.ROTATION_180:
4441 // We are currently in the same basic orientation as the natural orientation
4442 naturalOri = configOri;
4443 break;
4444 case Surface.ROTATION_90:
4445 case Surface.ROTATION_270:
4446 // We are currently in the other basic orientation to the natural orientation
4447 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4448 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4449 break;
4450 }
4451
4452 int[] oriMap = {
4453 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4454 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4455 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4456 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4457 };
4458 // Since the map starts at portrait, we need to offset if this device's natural orientation
4459 // is landscape.
4460 int indexOffset = 0;
4461 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4462 indexOffset = 1;
4463 }
4464 return oriMap[(d.getRotation() + indexOffset) % 4];
4465 }
Adam Cohen446e9402011-09-15 18:21:21 -07004466
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004467 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004468 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004469 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004470 if (Utilities.ATLEAST_JB_MR2) {
4471 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4472 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004473 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4474 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004475 }
Winson Chung4b919f82012-05-01 10:44:08 -07004476 }
4477 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004478
Winson Chung4b919f82012-05-01 10:44:08 -07004479 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004480 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004481 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004482 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004483 } else {
4484 mHandler.postDelayed(new Runnable() {
4485 public void run() {
4486 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4487 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004488 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004489 }
Winson Chung4b919f82012-05-01 10:44:08 -07004490 }
Winson Chung400438b2011-01-16 17:53:48 -08004491 }
4492
Winson Chunge43a1e72014-01-15 10:33:02 -08004493 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004494 if (mLauncherCallbacks != null) {
4495 return mLauncherCallbacks.isLauncherPreinstalled();
4496 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004497 PackageManager pm = getPackageManager();
4498 try {
4499 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4500 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4501 return true;
4502 } else {
4503 return false;
4504 }
4505 } catch (NameNotFoundException e) {
4506 e.printStackTrace();
4507 return false;
4508 }
4509 }
4510
Adam Cohenea90f832014-05-21 15:03:34 -07004511 /**
4512 * This method indicates whether or not we should suggest default wallpaper dimensions
4513 * when our wallpaper cropper was not yet used to set a wallpaper.
4514 */
4515 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004516 if (mLauncherCallbacks != null) {
4517 return mLauncherCallbacks.overrideWallpaperDimensions();
4518 }
Adam Cohenea90f832014-05-21 15:03:34 -07004519 return true;
4520 }
4521
Adam Cohen432609a2014-03-13 17:03:22 -07004522 /**
4523 * To be overridden by subclasses to indicate that there is an activity to launch
4524 * before showing the standard launcher experience.
4525 */
4526 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004527 if (mLauncherCallbacks != null) {
4528 return mLauncherCallbacks.hasFirstRunActivity();
4529 }
Adam Cohen432609a2014-03-13 17:03:22 -07004530 return false;
4531 }
4532
4533 /**
4534 * To be overridden by subclasses to launch any first run activity
4535 */
4536 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004537 if (mLauncherCallbacks != null) {
4538 return mLauncherCallbacks.getFirstRunActivity();
4539 }
Adam Cohen432609a2014-03-13 17:03:22 -07004540 return null;
4541 }
4542
Winson Chunga6945242014-01-08 14:04:34 -08004543 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004544 return !ActivityManager.isRunningInTestHarness() &&
4545 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004546 }
4547
Adam Cohen4a9423d2014-03-28 14:22:31 -07004548 protected boolean hasRunFirstRunActivity() {
4549 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4550 }
4551
Adam Cohen432609a2014-03-13 17:03:22 -07004552 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004553 if (shouldRunFirstRunActivity() &&
4554 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004555 Intent firstRunIntent = getFirstRunActivity();
4556 if (firstRunIntent != null) {
4557 startActivity(firstRunIntent);
4558 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004559 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004560 }
4561 }
Adam Cohen432609a2014-03-13 17:03:22 -07004562 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004563 }
4564
4565 private void markFirstRunActivityShown() {
4566 SharedPreferences.Editor editor = mSharedPrefs.edit();
4567 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4568 editor.apply();
4569 }
4570
Adam Cohen432609a2014-03-13 17:03:22 -07004571 /**
4572 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4573 * screen that must be displayed and dismissed.
4574 */
4575 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004576 if (mLauncherCallbacks != null) {
4577 return mLauncherCallbacks.hasDismissableIntroScreen();
4578 }
Adam Cohen432609a2014-03-13 17:03:22 -07004579 return false;
4580 }
4581
4582 /**
4583 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4584 */
4585 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004586 if (mLauncherCallbacks != null) {
4587 return mLauncherCallbacks.getIntroScreen();
4588 }
Adam Cohen432609a2014-03-13 17:03:22 -07004589 return null;
4590 }
4591
4592 /**
4593 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4594 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4595 */
4596 private boolean shouldShowIntroScreen() {
4597 return hasDismissableIntroScreen() &&
4598 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4599 }
4600
4601 protected void showIntroScreen() {
4602 View introScreen = getIntroScreen();
4603 changeWallpaperVisiblity(false);
4604 if (introScreen != null) {
4605 mDragLayer.showOverlayView(introScreen);
4606 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004607 if (mLauncherOverlayContainer != null) {
4608 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4609 }
Adam Cohen432609a2014-03-13 17:03:22 -07004610 }
4611
4612 public void dismissIntroScreen() {
4613 markIntroScreenDismissed();
4614 if (showFirstRunActivity()) {
4615 // We delay hiding the intro view until the first run activity is showing. This
4616 // avoids a blip.
4617 mWorkspace.postDelayed(new Runnable() {
4618 @Override
4619 public void run() {
4620 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004621 if (mLauncherOverlayContainer != null) {
4622 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4623 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004624 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004625 }
4626 }, ACTIVITY_START_DELAY);
4627 } else {
4628 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004629 if (mLauncherOverlayContainer != null) {
4630 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4631 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004632 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004633 }
4634 changeWallpaperVisiblity(true);
4635 }
4636
4637 private void markIntroScreenDismissed() {
4638 SharedPreferences.Editor editor = mSharedPrefs.edit();
4639 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4640 editor.apply();
4641 }
4642
Adam Cohen091440a2015-03-18 14:16:05 -07004643 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004644 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4645 // on the device, then we always show the first run cling experience (or if there is no
4646 // launcher2). Otherwise, we prompt the user upon started for migration
4647 LauncherClings launcherClings = new LauncherClings(this);
4648 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004649 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004650 if (mModel.canMigrateFromOldLauncherDb(this)) {
4651 launcherClings.showMigrationCling();
4652 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004653 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004654 }
4655 }
4656 }
4657
Winson Chunga6945242014-01-08 14:04:34 -08004658 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004659 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4660 if (mHotseat != null) mHotseat.setAlpha(1f);
4661 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004662 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4663 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004664 }
4665
4666 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004667 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4668 if (mHotseat != null) mHotseat.setAlpha(0f);
4669 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004670 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4671 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004672 }
4673
Winson Chung5ffd51d2015-06-25 11:36:50 -07004674 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004675 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004676 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004677 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004678 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004679 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004680 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4681 if (userHandle != null) {
4682 user = UserHandleCompat.fromUser(userHandle);
4683 }
4684 }
4685 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004686 }
4687
4688 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004689 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004690 if (user == null) {
4691 user = UserHandleCompat.myUserHandle();
4692 }
4693
4694 // Called from search suggestion, add the profile extra to the intent to ensure that we
4695 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004696 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004697 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004698 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004699 return null;
4700 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004701 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004702 }
4703
Winson Chung5ffd51d2015-06-25 11:36:50 -07004704 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004705 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4706 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004707 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004708 UserHandleCompat.myUserHandle());
4709 }
4710
Winson Chung5ffd51d2015-06-25 11:36:50 -07004711 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004712 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4713 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004714 mWorkspace.onExternalDragStartedWithItem(dragView);
4715 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004716 }
4717
Winson Chung5ffd51d2015-06-25 11:36:50 -07004718 protected void moveWorkspaceToDefaultScreen() {
4719 mWorkspace.moveToDefaultScreen(false);
4720 }
4721
Anjali Koppalf5d29132014-02-28 13:33:27 -08004722 @Override
4723 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004724 if (mLauncherCallbacks != null) {
4725 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4726 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004727 }
4728
Winson Chung80baf5a2010-08-09 16:03:15 -07004729 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004730 * Returns a FastBitmapDrawable with the icon, accurately sized.
4731 */
4732 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4733 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4734 d.setFilterBitmap(true);
4735 resizeIconDrawable(d);
4736 return d;
4737 }
4738
4739 /**
4740 * Resizes an icon drawable to the correct icon size.
4741 */
Winson5fbe0742015-09-30 15:33:00 -07004742 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004743 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004744 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004745 }
4746
4747 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004748 * Prints out out state for debugging.
4749 */
4750 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004751 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004752 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004753 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4754 Log.d(TAG, "mRestoring=" + mRestoring);
4755 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004756 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004757 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004758 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004759
Daniel Sandler325dc232013-06-05 22:57:57 -04004760 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004761 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004762
4763 @Override
4764 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4765 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004766 // Dump workspace
4767 writer.println(prefix + "Workspace Items");
4768 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4769 writer.println(prefix + " Homescreen " + i);
4770
4771 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4772 for (int j = 0; j < layout.getChildCount(); j++) {
4773 Object tag = layout.getChildAt(j).getTag();
4774 if (tag != null) {
4775 writer.println(prefix + " " + tag.toString());
4776 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004777 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004778 }
Sunny Goyala1365452015-10-01 15:46:24 -07004779
4780 writer.println(prefix + " Hotseat");
4781 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4782 for (int j = 0; j < layout.getChildCount(); j++) {
4783 Object tag = layout.getChildAt(j).getTag();
4784 if (tag != null) {
4785 writer.println(prefix + " " + tag.toString());
4786 }
4787 }
4788
4789 synchronized (sDumpLogs) {
4790 writer.println();
4791 writer.println(prefix + "Debug logs");
4792 for (String log : sDumpLogs) {
4793 writer.println(prefix + " " + log);
4794 }
4795 }
4796
Adam Cohen9211d422014-10-07 18:14:53 -07004797 if (mLauncherCallbacks != null) {
4798 mLauncherCallbacks.dump(prefix, fd, writer, args);
4799 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004800 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004801
Sunny Goyala1365452015-10-01 15:46:24 -07004802 public static void addDumpLog(String tag, String log) {
4803 Log.d(tag, log);
4804 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004805 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004806 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004807 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004808 }
4809
Adam Cohen59400422014-03-05 18:07:04 -08004810 public static CustomAppWidget getCustomAppWidget(String name) {
4811 return sCustomAppWidgets.get(name);
4812 }
4813
4814 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4815 return sCustomAppWidgets;
4816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004817}
Michael Jurka2763be32011-02-24 11:19:57 -08004818
Dan Sandlerd5024042014-01-09 15:01:33 -05004819interface DebugIntents {
4820 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4821 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004822}