blob: 5939878a95c25d79a309d6d6f7b0f13d9fbf86af [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;
85import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080087import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070088import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080092import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070094
Sunny Goyal651077b2014-06-30 14:15:31 -070095import com.android.launcher3.DropTarget.DragObject;
96import com.android.launcher3.PagedView.PageSwitchListener;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070097import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080098import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -070099import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100100import com.android.launcher3.compat.LauncherActivityInfoCompat;
101import com.android.launcher3.compat.LauncherAppsCompat;
102import com.android.launcher3.compat.UserHandleCompat;
103import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800104import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700105import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700106import com.android.launcher3.dragndrop.DragController;
107import com.android.launcher3.dragndrop.DragLayer;
108import com.android.launcher3.dragndrop.DragView;
Sunny Goyal26119432016-02-18 22:09:23 +0000109import com.android.launcher3.folder.Folder;
110import com.android.launcher3.folder.FolderIcon;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800111import com.android.launcher3.logging.UserEventLogger;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700112import com.android.launcher3.model.WidgetsModel;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800113import com.android.launcher3.logging.LoggerUtils;
114import com.android.launcher3.userevent.nano.LauncherLogProto;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700115import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700116import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700117import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700118import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700119import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700120import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700121import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700122import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700123
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700124import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700125import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700126import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700128import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800129import java.util.Collections;
Adam Cohen4caf2982013-08-20 18:54:31 -0700130import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700132import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700133import java.util.List;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800134import java.util.Locale;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700135
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136/**
137 * Default launcher application.
138 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100139public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700140 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chung006ee262015-08-03 14:40:11 -0700141 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700142 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700143 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700146 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700147 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400148 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700149
Dan Sandlerd5024042014-01-09 15:01:33 -0500150 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
151
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700153 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700154 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700155 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Michael Jurka8b805b12012-04-18 14:23:14 -0700157 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700158 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700159
Sunny Goyal28c6b962015-10-12 11:42:05 -0700160 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
161
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700162 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
163 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
164 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
165
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700166 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
167
Mathew Inwood876a8462013-06-14 14:12:41 +0100168 /**
169 * IntentStarter uses request codes starting with this. This must be greater than all activity
170 * request codes used internally.
171 */
172 protected static final int REQUEST_LAST = 100;
173
Michael Jurka0a457bf2012-11-19 14:05:05 -0800174 // To turn on these properties, type
175 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800176 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Winson Chung2672ff92012-05-04 16:22:30 -0700178 // The Intent extra that defines whether to ignore the launch animation
179 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400180 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
183 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700184 // Type: int
185 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700186 // Type: Content Values / parcelable
187 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700188 // Type: parcelable
189 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000190 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800191 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192
Adam Cohen432609a2014-03-13 17:03:22 -0700193 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800194 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
195
Adam Cohen3ed316a2014-07-23 18:21:20 -0700196 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
197 static final String ACTION_FIRST_LOAD_COMPLETE =
198 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
199
Sunny Goyal594d76d2014-11-06 10:12:54 -0800200 private static final String QSB_WIDGET_ID = "qsb_widget_id";
201 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
202
Winson Chunga6945242014-01-08 14:04:34 -0800203 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
204
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700205 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700206 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
207 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700208
Adam Cohen091440a2015-03-18 14:16:05 -0700209 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700210 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700211
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700212 private boolean mIsSafeModeEnabled;
213
Joe Onorato9c1289c2009-08-17 11:03:03 -0400214 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800215 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700216 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;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800368 private UserEventLogger mUserEventLogger;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800369
Adam Cohenf9c184a2016-01-15 16:47:43 -0800370 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700371 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400372
373 @Thunk void setOrientation() {
374 if (mRotationEnabled) {
375 unlockScreenOrientation(true);
376 } else {
377 setRequestedOrientation(
378 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700379 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400380 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700381
Sunny Goyal7779d622015-06-11 16:18:39 -0700382 private Runnable mUpdateOrientationRunnable = new Runnable() {
383 public void run() {
384 setOrientation();
385 }
386 };
387
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 @Override
389 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700390 if (DEBUG_STRICT_MODE) {
391 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
392 .detectDiskReads()
393 .detectDiskWrites()
394 .detectNetwork() // or .detectAll() for all detectable problems
395 .penaltyLog()
396 .build());
397 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
398 .detectLeakedSqlLiteObjects()
399 .detectLeakedClosableObjects()
400 .penaltyLog()
401 .penaltyDeath()
402 .build());
403 }
404
Adam Cohen9211d422014-10-07 18:14:53 -0700405 if (mLauncherCallbacks != null) {
406 mLauncherCallbacks.preOnCreate();
407 }
408
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800409 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400410
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400411 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700412
Adam Cohen2e6da152015-05-06 11:42:25 -0700413 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700414 mDeviceProfile = getResources().getConfiguration().orientation
415 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700416 app.getInvariantDeviceProfile().landscapeProfile
417 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700418
Sunny Goyalf7258242015-10-19 16:59:07 -0700419 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700420 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800421 mModel = app.setLauncher(this);
422 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700423
Joe Onorato41a12d22009-10-31 18:30:00 -0400424 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700425 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700426
Daniel Sandlerff02d492013-08-05 02:12:05 -0400427 mStats = new Stats(this);
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800428 initLogger();
Daniel Sandlerff02d492013-08-05 02:12:05 -0400429
Sunny Goyalffe83f12014-08-14 17:39:34 -0700430 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700431
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700432 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
433 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700434
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700435 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
436 // this also ensures that any synchronous binding below doesn't re-trigger another
437 // LauncherModel load.
438 mPaused = false;
439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200441 android.os.Debug.startMethodTracing(
442 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 }
444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700446
Tony Wickhameef44322015-10-20 13:24:36 -0700447 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
448 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700450 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451
Joe Onorato7c312c12009-08-13 21:36:53 -0700452 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700453
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 mSavedState = savedInstanceState;
455 restoreState(mSavedState);
456
457 if (PROFILE_STARTUP) {
458 android.os.Debug.stopMethodTracing();
459 }
460
461 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700462 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700463 // If the user leaves launcher, then we should just load items asynchronously when
464 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700465 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 } else {
467 // We only load the page synchronously if the user rotates (or triggers a
468 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700469 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700470 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 }
472
473 // For handling default keys
474 mDefaultKeySsb = new SpannableStringBuilder();
475 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800476
477 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
478 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800479
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800480 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700481 // In case we are on a device with locked rotation, we should look at preferences to check
482 // if the user has specifically allowed rotation.
483 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700484 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700485 }
486
487 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
488 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400489 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700490
Adam Cohen9211d422014-10-07 18:14:53 -0700491 if (mLauncherCallbacks != null) {
492 mLauncherCallbacks.onCreate(savedInstanceState);
493 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700494
495 if (shouldShowIntroScreen()) {
496 showIntroScreen();
497 } else {
498 showFirstRunActivity();
499 showFirstRunClings();
500 }
Adam Cohen9211d422014-10-07 18:14:53 -0700501 }
502
Sunny Goyal7779d622015-06-11 16:18:39 -0700503 @Override
504 public void onSettingsChanged(String settings, boolean value) {
505 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
506 mRotationEnabled = value;
507 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
508 mUpdateOrientationRunnable.run();
509 }
510 }
511 }
512
Adam Cohen9211d422014-10-07 18:14:53 -0700513 private LauncherCallbacks mLauncherCallbacks;
514
515 public void onPostCreate(Bundle savedInstanceState) {
516 super.onPostCreate(savedInstanceState);
517 if (mLauncherCallbacks != null) {
518 mLauncherCallbacks.onPostCreate(savedInstanceState);
519 }
520 }
521
Sunny Goyal32554d12015-12-03 15:31:25 -0800522 /**
523 * Call this after onCreate to set or clear overlay.
524 */
525 public void setLauncherOverlay(LauncherOverlay overlay) {
526 if (overlay != null) {
527 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
528 }
529 mWorkspace.setLauncherOverlay(overlay);
530 }
531
Adam Cohen9211d422014-10-07 18:14:53 -0700532 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
533 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700534 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700535 private boolean mWorkspaceImportanceStored = false;
536 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700537 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800538 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700539 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
540
541 @Override
542 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700543 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700544 return;
545 }
546 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700547 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700548 if (mWorkspace != null) {
549 mWorkspaceImportanceForAccessibility =
550 mWorkspace.getImportantForAccessibility();
551 mWorkspace.setImportantForAccessibility(
552 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
553 mWorkspaceImportanceStored = true;
554 }
555 if (mHotseat != null) {
556 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
557 mHotseat.setImportantForAccessibility(
558 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
559 mHotseatImportanceStored = true;
560 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700561 }
562
563 @Override
564 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700565 if (mWorkspaceImportanceStored && mWorkspace != null) {
566 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
567 }
568 if (mHotseatImportanceStored && mHotseat != null) {
569 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
570 }
571 mWorkspaceImportanceStored = false;
572 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700573 }
574 });
Adam Cohen9211d422014-10-07 18:14:53 -0700575 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700576 }
577
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700578 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700579 public void onLauncherProviderChange() {
580 if (mLauncherCallbacks != null) {
581 mLauncherCallbacks.onLauncherProviderChange();
582 }
583 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700584
Winson Chungef7f8742015-06-04 17:18:17 -0700585 /**
586 * Updates the bounds of all the overlays to match the new fixed bounds.
587 */
588 public void updateOverlayBounds(Rect newBounds) {
589 mAppsView.setSearchBarBounds(newBounds);
590 mWidgetsView.setSearchBarBounds(newBounds);
591 }
592
Adam Cohen9211d422014-10-07 18:14:53 -0700593 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700594 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700595 if (mLauncherCallbacks != null) {
596 return mLauncherCallbacks.hasCustomContentToLeft();
597 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700598 return false;
599 }
600
Dave Hawkeya8881582013-09-17 15:55:33 -0600601 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500602 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600603 * {@link #addToCustomContentPage}. This will only be invoked if
604 * {@link #hasCustomContentToLeft()} is {@code true}.
605 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500606 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700607 if (mLauncherCallbacks != null) {
608 mLauncherCallbacks.populateCustomContentContainer();
609 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600610 }
611
612 /**
613 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
614 * ensure the custom content page is added or removed if necessary.
615 */
616 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600617 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600618 // Not bound yet, wait for bindScreens to be called.
619 return;
620 }
621
622 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
623 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500624 mWorkspace.createCustomContentContainer();
625 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600626 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
627 mWorkspace.removeCustomContentPage();
628 }
629 }
630
Anton Hanssona2f665f2013-09-26 12:18:32 +0100631 public Stats getStats() {
632 return mStats;
633 }
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800634
635 /**
636 * Logger object is a singleton and does not have to be coupled with the foreground activity.
637 * Since most user event logging is done on the UI, the object is retrieved from the
638 * callback for convenience.
639 */
640 private void initLogger() {
641 if (mLauncherCallbacks != null) {
642 mUserEventLogger = mLauncherCallbacks.getLogger();
643 }
644 if (mUserEventLogger == null) {
645 mUserEventLogger = new UserEventLogger() {
646 @Override
647 public void processEvent(LauncherLogProto.LauncherEvent ev) {
648 if (ev.action.touch == LauncherLogProto.Action.TAP && ev.srcTarget.itemType == LauncherLogProto.APP_ICON) {
649 Log.d(TAG, String.format(Locale.US, "action:%s target:%s\n\telapsed container %d ms session %d ms",
650 LoggerUtils.getActionStr(ev.action),
651 LoggerUtils.getTargetStr(ev.srcTarget),
652 ev.elapsedContainerMillis,
653 ev.elapsedSessionMillis));
654 }
655 }
656 };
657 }
658 }
659
660 public UserEventLogger getLogger() {
661 return mUserEventLogger;
662 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100663
Hyunyoung Song3f471442015-04-08 19:01:34 -0700664 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700665 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
666 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700667 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700668 }
669
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000670 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700671 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
672 // This cast is safe as long as the id < 0x00FFFFFF
673 // Since we jail all the dynamically generated views, there should be no clashes
674 // with any other views.
675 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000676 }
677
678 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700679 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
680 * a configuration step, this allows the proper animations to run after other transitions.
681 */
Adam Cohendb364c32014-05-20 14:23:40 -0700682 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700683 long screenId = args.screenId;
684 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
685 // When the screen id represents an actual screen (as opposed to a rank) we make sure
686 // that the drop page actually exists.
687 screenId = ensurePendingDropLayoutExists(args.screenId);
688 }
Adam Cohendb364c32014-05-20 14:23:40 -0700689
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800690 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700692 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700693 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800695 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700696 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700697 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700698 case REQUEST_RECONFIGURE_APPWIDGET:
699 completeRestoreAppWidget(args.appWidgetId);
700 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800701 }
Michael Jurka27614d22012-04-02 06:40:22 -0700702 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
703 // if you turned the screen off and then back while in All Apps, Launcher would not
704 // return to the workspace. Clearing mAddInfo.container here fixes this issue
705 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700706 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800707 }
708
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800709 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700710 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700711 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700712 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700713 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800714 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700715
Adam Cohenad4e15c2013-10-17 16:21:35 -0700716 Runnable exitSpringLoaded = new Runnable() {
717 @Override
718 public void run() {
719 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
720 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
721 }
722 };
723
Michael Jurka8b805b12012-04-18 14:23:14 -0700724 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700725 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700726 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700727 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
728 if (resultCode == RESULT_CANCELED) {
729 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700730 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700731 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700732 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800733 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700734 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700735
736 // When the user has granted permission to bind widgets, we should check to see if
737 // we can inflate the default search bar widget.
738 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700739 }
740 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200741 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
742 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700743 // User could have free-scrolled between pages before picking a wallpaper; make sure
744 // we move to the closest one now.
745 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700746 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200747 }
748 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700749 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200750
Adam Cohened66b2b2012-01-23 17:28:51 -0800751 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700752 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700753
Adam Cohendb364c32014-05-20 14:23:40 -0700754 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800755 // We have special handling for widgets
756 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800757 final int appWidgetId;
758 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
759 : -1;
760 if (widgetId < 0) {
761 appWidgetId = pendingAddWidgetId;
762 } else {
763 appWidgetId = widgetId;
764 }
765
Adam Cohenad4e15c2013-10-17 16:21:35 -0700766 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800767 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700768 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
769 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 result = RESULT_CANCELED;
771 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700772 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 @Override
774 public void run() {
775 exitSpringLoadedDragModeDelayed(false, 0, null);
776 }
777 };
Adam Cohendb364c32014-05-20 14:23:40 -0700778 if (workspaceLocked) {
779 // No need to remove the empty screen if we're mid-binding, as the
780 // the bind will not add the empty screen.
781 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
782 } else {
783 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
784 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
785 }
Winson Chung5aaab772012-04-27 15:24:02 -0700786 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700787 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700788 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
789 // When the screen id represents an actual screen (as opposed to a rank)
790 // we make sure that the drop page actually exists.
791 mPendingAddInfo.screenId =
792 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
793 }
Adam Cohendb364c32014-05-20 14:23:40 -0700794 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
795
796 dropLayout.setDropPending(true);
797 final Runnable onComplete = new Runnable() {
798 @Override
799 public void run() {
800 completeTwoStageWidgetDrop(resultCode, appWidgetId);
801 dropLayout.setDropPending(false);
802 }
803 };
804 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
805 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
806 } else {
807 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
808 mPendingAddInfo);
809 sPendingAddItem = args;
810 }
Winson Chung5aaab772012-04-27 15:24:02 -0700811 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800812 return;
813 }
814
Sunny Goyalff572272014-07-23 13:58:07 -0700815 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
816 if (resultCode == RESULT_OK) {
817 // Update the widget view.
818 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
819 pendingAddWidgetId, mPendingAddInfo);
820 if (workspaceLocked) {
821 sPendingAddItem = args;
822 } else {
823 completeAdd(args);
824 }
825 }
826 // Leave the widget in the pending state if the user canceled the configure.
827 return;
828 }
829
Sunny Goyalaad90582015-07-09 14:22:50 -0700830 if (requestCode == REQUEST_CREATE_SHORTCUT) {
831 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
832 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
833 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
834 mPendingAddInfo);
835 if (isWorkspaceLocked()) {
836 sPendingAddItem = args;
837 } else {
838 completeAdd(args);
839 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
840 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
841 }
842 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700843 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
844 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800847 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800848
849 }
850
851 @Override
852 protected void onActivityResult(
853 final int requestCode, final int resultCode, final Intent data) {
854 handleActivityResult(requestCode, resultCode, data);
855 if (mLauncherCallbacks != null) {
856 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
857 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800858 }
859
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600860 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700861 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600862 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700863 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
864 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
865 View v = null;
866 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
867 if (layout != null) {
868 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
869 }
870 Intent intent = sPendingAddItem.intent;
871 sPendingAddItem = null;
872 if (grantResults.length > 0
873 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
874 startActivity(v, intent, null);
875 } else {
876 // TODO: Show a snack bar with link to settings
877 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
878 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
879 }
880 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600881 if (mLauncherCallbacks != null) {
882 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
883 grantResults);
884 }
885 }
886
Adam Cohendb364c32014-05-20 14:23:40 -0700887 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
888 appWidgetId, ItemInfo info) {
889 PendingAddArguments args = new PendingAddArguments();
890 args.requestCode = requestCode;
891 args.intent = data;
892 args.container = info.container;
893 args.screenId = info.screenId;
894 args.cellX = info.cellX;
895 args.cellY = info.cellY;
896 args.appWidgetId = appWidgetId;
897 return args;
898 }
899
900 /**
901 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
902 *
903 * @param screenId the screen id to check
904 * @return the new screen, or screenId if it exists
905 */
906 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800907 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700908 if (dropLayout == null) {
909 // it's possible that the add screen was removed because it was
910 // empty and a re-bind occurred
911 mWorkspace.addExtraEmptyScreen();
912 return mWorkspace.commitExtraEmptyScreen();
913 } else {
914 return screenId;
915 }
916 }
917
Adam Cohen091440a2015-03-18 14:16:05 -0700918 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800919 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 Runnable onCompleteRunnable = null;
921 int animationType = 0;
922
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700923 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800924 if (resultCode == RESULT_OK) {
925 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
926 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700927 mPendingAddWidgetInfo);
928 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800929 onCompleteRunnable = new Runnable() {
930 @Override
931 public void run() {
932 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700933 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700934 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
935 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800936 }
937 };
938 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800939 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800940 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800941 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700942 if (mDragLayer.getAnimatedView() != null) {
943 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
944 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
945 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700946 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700947 // The animated view may be null in the case of a rotation during widget configuration
948 onCompleteRunnable.run();
949 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 }
951
952 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700953 protected void onStop() {
954 super.onStop();
955 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700956
957 if (mLauncherCallbacks != null) {
958 mLauncherCallbacks.onStop();
959 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700960 }
961
962 @Override
963 protected void onStart() {
964 super.onStart();
965 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700966
967 if (mLauncherCallbacks != null) {
968 mLauncherCallbacks.onStart();
969 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700970 }
971
972 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200974 long startTime = 0;
975 if (DEBUG_RESUME_TIME) {
976 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400977 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200978 }
Adam Cohen9211d422014-10-07 18:14:53 -0700979
980 if (mLauncherCallbacks != null) {
981 mLauncherCallbacks.preOnResume();
982 }
983
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 super.onResume();
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800985 mUserEventLogger.resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700986
Winson Chung4a2afa32012-07-19 14:53:05 -0700987 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700988 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700989 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800990 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700991 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700992 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700993 // view after launching an app, as they may be depending on the UI to be static to
994 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700995 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700996 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800997 } else if (mOnResumeState == State.WIDGETS) {
998 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700999 }
1000 mOnResumeState = State.NONE;
1001
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001002 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001003 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1004 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001005
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001006 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001007 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001008 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001009 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001010 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001011 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001013 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001014 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1015 // execute them here
1016 long startTimeCallbacks = 0;
1017 if (DEBUG_RESUME_TIME) {
1018 startTimeCallbacks = System.currentTimeMillis();
1019 }
1020
Michael Jurka1e2f4652013-07-08 18:03:46 -07001021 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1022 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001023 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001024 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001025 if (DEBUG_RESUME_TIME) {
1026 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1027 (System.currentTimeMillis() - startTimeCallbacks));
1028 }
Michael Jurka447bf842013-05-15 14:52:15 +02001029 }
Michael Jurka54554252013-08-01 12:52:23 +02001030 if (mOnResumeCallbacks.size() > 0) {
1031 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1032 mOnResumeCallbacks.get(i).run();
1033 }
1034 mOnResumeCallbacks.clear();
1035 }
Winson Chunge4e50662012-01-23 14:45:13 -08001036
1037 // Reset the pressed state of icons that were locked in the press state while activities
1038 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001039 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001040 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001041 mWaitingForResume.setStayPressed(false);
1042 }
Winson Chung82963d52013-10-09 11:20:57 -07001043
Adam Cohen06dff352012-06-01 17:17:08 -07001044 // It is possible that widgets can receive updates while launcher is not in the foreground.
1045 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1046 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1047 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001048 if (!isWorkspaceLoading()) {
1049 getWorkspace().reinflateWidgetsIfNecessary();
1050 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001051 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001052
Michael Jurka447bf842013-05-15 14:52:15 +02001053 if (DEBUG_RESUME_TIME) {
1054 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1055 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001056
Adam Cohen4b66bf32015-09-18 12:15:19 -07001057 // We want to suppress callbacks about CustomContent being shown if we have just received
1058 // onNewIntent while the user was present within launcher. In that case, we post a call
1059 // to move the user to the main screen (which will occur after onResume). We don't want to
1060 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1061 // suppress here.
1062 if (mWorkspace.getCustomContentCallbacks() != null
1063 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001064 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001065 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001066 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1067 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001068 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001069 }
1070 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001071 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001072 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001073 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001074
Sunny Goyal756adbc2015-04-16 15:20:51 -07001075 if (!isWorkspaceLoading()) {
1076 // Process any items that were added while Launcher was away.
1077 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1078 }
Adam Cohen9211d422014-10-07 18:14:53 -07001079
1080 if (mLauncherCallbacks != null) {
1081 mLauncherCallbacks.onResume();
1082 }
Adam Cohen06dff352012-06-01 17:17:08 -07001083 }
1084
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001086 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001087 // Ensure that items added to Launcher are queued until Launcher returns
1088 InstallShortcutReceiver.enableInstallQueue();
1089
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001090 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001091 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001092 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001093 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001094
1095 // We call onHide() aggressively. The custom content callbacks should be able to
1096 // debounce excess onHide calls.
1097 if (mWorkspace.getCustomContentCallbacks() != null) {
1098 mWorkspace.getCustomContentCallbacks().onHide();
1099 }
Romain Guycbb89e42009-06-08 15:52:54 -07001100
Adam Cohen9211d422014-10-07 18:14:53 -07001101 if (mLauncherCallbacks != null) {
1102 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001103 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001104 }
1105
1106 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001107 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1108 // by a onResume or by scrolling otherwise.
1109 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001110
1111 // Custom content is completely hidden
1112 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001113
1114 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1115 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001116
1117 // Indicates whether the user is allowed to scroll away from the custom content.
1118 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001119 }
1120
Adam Cohenc2d6e892014-10-16 09:49:24 -07001121 public interface LauncherOverlay {
1122
1123 /**
1124 * Touch interaction leading to overscroll has begun
1125 */
1126 public void onScrollInteractionBegin();
1127
1128 /**
1129 * Touch interaction related to overscroll has ended
1130 */
1131 public void onScrollInteractionEnd();
1132
1133 /**
1134 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1135 * screen (or in the case of RTL, the rightmost screen).
1136 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001137 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001138
1139 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001140 * Called when the launcher is ready to use the overlay
1141 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001142 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001143 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001144 }
1145
Jun Mukai8af0cd82015-05-12 12:32:12 -07001146 public interface LauncherSearchCallbacks {
1147 /**
1148 * Called when the search overlay is shown.
1149 */
1150 public void onSearchOverlayOpened();
1151
1152 /**
1153 * Called when the search overlay is dismissed.
1154 */
1155 public void onSearchOverlayClosed();
1156 }
1157
Adam Cohenc2d6e892014-10-16 09:49:24 -07001158 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001159 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001160 }
1161
1162 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1163
Sunny Goyalc86df472016-02-25 09:19:38 -08001164 public void onScrollChanged(float progress) {
1165 if (mWorkspace != null) {
1166 mWorkspace.onOverlayScrollChanged(progress);
1167 }
1168 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001169 }
1170
Jorim Jaggid017f882014-01-14 17:08:48 -08001171 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001172 if (mLauncherCallbacks != null) {
1173 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001174 } else {
1175 // On devices with a locked orientation, we will at least have the allow rotation
1176 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001177 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001178 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001179 }
1180
Adam Cohen9211d422014-10-07 18:14:53 -07001181 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001182 CustomContentCallbacks callbacks, String description) {
1183 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001184 }
1185
Adam Cohenedb40762013-07-18 16:45:45 -07001186 // The custom content needs to offset its content to account for the QSB
1187 public int getTopOffsetForCustomContent() {
1188 return mWorkspace.getPaddingTop();
1189 }
1190
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001191 @Override
1192 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001193 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001194 if (mModel.isCurrentCallbacks(this)) {
1195 mModel.stopLoader();
1196 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001197 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1198
Romain Guy13c2e7b2010-03-10 19:45:00 -08001199 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001200 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001201
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001202 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001203 @Override
1204 public void onWindowFocusChanged(boolean hasFocus) {
1205 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001206 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001207
1208 if (mLauncherCallbacks != null) {
1209 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1210 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001211 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001212
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 private boolean acceptFilter() {
1214 final InputMethodManager inputManager = (InputMethodManager)
1215 getSystemService(Context.INPUT_METHOD_SERVICE);
1216 return !inputManager.isFullscreenMode();
1217 }
1218
1219 @Override
1220 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001221 final int uniChar = event.getUnicodeChar();
1222 final boolean handled = super.onKeyDown(keyCode, event);
1223 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1224 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1226 keyCode, event);
1227 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001228 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001229 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001230 // showSearchDialog()
1231 // If there are multiple keystrokes before the search dialog takes focus,
1232 // onSearchRequested() will be called for every keystroke,
1233 // but it is idempotent, so it's fine.
1234 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 }
1236 }
1237
Joe Onorato8a9625e2010-01-28 15:55:35 -08001238 // Eat the long press event so the keyboard doesn't come up.
1239 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1240 return true;
1241 }
1242
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 return handled;
1244 }
1245
Winson46163472015-09-22 17:31:56 -07001246 @Override
1247 public boolean onKeyUp(int keyCode, KeyEvent event) {
1248 if (keyCode == KeyEvent.KEYCODE_MENU) {
1249 // Ignore the menu key if we are currently dragging or are on the custom content screen
1250 if (!isOnCustomContent() && !mDragController.isDragging()) {
1251 // Close any open folders
1252 closeFolder();
1253
1254 // Stop resizing any widgets
1255 mWorkspace.exitWidgetResizeMode();
1256
1257 // Show the overview mode if we are on the workspace
1258 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1259 !mWorkspace.isSwitchingState()) {
1260 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001261 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001262 }
1263 }
1264 return true;
1265 }
1266 return super.onKeyUp(keyCode, event);
1267 }
1268
Karl Rosaen138a0412009-04-23 19:00:21 -07001269 private String getTypedText() {
1270 return mDefaultKeySsb.toString();
1271 }
1272
1273 private void clearTypedText() {
1274 mDefaultKeySsb.clear();
1275 mDefaultKeySsb.clearSpans();
1276 Selection.setSelection(mDefaultKeySsb, 0);
1277 }
1278
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001279 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001280 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1281 * State
1282 */
1283 private static State intToState(int stateOrdinal) {
1284 State state = State.WORKSPACE;
1285 final State[] stateValues = State.values();
1286 for (int i = 0; i < stateValues.length; i++) {
1287 if (stateValues[i].ordinal() == stateOrdinal) {
1288 state = stateValues[i];
1289 break;
1290 }
1291 }
1292 return state;
1293 }
1294
1295 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 * Restores the previous state, if it exists.
1297 *
1298 * @param savedState The previous state.
1299 */
1300 private void restoreState(Bundle savedState) {
1301 if (savedState == null) {
1302 return;
1303 }
1304
Michael Jurka883f55b2010-10-21 15:47:14 -07001305 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001306 if (state == State.APPS || state == State.WIDGETS) {
1307 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001308 }
1309
Adam Cohen21cd0022013-10-09 18:57:02 -07001310 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1311 PagedView.INVALID_RESTORE_PAGE);
1312 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001313 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 }
1315
Sunny Goyal756cd262015-08-20 12:33:21 -07001316 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1317 if (itemValues != null) {
1318 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001319 AppWidgetProviderInfo info = savedState.getParcelable(
1320 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001321 mPendingAddWidgetInfo = info == null ?
1322 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1323
Adam Cohen4637b5a2013-11-04 18:21:24 -08001324 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001325 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 mRestoring = true;
1327 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
1329
1330 /**
1331 * Finds all the views we need and configure them properly.
1332 */
1333 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001334 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001335
Craig Mautner360310b2012-10-26 15:13:08 -07001336 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001337 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001338 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1339 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001340 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001341 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001342
John Spurlock77e1f472013-09-11 10:09:51 -04001343 mLauncherView.setSystemUiVisibility(
1344 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001345 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346
Winson Chung4c98d922011-05-31 16:50:48 -07001347 // Setup the drag layer
1348 mDragLayer.setup(this, dragController);
1349
Winson Chung3d503fb2011-07-13 17:25:49 -07001350 // Setup the hotseat
1351 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1352 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001353 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001354 }
1355
Winsone9f27272015-10-13 10:47:51 -07001356 // Setup the overview panel
1357 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001358
Winson Chung4c98d922011-05-31 16:50:48 -07001359 // Setup the workspace
1360 mWorkspace.setHapticFeedbackEnabled(false);
1361 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001362 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001363 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001364
Tony Wickham34d2c912015-09-11 09:27:58 -07001365 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001366 mSearchDropTargetBar = (SearchDropTargetBar)
1367 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001368 // Get the app info bar
1369 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1370 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001371
Winson Chungef7f8742015-06-04 17:18:17 -07001372 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001373 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001374 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001375 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1376 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1377 } else {
1378 mAppsView.setSearchBarController(new DefaultAppSearchController());
1379 }
Craig Mautner360310b2012-10-26 15:13:08 -07001380
Winson Chung3d503fb2011-07-13 17:25:49 -07001381 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001382 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001383 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001384 dragController.setMoveTarget(mWorkspace);
1385 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001386 if (mSearchDropTargetBar != null) {
1387 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001388 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001389 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001390 if (mAppInfoDropTargetBar != null) {
1391 mAppInfoDropTargetBar.setup(this, dragController);
1392 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001393
Sunny Goyal322d5562015-06-25 19:35:49 -07001394 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1395 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001396 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001397 }
1398
Winsone9f27272015-10-13 10:47:51 -07001399 private void setupOverviewPanel() {
1400 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1401
1402 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1403 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1404 @Override
1405 public boolean onLongClick(View v) {
1406 return v.performClick();
1407 }
1408 };
1409
1410 // Bind wallpaper button actions
1411 View wallpaperButton = findViewById(R.id.wallpaper_button);
1412 wallpaperButton.setOnClickListener(new OnClickListener() {
1413 @Override
1414 public void onClick(View view) {
1415 if (!mWorkspace.isSwitchingState()) {
1416 onClickWallpaperPicker(view);
1417 }
1418 }
1419 });
1420 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1421 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1422
1423 // Bind widget button actions
1424 mWidgetsButton = findViewById(R.id.widget_button);
1425 mWidgetsButton.setOnClickListener(new OnClickListener() {
1426 @Override
1427 public void onClick(View view) {
1428 if (!mWorkspace.isSwitchingState()) {
1429 onClickAddWidgetButton(view);
1430 }
1431 }
1432 });
1433 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1434 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1435
1436 // Bind settings actions
1437 View settingsButton = findViewById(R.id.settings_button);
1438 boolean hasSettings = hasSettings();
1439 if (hasSettings) {
1440 settingsButton.setOnClickListener(new OnClickListener() {
1441 @Override
1442 public void onClick(View view) {
1443 if (!mWorkspace.isSwitchingState()) {
1444 onClickSettingsButton(view);
1445 }
1446 }
1447 });
1448 settingsButton.setOnLongClickListener(performClickOnLongClick);
1449 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1450 } else {
1451 settingsButton.setVisibility(View.GONE);
1452 }
1453
1454 mOverviewPanel.setAlpha(0f);
1455 }
1456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001458 * Sets the all apps button. This method is called from {@link Hotseat}.
1459 */
1460 public void setAllAppsButton(View allAppsButton) {
1461 mAllAppsButton = allAppsButton;
1462 }
1463
1464 public View getAllAppsButton() {
1465 return mAllAppsButton;
1466 }
1467
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001468 public View getWidgetsButton() {
1469 return mWidgetsButton;
1470 }
1471
Anjali Koppal5ad44842014-03-10 20:34:39 -07001472 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 * Creates a view representing a shortcut.
1474 *
1475 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001477 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001478 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 }
1480
1481 /**
1482 * Creates a view representing a shortcut inflated from the specified resource.
1483 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 * @param parent The group the shortcut belongs to.
1485 * @param info The data structure describing the shortcut.
1486 *
1487 * @return A View inflated from layoutResId.
1488 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001489 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001490 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001491 parent, false);
1492 favorite.applyFromShortcutInfo(info, mIconCache);
1493 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001494 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001495 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 return favorite;
1497 }
1498
1499 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001500 * Add a shortcut to the workspace.
1501 *
1502 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001504 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001505 int cellY) {
1506 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001507 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001508
Sunny Goyal5c97f512015-05-19 16:03:28 -07001509 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001510 if (info == null) {
1511 return;
1512 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001513 final View view = createShortcut(info);
1514
Sunny Goyal5c97f512015-05-19 16:03:28 -07001515 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001516 // First we check if we already know the exact location where we want to add this item.
1517 if (cellX >= 0 && cellY >= 0) {
1518 cellXY[0] = cellX;
1519 cellXY[1] = cellY;
1520 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001521
1522 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001523 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001524 true, null,null)) {
1525 return;
1526 }
1527 DragObject dragObject = new DragObject();
1528 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001529 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1530 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001531 return;
1532 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001533 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001534 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001535 }
1536
1537 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001538 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001539 return;
1540 }
1541
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001542 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543
1544 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001545 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001546 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 }
1548 }
1549
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001550 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001551 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001553 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 */
Adam Cohen091440a2015-03-18 14:16:05 -07001555 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001556 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1557
1558 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001559 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001560 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001561 }
Romain Guycbb89e42009-06-08 15:52:54 -07001562
Adam Cohen59400422014-03-05 18:07:04 -08001563 if (appWidgetInfo.isCustomWidget) {
1564 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001565 }
1566
Adam Cohen59400422014-03-05 18:07:04 -08001567 LauncherAppWidgetInfo launcherInfo;
1568 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1569 launcherInfo.spanX = info.spanX;
1570 launcherInfo.spanY = info.spanY;
1571 launcherInfo.minSpanX = info.minSpanX;
1572 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001573 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001574
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001576 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
1578 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001579 if (hostView == null) {
1580 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001581 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1582 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001583 } else {
1584 // The AppWidgetHostView has already been inflated and instantiated
1585 launcherInfo.hostView = hostView;
1586 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001587 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001588 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001590 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591 }
Romain Guycbb89e42009-06-08 15:52:54 -07001592
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001593 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1594 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1595 item.hostView.setTag(item);
1596 item.onBindAppWidget(this);
1597
1598 item.hostView.setFocusable(true);
1599 item.hostView.setOnFocusChangeListener(mFocusHandler);
1600
1601 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1602 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1603
1604 if (!item.isCustomWidget()) {
1605 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1606 }
1607 }
1608
Adam Cohended9f8d2010-11-03 13:25:16 -07001609 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1610 @Override
1611 public void onReceive(Context context, Intent intent) {
1612 final String action = intent.getAction();
1613 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1614 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001615 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001616 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001617
Winson Chungc100e8e2011-08-09 16:02:43 -07001618 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001619 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001620 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001621 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001622 if (!showWorkspace(false)) {
1623 // If we are already on the workspace, then manually reset all apps
1624 mAppsView.reset();
1625 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001626 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001627 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1628 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001629 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001630 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1631 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001632 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001633 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1634 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1635 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001636 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001637 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1638 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001639 }
1640 }
1641 };
1642
1643 @Override
1644 public void onAttachedToWindow() {
1645 super.onAttachedToWindow();
1646
1647 // Listen for broadcasts related to user-presence
1648 final IntentFilter filter = new IntentFilter();
1649 filter.addAction(Intent.ACTION_SCREEN_OFF);
1650 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001651 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001652 if (ENABLE_DEBUG_INTENTS) {
1653 filter.addAction(DebugIntents.DELETE_DATABASE);
1654 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1655 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001656 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001657 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001658 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001659 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001660
1661 if (mLauncherCallbacks != null) {
1662 mLauncherCallbacks.onAttachedToWindow();
1663 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001664 }
1665
1666 @Override
1667 public void onDetachedFromWindow() {
1668 super.onDetachedFromWindow();
1669 mVisible = false;
1670
Adam Cohend113e0c2010-11-11 10:48:05 -08001671 if (mAttached) {
1672 unregisterReceiver(mReceiver);
1673 mAttached = false;
1674 }
Winson Chungb745afb2015-03-02 11:51:23 -08001675 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001676
1677 if (mLauncherCallbacks != null) {
1678 mLauncherCallbacks.onDetachedFromWindow();
1679 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001680 }
1681
1682 public void onWindowVisibilityChanged(int visibility) {
1683 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001684 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001685 // The following code used to be in onResume, but it turns out onResume is called when
1686 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1687 // is a more appropriate event to handle
1688 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001689 if (!mWorkspaceLoading) {
1690 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001691 // We want to let Launcher draw itself at least once before we force it to build
1692 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001693 // apps is nice and speedy.
1694 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001695 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001696 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001697 if (mStarted) return;
1698 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001699 // We delay the layer building a bit in order to give
1700 // other message processing a time to run. In particular
1701 // this avoids a delay in hiding the IME if it was
1702 // currently shown, because doing that may involve
1703 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001704 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001705 final ViewTreeObserver.OnDrawListener listener = this;
1706 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001707 public void run() {
1708 if (mWorkspace != null &&
1709 mWorkspace.getViewTreeObserver() != null) {
1710 mWorkspace.getViewTreeObserver().
1711 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001712 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001713 }
1714 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001715 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001716 }
1717 });
1718 }
1719 clearTypedText();
1720 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001721 }
1722
Adam Cohen091440a2015-03-18 14:16:05 -07001723 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001724 mHandler.removeMessages(ADVANCE_MSG);
1725 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1726 mHandler.sendMessageDelayed(msg, delay);
1727 mAutoAdvanceSentTime = System.currentTimeMillis();
1728 }
1729
Adam Cohen091440a2015-03-18 14:16:05 -07001730 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001731 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1732 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1733 mAutoAdvanceRunning = autoAdvanceRunning;
1734 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001735 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001736 sendAdvanceMessage(delay);
1737 } else {
1738 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001739 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001740 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1741 }
1742 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001743 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 }
1745 }
1746 }
1747
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001748 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1749
Adam Cohended9f8d2010-11-03 13:25:16 -07001750 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001751 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001752 if (msg.what == ADVANCE_MSG) {
1753 int i = 0;
1754 for (View key: mWidgetsToAdvance.keySet()) {
1755 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001756 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001757 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001758 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 public void run() {
1760 ((Advanceable) v).advance();
1761 }
1762 }, delay);
1763 }
1764 i++;
1765 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001766 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001768 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001769 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001770 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001771
Winsonc0b52fe2015-09-09 16:38:15 -07001772 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001773 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001774 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1775 if (v instanceof Advanceable) {
1776 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001777 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001778 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001779 }
1780 }
1781
Winsonc0b52fe2015-09-09 16:38:15 -07001782 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001783 if (mWidgetsToAdvance.containsKey(hostView)) {
1784 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001785 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001787 }
1788
Hyunyoung Song3f471442015-04-08 19:01:34 -07001789 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001790 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1791 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001792 }
1793
Winson Chunga6945242014-01-08 14:04:34 -08001794 public DragLayer getDragLayer() {
1795 return mDragLayer;
1796 }
1797
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001798 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001799 return mAppsView;
1800 }
1801
Hyunyoung Song3f471442015-04-08 19:01:34 -07001802 public WidgetsContainerView getWidgetsView() {
1803 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001804 }
1805
Winson Chunga6945242014-01-08 14:04:34 -08001806 public Workspace getWorkspace() {
1807 return mWorkspace;
1808 }
1809
1810 public Hotseat getHotseat() {
1811 return mHotseat;
1812 }
1813
Jorim Jaggid017f882014-01-14 17:08:48 -08001814 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001815 return mOverviewPanel;
1816 }
1817
Winson Chung006ee262015-08-03 14:40:11 -07001818 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001819 return mSearchDropTargetBar;
1820 }
1821
Tony Wickham34d2c912015-09-11 09:27:58 -07001822 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1823 return mAppInfoDropTargetBar;
1824 }
1825
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001826 public LauncherAppWidgetHost getAppWidgetHost() {
1827 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 }
Romain Guycbb89e42009-06-08 15:52:54 -07001829
Winson Chunga9abd0e2010-10-27 17:18:37 -07001830 public LauncherModel getModel() {
1831 return mModel;
1832 }
1833
Winson Chunga6945242014-01-08 14:04:34 -08001834 protected SharedPreferences getSharedPrefs() {
1835 return mSharedPrefs;
1836 }
1837
Adam Cohen2e6da152015-05-06 11:42:25 -07001838 public DeviceProfile getDeviceProfile() {
1839 return mDeviceProfile;
1840 }
1841
Bjorn Bringertc459e522013-06-07 19:36:01 +01001842 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001843 getWindow().closeAllPanels();
1844
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001845 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001846 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001847 }
1848
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 @Override
1850 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001851 long startTime = 0;
1852 if (DEBUG_RESUME_TIME) {
1853 startTime = System.currentTimeMillis();
1854 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 super.onNewIntent(intent);
1856
1857 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001858 Folder openFolder = mWorkspace.getOpenFolder();
1859 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1860 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1861 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1862 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1863 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001864 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001865 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001866
Adam Cohen6fecd412013-10-02 17:41:50 -07001867 if (mWorkspace == null) {
1868 // Can be cases where mWorkspace is null, this prevents a NPE
1869 return;
1870 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001871 // In all these cases, only animate if we're already on home
1872 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001873
Sunny Goyal935fca12015-10-13 10:19:01 -07001874 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001875 exitSpringLoadedDragMode();
1876
1877 // If we are already on home, then just animate back to the workspace,
1878 // otherwise, just wait until onResume to set the state back to Workspace
1879 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001880 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001881 } else {
1882 mOnResumeState = State.WORKSPACE;
1883 }
1884
1885 final View v = getWindow().peekDecorView();
1886 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001887 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001888 INPUT_METHOD_SERVICE);
1889 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1890 }
1891
Winson Chungb745afb2015-03-02 11:51:23 -08001892 // Reset the apps view
1893 if (!alreadyOnHome && mAppsView != null) {
1894 mAppsView.scrollToTop();
1895 }
1896
Hyunyoung Song3f471442015-04-08 19:01:34 -07001897 // Reset the widgets view
1898 if (!alreadyOnHome && mWidgetsView != null) {
1899 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001900 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001901
Adam Cohen9211d422014-10-07 18:14:53 -07001902 if (mLauncherCallbacks != null) {
1903 mLauncherCallbacks.onHomeIntent();
1904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 }
Adam Cohened307df2013-10-02 09:37:31 -07001906
Adam Cohen9211d422014-10-07 18:14:53 -07001907 if (mLauncherCallbacks != null) {
1908 mLauncherCallbacks.onNewIntent(intent);
1909 }
Winson15f8b172015-08-19 11:02:39 -07001910
1911 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1912 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1913 // animation.
1914 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001915 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1916 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001917 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1918 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001919
1920 // We use this flag to suppress noisy callbacks above custom content state
1921 // from onResume.
1922 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001923 mWorkspace.post(new Runnable() {
1924 @Override
1925 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001926 if (mWorkspace != null) {
1927 mWorkspace.moveToDefaultScreen(true);
1928 }
Winson15f8b172015-08-19 11:02:39 -07001929 }
1930 });
1931 }
1932 }
1933
1934 if (DEBUG_RESUME_TIME) {
1935 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1936 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001937 }
1938
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001940 public void onRestoreInstanceState(Bundle state) {
1941 super.onRestoreInstanceState(state);
1942 for (int page: mSynchronouslyBoundPages) {
1943 mWorkspace.restoreInstanceStateForChild(page);
1944 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 }
1946
1947 @Override
1948 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001949 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001950 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1951 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001952 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001953 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954
Michael Jurka883f55b2010-10-21 15:47:14 -07001955 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001956 // We close any open folder since it will not be re-opened, and we need to make sure
1957 // this state is reflected.
1958 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1959 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960
Adam Cohendcd297f2013-06-18 13:13:40 -07001961 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001962 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001963 ContentValues itemValues = new ContentValues();
1964 mPendingAddInfo.writeToValues(itemValues);
1965 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001966 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001967 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001968 }
1969
Hyunyoung Song3f471442015-04-08 19:01:34 -07001970 // Save the current widgets tray?
1971 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001972
1973 if (mLauncherCallbacks != null) {
1974 mLauncherCallbacks.onSaveInstanceState(outState);
1975 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 }
1977
1978 @Override
1979 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001981
Winson Chunge7a03942011-08-05 15:05:12 -07001982 // Remove all pending runnables
1983 mHandler.removeMessages(ADVANCE_MSG);
1984 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001985 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001986
Winson Chungcd2b0142011-06-08 16:02:26 -07001987 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001988 // 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();
Sunny Goyald365ed62016-02-12 09:44:03 -08001992 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07001993 }
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
Michael Jurka2ecf9952012-06-18 12:52:28 -07002008 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002009
2010 if (mLauncherCallbacks != null) {
2011 mLauncherCallbacks.onDestroy();
2012 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002013 }
2014
Adam Cohena9cf38f2011-05-02 15:36:58 -07002015 public DragController getDragController() {
2016 return mDragController;
2017 }
2018
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 @Override
2020 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002021 onStartForResult(requestCode);
2022 super.startActivityForResult(intent, requestCode);
2023 }
2024
2025 @Override
2026 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2027 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2028 onStartForResult(requestCode);
2029 try {
2030 super.startIntentSenderForResult(intent, requestCode,
2031 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2032 } catch (IntentSender.SendIntentException e) {
2033 throw new ActivityNotFoundException();
2034 }
2035 }
2036
2037 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002038 if (requestCode >= 0) {
2039 setWaitingForResult(true);
2040 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 }
2042
Winson Chung70d72102011-08-12 11:24:35 -07002043 /**
2044 * Indicates that we want global search for this activity by setting the globalSearch
2045 * argument for {@link #startSearch} to true.
2046 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002048 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002050
Karl Rosaen138a0412009-04-23 19:00:21 -07002051 if (initialQuery == null) {
2052 // Use any text typed in the launcher as the initial query
2053 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 if (appSearchData == null) {
2056 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002057 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 }
Winson Chungadf0c182012-08-23 14:59:07 -07002059 Rect sourceBounds = new Rect();
2060 if (mSearchDropTargetBar != null) {
2061 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2062 }
Romain Guycbb89e42009-06-08 15:52:54 -07002063
Ian Parkinson047036e2014-09-01 15:40:53 +01002064 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002065 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002066 if (clearTextImmediately) {
2067 clearTypedText();
2068 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002069
2070 // We need to show the workspace after starting the search
2071 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002072 }
2073
Ian Parkinson047036e2014-09-01 15:40:53 +01002074 /**
2075 * Start a text search.
2076 *
2077 * @return {@code true} if the search will start immediately, so any further keypresses
2078 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2079 * to buffer keypresses.
2080 */
2081 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002082 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002083 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2084 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2085 sourceBounds);
2086 }
2087
Michael Jurkaa33411c2012-06-14 16:18:21 -07002088 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002089 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002090 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002091 }
2092
2093 /**
2094 * Starts the global search activity. This code is a copied from SearchManager
2095 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002096 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002097 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002098 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002099 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2100 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2101 if (globalSearchActivity == null) {
2102 Log.w(TAG, "No global search activity found.");
2103 return;
2104 }
2105 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2106 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2107 intent.setComponent(globalSearchActivity);
2108 // Make sure that we have a Bundle to put source in
2109 if (appSearchData == null) {
2110 appSearchData = new Bundle();
2111 } else {
2112 appSearchData = new Bundle(appSearchData);
2113 }
Adam Cohen9211d422014-10-07 18:14:53 -07002114 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002115 if (!appSearchData.containsKey("source")) {
2116 appSearchData.putString("source", getPackageName());
2117 }
2118 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2119 if (!TextUtils.isEmpty(initialQuery)) {
2120 intent.putExtra(SearchManager.QUERY, initialQuery);
2121 }
2122 if (selectInitialQuery) {
2123 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2124 }
2125 intent.setSourceBounds(sourceBounds);
2126 try {
2127 startActivity(intent);
2128 } catch (ActivityNotFoundException ex) {
2129 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2130 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 }
2132
Yura4f93ec62014-02-04 14:15:21 +00002133 public boolean isOnCustomContent() {
2134 return mWorkspace.isOnOrMovingToCustomContent();
2135 }
2136
Winson Chung70d72102011-08-12 11:24:35 -07002137 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002138 public boolean onPrepareOptionsMenu(Menu menu) {
2139 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002140 if (mLauncherCallbacks != null) {
2141 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2142 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002143 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002144 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002146 @Override
2147 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002148 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002149 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002150 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002151 }
2152
Joe Onorato9c1289c2009-08-17 11:03:03 -04002153 public boolean isWorkspaceLocked() {
2154 return mWorkspaceLoading || mWaitingForResult;
2155 }
2156
Adam Cohen517a7f52014-03-01 12:12:59 -08002157 public boolean isWorkspaceLoading() {
2158 return mWorkspaceLoading;
2159 }
2160
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002161 private void setWorkspaceLoading(boolean value) {
2162 boolean isLocked = isWorkspaceLocked();
2163 mWorkspaceLoading = value;
2164 if (isLocked != isWorkspaceLocked()) {
2165 onWorkspaceLockedChanged();
2166 }
2167 }
2168
2169 private void setWaitingForResult(boolean value) {
2170 boolean isLocked = isWorkspaceLocked();
2171 mWaitingForResult = value;
2172 if (isLocked != isWorkspaceLocked()) {
2173 onWorkspaceLockedChanged();
2174 }
2175 }
2176
Adam Cohen9211d422014-10-07 18:14:53 -07002177 protected void onWorkspaceLockedChanged() {
2178 if (mLauncherCallbacks != null) {
2179 mLauncherCallbacks.onWorkspaceLockedChanged();
2180 }
2181 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002182
Michael Jurka0280c3b2010-09-17 15:00:07 -07002183 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002184 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002185 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002186 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2187 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002188 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002189 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002190
Tony Wickhama0628cc2015-10-14 15:23:04 -07002191 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002192 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002193 if (LOGD) {
2194 Log.d(TAG, "Adding widget from drop");
2195 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002196 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2197 }
2198
Sunny Goyale6b63a32015-01-16 16:14:29 -08002199 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002200 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2201 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002202 if (appWidgetInfo.configure != null) {
2203 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002204 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002205
Bjorn Bringert7984c942009-12-09 15:38:25 +00002206 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002207 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2208 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2209
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002211 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002212 Runnable onComplete = new Runnable() {
2213 @Override
2214 public void run() {
2215 // Exit spring loaded mode if necessary after adding the widget
2216 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2217 null);
2218 }
2219 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002220 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002221 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002222 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002223 }
2224 }
Romain Guycbb89e42009-06-08 15:52:54 -07002225
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002226 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002227 // Close any folders that may be open.
2228 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002229 mWorkspace.moveToCustomContentScreen(animate);
2230 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002231
2232 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2233 int[] cell, int spanX, int spanY) {
2234 switch (info.itemType) {
2235 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2236 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2237 int span[] = new int[2];
2238 span[0] = spanX;
2239 span[1] = spanY;
2240 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2241 container, screenId, cell, span);
2242 break;
2243 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2244 processShortcutFromDrop(info.componentName, container, screenId, cell);
2245 break;
2246 default:
2247 throw new IllegalStateException("Unknown item type: " + info.itemType);
2248 }
2249 }
2250
Adam Cohenfbba09b2011-07-18 21:43:05 -07002251 /**
2252 * Process a shortcut drop.
2253 *
2254 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002255 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002256 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002258 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2259 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002260 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002261 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002262 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002263
2264 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002265 mPendingAddInfo.cellX = cell[0];
2266 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002267 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002268
2269 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2270 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002271 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002272 }
2273
Adam Cohenfbba09b2011-07-18 21:43:05 -07002274 /**
2275 * Process a widget drop.
2276 *
2277 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002278 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002279 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002280 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002281 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2282 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002283 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002284 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002285 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002286 mPendingAddInfo.minSpanX = info.minSpanX;
2287 mPendingAddInfo.minSpanY = info.minSpanY;
2288
Adam Cohenfbba09b2011-07-18 21:43:05 -07002289 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002290 mPendingAddInfo.cellX = cell[0];
2291 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002292 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002293 if (span != null) {
2294 mPendingAddInfo.spanX = span[0];
2295 mPendingAddInfo.spanY = span[1];
2296 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002297
Adam Cohened66b2b2012-01-23 17:28:51 -08002298 AppWidgetHostView hostView = info.boundWidget;
2299 int appWidgetId;
2300 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002301 // In the case where we've prebound the widget, we remove it from the DragLayer
2302 if (LOGD) {
2303 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2304 }
2305 getDragLayer().removeView(hostView);
2306
Adam Cohened66b2b2012-01-23 17:28:51 -08002307 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002308 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002309
2310 // Clear the boundWidget so that it doesn't get destroyed.
2311 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002312 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002313 // In this case, we either need to start an activity to get permission to bind
2314 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002315 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002316 Bundle options = info.bindOptions;
2317
Sunny Goyalffe83f12014-08-14 17:39:34 -07002318 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2319 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002320 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002321 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002322 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002323 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002324 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2325 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2326 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002327 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2328 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002329 // TODO: we need to make sure that this accounts for the options bundle.
2330 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002331 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2332 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002333 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002334 }
2335
Adam Cohendcd297f2013-06-18 13:13:40 -07002336 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002337 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002338 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 folderInfo.title = getText(R.string.folder_name);
2340
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002342 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2343 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002344 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002345
2346 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002347 FolderIcon newFolder =
2348 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002349 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002350 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002351 // Force measure the new folder icon
2352 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2353 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002354 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002355 }
Romain Guycbb89e42009-06-08 15:52:54 -07002356
Winsonc0b52fe2015-09-09 16:38:15 -07002357 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002358 * Unbinds the view for the specified item, and removes the item and all its children.
2359 *
2360 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002361 * @param itemInfo the {@link ItemInfo} for this view.
2362 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002363 */
Winson2949fb52015-09-24 09:56:11 -07002364 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002365 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002366 // Remove the shortcut from the folder before removing it from launcher
Winson2949fb52015-09-24 09:56:11 -07002367 FolderInfo folderInfo = sFolders.get(itemInfo.container);
2368 if (folderInfo != null) {
2369 folderInfo.remove((ShortcutInfo) itemInfo);
Winsonfa56b3f2015-09-14 12:01:13 -07002370 } else {
2371 mWorkspace.removeWorkspaceItem(v);
2372 }
Winsonc0b52fe2015-09-09 16:38:15 -07002373 if (deleteFromDb) {
2374 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2375 }
2376 } else if (itemInfo instanceof FolderInfo) {
2377 final FolderInfo folderInfo = (FolderInfo) itemInfo;
2378 unbindFolder(folderInfo);
2379 mWorkspace.removeWorkspaceItem(v);
2380 if (deleteFromDb) {
2381 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2382 }
2383 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2384 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002385 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002386 removeWidgetToAutoAdvance(widgetInfo.hostView);
2387 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002388 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002389 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002390 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002391
Winsonc0b52fe2015-09-09 16:38:15 -07002392 } else {
2393 return false;
2394 }
2395 return true;
2396 }
2397
2398 /**
2399 * Unbinds any launcher references to the folder.
2400 */
2401 private void unbindFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002402 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002403 }
2404
Winsonc0b52fe2015-09-09 16:38:15 -07002405 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002406 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002407 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002408 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002409 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002410 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002411 // Deleting an app widget ID is a void call but writes to disk before returning
2412 // to the caller...
2413 new AsyncTask<Void, Void, Void>() {
2414 public Void doInBackground(Void ... args) {
2415 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2416 return null;
2417 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002418 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002419 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002420 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002421 }
2422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002423 @Override
2424 public boolean dispatchKeyEvent(KeyEvent event) {
2425 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2426 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002427 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002428 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002429 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002430 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002431 dumpState();
2432 return true;
2433 }
2434 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002435 }
2436 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2437 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002438 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002439 return true;
2440 }
2441 }
2442
2443 return super.dispatchKeyEvent(event);
2444 }
2445
Joe Onorato88ec0992009-11-19 13:16:06 -08002446 @Override
2447 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002448 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2449 return;
2450 }
2451
Sunny Goyal45478022015-06-08 16:52:41 -07002452 if (mDragController.isDragging()) {
2453 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002454 return;
2455 }
2456
Winson Chungb745afb2015-03-02 11:51:23 -08002457 if (isAppsViewVisible()) {
2458 showWorkspace(true);
2459 } else if (isWidgetsViewVisible()) {
2460 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002461 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002462 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002463 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002464 Folder openFolder = mWorkspace.getOpenFolder();
2465 if (openFolder.isEditingName()) {
2466 openFolder.dismissEditingName();
2467 } else {
2468 closeFolder();
2469 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002470 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002471 mWorkspace.exitWidgetResizeMode();
2472
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002473 // Back button is a no-op here, but give at least some feedback for the button press
2474 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002475 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002476 }
2477
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002478 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002479 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002480 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002481 @Override
2482 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002483 if (mAppWidgetHost != null) {
2484 mAppWidgetHost.startListening();
2485 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002486
2487 // Recreate the QSB, as the widget has been reset.
2488 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002489 }
2490
2491 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002492 * Launches the intent referred by the clicked shortcut.
2493 *
2494 * @param v The view representing the clicked shortcut.
2495 */
2496 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002497 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2498 // view has detached (it's possible for this to happen if the view is removed mid touch).
2499 if (v.getWindowToken() == null) {
2500 return;
2501 }
2502
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002503 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002504 return;
2505 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002506
Adam Cohen1697b792013-09-17 19:08:21 -07002507 if (v instanceof Workspace) {
2508 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002509 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002510 }
2511 return;
2512 }
2513
2514 if (v instanceof CellLayout) {
2515 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002516 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2517 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002518 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002519 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002520 }
2521
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002522 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002523 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002524 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002525 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002526 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002527 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002528 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002529 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002530 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002531 } else if (tag instanceof AppInfo) {
2532 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002533 } else if (tag instanceof LauncherAppWidgetInfo) {
2534 if (v instanceof PendingAppWidgetHostView) {
2535 onClickPendingWidget((PendingAppWidgetHostView) v);
2536 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002537 }
2538 }
2539
Sunny Goyal70660032015-05-14 00:07:08 -07002540 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002541 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002542 return false;
2543 }
2544
Michael Jurkaaf442092010-06-10 17:01:57 -07002545 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002546 * Event handler for the app widget view which has not fully restored.
2547 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002548 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002549 if (mIsSafeModeEnabled) {
2550 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2551 return;
2552 }
2553
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002554 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002555 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002556 int widgetId = info.appWidgetId;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002557 LauncherAppWidgetProviderInfo appWidgetInfo =
2558 mAppWidgetManager.getLauncherAppWidgetInfo(widgetId);
Sunny Goyalff572272014-07-23 13:58:07 -07002559 if (appWidgetInfo != null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08002560 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002561 mPendingAddInfo.copyFrom(info);
2562 mPendingAddWidgetId = widgetId;
2563
Sunny Goyalffe83f12014-08-14 17:39:34 -07002564 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2565 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002566 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002567 } else if (info.installProgress < 0) {
2568 // The install has not been queued
2569 final String packageName = info.providerName.getPackageName();
2570 showBrokenAppInstallDialog(packageName,
2571 new DialogInterface.OnClickListener() {
2572 public void onClick(DialogInterface dialog, int id) {
2573 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2574 }
2575 });
2576 } else {
2577 // Download has started.
2578 final String packageName = info.providerName.getPackageName();
2579 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002580 }
2581 }
2582
2583 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002584 * Event handler for the "grid" button that appears on the home screen, which
2585 * enters all apps mode.
2586 *
2587 * @param v The view that was clicked.
2588 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002589 protected void onClickAllAppsButton(View v) {
2590 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002591 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002592 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002593 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002594
2595 if (mLauncherCallbacks != null) {
2596 mLauncherCallbacks.onClickAllAppsButton(v);
2597 }
Winson Chung76648c52015-07-10 14:33:23 -07002598 }
2599 }
2600
2601 protected void onLongClickAllAppsButton(View v) {
2602 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2603 if (!isAppsViewVisible()) {
2604 showAppsView(true /* animated */, false /* resetListToTop */,
2605 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002606 }
2607 }
2608
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002609 private void showBrokenAppInstallDialog(final String packageName,
2610 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002611 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002612 .setTitle(R.string.abandoned_promises_title)
2613 .setMessage(R.string.abandoned_promise_explanation)
2614 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2615 .setNeutralButton(R.string.abandoned_clean_this,
2616 new DialogInterface.OnClickListener() {
2617 public void onClick(DialogInterface dialog, int id) {
2618 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2619 mWorkspace.removeAbandonedPromise(packageName, user);
2620 }
2621 })
2622 .create().show();
2623 return;
2624 }
2625
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002626 /**
2627 * Event handler for an app shortcut click.
2628 *
2629 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2630 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002631 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002632 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2633 Object tag = v.getTag();
2634 if (!(tag instanceof ShortcutInfo)) {
2635 throw new IllegalArgumentException("Input must be a Shortcut");
2636 }
2637
2638 // Open shortcut
2639 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002640
2641 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002642 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2643 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002644 // Launch activity anyway, framework will tell the user why the app is suspended.
2645 } else {
2646 int error = R.string.activity_not_available;
2647 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2648 error = R.string.safemode_shortcut_error;
2649 }
2650 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2651 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002652 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002653 }
2654
Chris Wren40c5ed32014-06-24 18:24:23 -04002655 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002656 if ((v instanceof BubbleTextView)
2657 && shortcut.isPromise()
2658 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002659 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002660 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002661 new DialogInterface.OnClickListener() {
2662 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002663 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002664 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002665 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002666 return;
2667 }
2668
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002669 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002670 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002671
2672 if (mLauncherCallbacks != null) {
2673 mLauncherCallbacks.onClickAppShortcut(v);
2674 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002675 }
2676
Adam Cohen091440a2015-03-18 14:16:05 -07002677 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002678 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002679 final ShortcutInfo shortcut;
2680 final Intent intent;
2681 if (tag instanceof ShortcutInfo) {
2682 shortcut = (ShortcutInfo) tag;
2683 intent = shortcut.intent;
2684 int[] pos = new int[2];
2685 v.getLocationOnScreen(pos);
2686 intent.setSourceBounds(new Rect(pos[0], pos[1],
2687 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002688
Sunny Goyal508da152014-08-14 10:53:27 -07002689 } else if (tag instanceof AppInfo) {
2690 shortcut = null;
2691 intent = ((AppInfo) tag).intent;
2692 } else {
2693 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2694 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002695
2696 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002697 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002698
2699 if (success && v instanceof BubbleTextView) {
2700 mWaitingForResume = (BubbleTextView) v;
2701 mWaitingForResume.setStayPressed(true);
2702 }
2703 }
2704
2705 /**
2706 * Event handler for a folder icon click.
2707 *
2708 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2709 */
2710 protected void onClickFolderIcon(View v) {
2711 if (LOGD) Log.d(TAG, "onClickFolder");
2712 if (!(v instanceof FolderIcon)){
2713 throw new IllegalArgumentException("Input must be a FolderIcon");
2714 }
2715
2716 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002717 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002718 // Open the requested folder
Sunny Goyal08442b82015-10-21 17:15:08 -07002719 openFolder(folderIcon, true);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002720 }
Adam Cohen9211d422014-10-07 18:14:53 -07002721
2722 if (mLauncherCallbacks != null) {
2723 mLauncherCallbacks.onClickFolderIcon(v);
2724 }
Michael Jurka5130e402011-10-13 04:55:35 -07002725 }
2726
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002727 /**
2728 * Event handler for the (Add) Widgets button that appears after a long press
2729 * on the home screen.
2730 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002731 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002732 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002733 if (mIsSafeModeEnabled) {
2734 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2735 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002736 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002737 if (mLauncherCallbacks != null) {
2738 mLauncherCallbacks.onClickAddWidgetButton(view);
2739 }
Adam Cohen9211d422014-10-07 18:14:53 -07002740 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002741 }
2742
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002743 /**
2744 * Event handler for the wallpaper picker button that appears after a long press
2745 * on the home screen.
2746 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002747 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002748 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002749 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2750 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
2751 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
Sunny Goyal6f866092016-03-17 17:04:15 -07002752 .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset),
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002753 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002754
2755 if (mLauncherCallbacks != null) {
2756 mLauncherCallbacks.onClickWallpaperPicker(v);
2757 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002758 }
2759
2760 /**
2761 * Event handler for a click on the settings button that appears after a long press
2762 * on the home screen.
2763 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002764 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002765 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002766 if (mLauncherCallbacks != null) {
2767 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002768 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002769 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002770 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002771 }
2772
Adam Cohen61f560d2013-09-30 15:58:20 -07002773 public View.OnTouchListener getHapticFeedbackTouchListener() {
2774 if (mHapticFeedbackTouchListener == null) {
2775 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002776 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002777 @Override
2778 public boolean onTouch(View v, MotionEvent event) {
2779 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2780 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2781 }
2782 return false;
2783 }
2784 };
2785 }
2786 return mHapticFeedbackTouchListener;
2787 }
2788
Adam Cohen9211d422014-10-07 18:14:53 -07002789 public void onDragStarted(View view) {
2790 if (isOnCustomContent()) {
2791 // Custom content screen doesn't participate in drag and drop. If on custom
2792 // content screen, move to default.
2793 moveWorkspaceToDefaultScreen();
2794 }
2795
2796 if (mLauncherCallbacks != null) {
2797 mLauncherCallbacks.onDragStarted(view);
2798 }
2799 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002800
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002801 /**
2802 * Called when the user stops interacting with the launcher.
2803 * This implies that the user is now on the homescreen and is not doing housekeeping.
2804 */
Adam Cohen9211d422014-10-07 18:14:53 -07002805 protected void onInteractionEnd() {
2806 if (mLauncherCallbacks != null) {
2807 mLauncherCallbacks.onInteractionEnd();
2808 }
2809 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002810
2811 /**
2812 * Called when the user starts interacting with the launcher.
2813 * The possible interactions are:
2814 * - open all apps
2815 * - reorder an app shortcut, or a widget
2816 * - open the overview mode.
2817 * This is a good time to stop doing things that only make sense
2818 * when the user is on the homescreen and not doing housekeeping.
2819 */
Adam Cohen9211d422014-10-07 18:14:53 -07002820 protected void onInteractionBegin() {
2821 if (mLauncherCallbacks != null) {
2822 mLauncherCallbacks.onInteractionBegin();
2823 }
2824 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002825
Winson Chungcd99cd32015-04-29 11:03:24 -07002826 /** Updates the interaction state. */
2827 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002828 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002829 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002830 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2831 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002832 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002833 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002834 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002835 onInteractionEnd();
2836 }
2837 }
2838
Kenny Guyf07af7b2014-07-31 11:39:16 +01002839 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002840 try {
2841 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002842 launcherApps.showAppDetailsForProfile(componentName, user);
2843 } catch (SecurityException e) {
2844 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2845 Log.e(TAG, "Launcher does not have permission to launch settings");
2846 } catch (ActivityNotFoundException e) {
2847 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2848 Log.e(TAG, "Unable to launch settings");
2849 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002850 }
2851
Michael Jurka1e2f4652013-07-08 18:03:46 -07002852 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002853 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2854 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002855 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002856 // System applications cannot be installed. For now, show a toast explaining that.
2857 // We may give them the option of disabling apps this way.
2858 int messageId = R.string.uninstall_system_app_text;
2859 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002860 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002861 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002862 String packageName = componentName.getPackageName();
2863 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002864 Intent intent = new Intent(
2865 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002866 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2867 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002868 if (user != null) {
2869 user.addToIntent(intent, Intent.EXTRA_USER);
2870 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002871 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002872 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002873 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002874 }
2875
Winson Chung8f1eff72015-05-28 17:33:40 -07002876 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002877 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002878 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002879 // Only launch using the new animation if the shortcut has not opted out (this is a
2880 // private contract between launcher and may be ignored in the future).
2881 boolean useLaunchAnimation = (v != null) &&
2882 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002883 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2884 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002885
Kenny Guy1317e2d2014-05-08 18:52:50 +01002886 UserHandleCompat user = null;
2887 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2888 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2889 user = userManager.getUserForSerialNumber(serialNumber);
2890 }
2891
2892 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002893 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002894 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002895 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002896 int left = 0, top = 0;
2897 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2898 if (v instanceof TextView) {
2899 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002900 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2901 if (icon != null) {
2902 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002903 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002904 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002905 width = bounds.width();
2906 height = bounds.height();
2907 }
2908 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002909 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2910 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002911 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002912 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002913 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002914 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002915 // On L devices, we use the device default slide-up transition.
2916 // On L MR1 devices, we a custom version of the slide-up transition which
2917 // doesn't have the delay present in the device default.
2918 opts = ActivityOptions.makeCustomAnimation(this,
2919 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002920 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002921 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002922 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002923
2924 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2925 // Could be launching some bookkeeping activity
2926 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002927 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002928 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002929 launcherApps.startActivityForProfile(intent.getComponent(), user,
2930 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002931 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002932 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002933 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002934 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2935 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2936 // corresponding permission. Show the appropriate permission prompt if that
2937 // is the case.
2938 if (intent.getComponent() == null
2939 && Intent.ACTION_CALL.equals(intent.getAction())
2940 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2941 PackageManager.PERMISSION_GRANTED) {
2942 // TODO: Rename sPendingAddItem to a generic name.
2943 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2944 0, (ItemInfo) tag);
2945 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2946 REQUEST_PERMISSION_CALL_PHONE);
2947 return false;
2948 }
2949 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002950 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002951 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002952 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002953 "or use the exported attribute for this activity. "
2954 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002955 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002956 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002957 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002958
Winson Chungbedf9232015-07-10 12:38:30 -07002959 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002960 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002961 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2962 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2963 return false;
2964 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002965 try {
2966 success = startActivity(v, intent, tag);
2967 } catch (ActivityNotFoundException e) {
2968 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2969 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2970 }
2971 return success;
2972 }
2973
Adam Cohen268c4752012-06-06 17:47:33 -07002974 /**
2975 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2976 * in the DragLayer in the exact absolute location of the original FolderIcon.
2977 */
2978 private void copyFolderIconToImage(FolderIcon fi) {
2979 final int width = fi.getMeasuredWidth();
2980 final int height = fi.getMeasuredHeight();
2981
2982 // Lazy load ImageView, Bitmap and Canvas
2983 if (mFolderIconImageView == null) {
2984 mFolderIconImageView = new ImageView(this);
2985 }
2986 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2987 mFolderIconBitmap.getHeight() != height) {
2988 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2989 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2990 }
2991
2992 DragLayer.LayoutParams lp;
2993 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2994 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2995 } else {
2996 lp = new DragLayer.LayoutParams(width, height);
2997 }
2998
Adam Cohen307fe232012-08-16 17:55:58 -07002999 // The layout from which the folder is being opened may be scaled, adjust the starting
3000 // view size by this scale factor.
3001 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003002 lp.customPosition = true;
3003 lp.x = mRectForFolderAnimation.left;
3004 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003005 lp.width = (int) (scale * width);
3006 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003007
3008 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3009 fi.draw(mFolderIconCanvas);
3010 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003011 if (fi.getFolder() != null) {
3012 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3013 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003014 }
Adam Cohen268c4752012-06-06 17:47:33 -07003015 // Just in case this image view is still in the drag layer from a previous animation,
3016 // we remove it and re-add it.
3017 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3018 mDragLayer.removeView(mFolderIconImageView);
3019 }
3020 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003021 if (fi.getFolder() != null) {
3022 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003023 }
Adam Cohen268c4752012-06-06 17:47:33 -07003024 }
3025
Sunny Goyal08442b82015-10-21 17:15:08 -07003026 private void growAndFadeOutFolderIcon(FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003027 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003028 FolderInfo info = (FolderInfo) fi.getTag();
3029 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3030 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003031 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3032 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003033 }
3034
Adam Cohen268c4752012-06-06 17:47:33 -07003035 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3036 copyFolderIconToImage(fi);
3037 fi.setVisibility(View.INVISIBLE);
3038
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003039 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3040 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003041 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003042 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3043 }
3044 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003045 oa.start();
Sunny Goyal08442b82015-10-21 17:15:08 -07003046 if (!animate) {
Tony Wickham112ac952015-11-12 12:31:50 -08003047 oa.end();
3048 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003049 }
3050
Sunny Goyal935fca12015-10-13 10:19:01 -07003051 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003052 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003053 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003054
Adam Cohen268c4752012-06-06 17:47:33 -07003055 // We remove and re-draw the FolderIcon in-case it has changed
3056 mDragLayer.removeView(mFolderIconImageView);
3057 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08003058
3059 if (cl != null) {
3060 cl.clearFolderLeaveBehind();
3061 }
3062
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003063 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003064 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003065 oa.addListener(new AnimatorListenerAdapter() {
3066 @Override
3067 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003068 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003069 // Remove the ImageView copy of the FolderIcon and make the original visible.
3070 mDragLayer.removeView(mFolderIconImageView);
3071 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003072 }
3073 }
3074 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003075 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003076 if (!animate) {
3077 oa.end();
3078 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003079 }
3080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003081 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003082 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003083 * is animated relative to the specified View. If the View is null, no animation
3084 * is played.
3085 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003086 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003087 */
Sunny Goyal08442b82015-10-21 17:15:08 -07003088 public void openFolder(FolderIcon folderIcon, boolean animate) {
3089 animate &= !Utilities.isPowerSaverOn(this);
3090
Adam Cohenfb91f302012-06-11 15:45:18 -07003091 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003092 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3093 if (openFolder != null && openFolder != folder) {
3094 // Close any open folder before opening a folder.
3095 closeFolder();
3096 }
3097
Adam Cohena9cf38f2011-05-02 15:36:58 -07003098 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003099
Adam Cohena9cf38f2011-05-02 15:36:58 -07003100 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003101
Sunny Goyalf4066152015-04-15 09:42:19 -07003102 // While the folder is open, the position of the icon cannot change.
3103 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3104
Adam Cohen4554ee12011-08-03 16:13:21 -07003105 // Just verify that the folder hasn't already been added to the DragLayer.
3106 // There was a one-off crash where the folder had a parent already.
3107 if (folder.getParent() == null) {
3108 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003109 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003110 } else {
3111 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3112 folder.getParent() + ").");
3113 }
Sunny Goyal08442b82015-10-21 17:15:08 -07003114 if (animate) {
3115 folder.animateOpen();
3116 } else {
3117 folder.open();
3118 }
3119 growAndFadeOutFolderIcon(folderIcon, animate);
Winson Chung83ca4802013-04-12 15:10:52 -07003120
3121 // Notify the accessibility manager that this folder "window" has appeared and occluded
3122 // the workspace items
3123 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3124 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003125 }
3126
3127 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003128 closeFolder(true);
3129 }
3130
3131 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003132 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003133 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003134 if (folder.isEditingName()) {
3135 folder.dismissEditingName();
3136 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003137 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003138 }
3139 }
3140
Sunny Goyal935fca12015-10-13 10:19:01 -07003141 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003142 animate &= !Utilities.isPowerSaverOn(this);
3143
Adam Cohen4554ee12011-08-03 16:13:21 -07003144 folder.getInfo().opened = false;
3145
3146 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3147 if (parent != null) {
3148 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003149 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003150 if (fi != null) {
3151 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3152 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003153 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003154 if (animate) {
3155 folder.animateClosed();
3156 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003157 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003158 }
Winson Chung83ca4802013-04-12 15:10:52 -07003159
Sunny Goyal935fca12015-10-13 10:19:01 -07003160 // Notify the accessibility manager that this folder "window" has disappeared and no
3161 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003162 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003163 }
3164
Tony Wickhamdadb3042016-02-24 11:07:00 -08003165 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003166 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003167 if (!isDraggingEnabled()) return false;
3168 if (isWorkspaceLocked()) return false;
3169 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003170
Winson Chung76648c52015-07-10 14:33:23 -07003171 if (v == mAllAppsButton) {
3172 onLongClickAllAppsButton(v);
3173 return true;
3174 }
3175
Adam Cohen1697b792013-09-17 19:08:21 -07003176 if (v instanceof Workspace) {
3177 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003178 if (!mWorkspace.isTouchActive()) {
3179 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003180 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3181 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3182 return true;
3183 } else {
3184 return false;
3185 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003186 } else {
3187 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003188 }
Adam Cohen1697b792013-09-17 19:08:21 -07003189 }
3190
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003191 CellLayout.CellInfo longClickCellInfo = null;
3192 View itemUnderLongClick = null;
3193 if (v.getTag() instanceof ItemInfo) {
3194 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003195 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003196 itemUnderLongClick = longClickCellInfo.cell;
3197 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003198 }
3199
Winson Chung3d503fb2011-07-13 17:25:49 -07003200 // The hotseat touch handling does not go through Workspace, and we always allow long press
3201 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003202 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003203 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003204 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003205 // User long pressed on empty space
3206 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3207 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003208 if (mWorkspace.isInOverviewMode()) {
3209 mWorkspace.startReordering(v);
3210 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003211 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003213 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003214 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3215 mHotseat.getOrderInHotseat(
3216 longClickCellInfo.cellX,
3217 longClickCellInfo.cellY));
3218 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003219 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003220 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003221 }
3222 }
3223 }
3224 return true;
3225 }
3226
Winson Chung3d503fb2011-07-13 17:25:49 -07003227 boolean isHotseatLayout(View layout) {
3228 return mHotseat != null && layout != null &&
3229 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3230 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003231
Winson Chung3d503fb2011-07-13 17:25:49 -07003232 /**
3233 * Returns the CellLayout of the specified container at the specified screen.
3234 */
Sunny Goyal92820592015-03-02 11:31:35 -08003235 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003236 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3237 if (mHotseat != null) {
3238 return mHotseat.getLayout();
3239 } else {
3240 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003241 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003242 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003243 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003244 }
3245 }
3246
Winson Chungb745afb2015-03-02 11:51:23 -08003247 /**
3248 * For overridden classes.
3249 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003250 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003251 return isAppsViewVisible();
3252 }
3253
3254 public boolean isAppsViewVisible() {
3255 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3256 }
3257
3258 public boolean isWidgetsViewVisible() {
3259 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003260 }
3261
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003262 private void setWorkspaceBackground(int background) {
3263 switch (background) {
3264 case WORKSPACE_BACKGROUND_TRANSPARENT:
3265 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3266 break;
3267 case WORKSPACE_BACKGROUND_BLACK:
3268 getWindow().setBackgroundDrawable(null);
3269 break;
3270 default:
3271 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3272 }
Craig Mautner360310b2012-10-26 15:13:08 -07003273 }
3274
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003275 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003276 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3277 int curflags = getWindow().getAttributes().flags
3278 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3279 if (wpflags != curflags) {
3280 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3281 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003282 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003283 }
3284
Michael Jurkae326f182011-11-21 14:05:46 -08003285 @Override
3286 public void onTrimMemory(int level) {
3287 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003288 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3289 // The widget preview db can result in holding onto over
3290 // 3MB of memory for caching which isn't necessary.
3291 SQLiteDatabase.releaseMemory();
3292
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003293 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003294 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003295 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003296 if (mLauncherCallbacks != null) {
3297 mLauncherCallbacks.onTrimMemory(level);
3298 }
Michael Jurkae326f182011-11-21 14:05:46 -08003299 }
3300
Winson5c6bdbb2015-09-03 11:36:19 -07003301 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003302 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003303 }
3304
Winson5c6bdbb2015-09-03 11:36:19 -07003305 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003306 boolean changed = mState != State.WORKSPACE ||
3307 mWorkspace.getState() != Workspace.State.NORMAL;
3308 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003309 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003310 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003311 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003312
Michael Jurkab3e22d92011-10-31 15:58:33 -07003313 // Set focus to the AppsCustomize button
3314 if (mAllAppsButton != null) {
3315 mAllAppsButton.requestFocus();
3316 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003317 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003318
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003319 // Change the state *after* we've called all the transition code
3320 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003321
Winson Chung5fb63472011-02-02 17:03:37 -08003322 // Resume the auto-advance of widgets
3323 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003324 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003325
Winson Chung0f785722015-04-08 10:27:49 -07003326 if (changed) {
3327 // Send an accessibility event to announce the context change
3328 getWindow().getDecorView()
3329 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003330 }
Winson5c6bdbb2015-09-03 11:36:19 -07003331 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003332 }
3333
Winsone9f27272015-10-13 10:47:51 -07003334 /**
3335 * Shows the overview button.
3336 */
Adam Cohened307df2013-10-02 09:37:31 -07003337 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003338 showOverviewMode(animated, false);
3339 }
3340
3341 /**
3342 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3343 * onto one of the overview panel buttons.
3344 */
3345 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3346 Runnable postAnimRunnable = null;
3347 if (requestButtonFocus) {
3348 postAnimRunnable = new Runnable() {
3349 @Override
3350 public void run() {
3351 // Hitting the menu button when in touch mode does not trigger touch mode to
3352 // be disabled, so if requested, force focus on one of the overview panel
3353 // buttons.
3354 mOverviewPanel.requestFocusFromTouch();
3355 }
3356 };
3357 }
Adam Cohened307df2013-10-02 09:37:31 -07003358 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003359 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003360 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003361 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003362 }
3363
Winson Chungb745afb2015-03-02 11:51:23 -08003364 /**
3365 * Shows the apps view.
3366 */
Winson Chung76648c52015-07-10 14:33:23 -07003367 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3368 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003369 if (resetListToTop) {
3370 mAppsView.scrollToTop();
3371 }
Winson Chung4ac30062015-05-08 17:34:17 -07003372 if (updatePredictedApps) {
3373 tryAndUpdatePredictedApps();
3374 }
Winson Chung76648c52015-07-10 14:33:23 -07003375 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003376 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003377
Winson Chungb745afb2015-03-02 11:51:23 -08003378 /**
3379 * Shows the widgets view.
3380 */
3381 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003382 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003383 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003384 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003385 }
Winson Chung76648c52015-07-10 14:33:23 -07003386 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003387
3388 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003389 @Override
3390 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003391 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003392 }
3393 });
Winson Chungb745afb2015-03-02 11:51:23 -08003394 }
3395
3396 /**
3397 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003398 *
3399 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003400 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003401 // TODO: calling method should use the return value so that when {@code false} is returned
3402 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003403 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003404 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3405 mState != State.WIDGETS_SPRING_LOADED) {
3406 return false;
3407 }
3408 if (toState != State.APPS && toState != State.WIDGETS) {
3409 return false;
3410 }
Winson Chungb745afb2015-03-02 11:51:23 -08003411
3412 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003413 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3414 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003415 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003416 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003417 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003418
Michael Jurkab3e22d92011-10-31 15:58:33 -07003419 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003420 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003421
3422 // Pause the auto-advance of widgets until we are out of AllApps
3423 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003424 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003425 closeFolder();
3426
3427 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003428 getWindow().getDecorView()
3429 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003430 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003431 }
3432
Winson Chungcd99cd32015-04-29 11:03:24 -07003433 /**
3434 * Updates the workspace and interaction state on state change, and return the animation to this
3435 * new state.
3436 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003437 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003438 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003439 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003440 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003441 updateInteraction(fromState, toState);
3442 return anim;
3443 }
3444
Jun Mukaif0033da2015-08-04 18:34:30 -07003445 public void onLauncherClingShown() {
3446 // When a launcher cling appears, it should cover the underlying layers, so their focus
3447 // should be blocked.
3448 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3449 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3450 }
3451 }
3452
3453 public void onLauncherClingDismissed() {
3454 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3455 }
3456
Hyunyoung Song3f471442015-04-08 19:01:34 -07003457 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003458 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003459 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003460 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003461 }
Winson Chungb745afb2015-03-02 11:51:23 -08003462
Winson Chung006ee262015-08-03 14:40:11 -07003463 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003464 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003465 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003466
3467 if (isAppsViewVisible()) {
3468 mState = State.APPS_SPRING_LOADED;
3469 } else if (isWidgetsViewVisible()) {
3470 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003471 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003472 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003473 } else {
3474 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003475 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003476 }
Adam Cohen7777d962011-08-18 18:58:38 -07003477
Hyunyoung Song3f471442015-04-08 19:01:34 -07003478 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003479 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003480 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003481
Winson Chunge7a03942011-08-05 15:05:12 -07003482 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003483 @Override
3484 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003485 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003486 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3487 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003488 // Before we show workspace, hide all apps again because
3489 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3490 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003491 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003492 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003493 } else {
3494 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003495 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003496 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003497 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003498 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003499
Tony Wickhame0c33232016-02-08 11:37:04 -08003500 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003501 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3502 || mState == State.WIDGETS_SPRING_LOADED;
3503 }
3504
Michael Jurkad3ef3062010-11-23 16:23:58 -08003505 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003506 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003507 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003508 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003509 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003510 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003511 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3512 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003513 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003514 }
3515
Winson Chung4ac30062015-05-08 17:34:17 -07003516 /**
3517 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3518 * resumed.
3519 */
3520 private void tryAndUpdatePredictedApps() {
3521 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003522 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003523 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003524 mAppsView.setPredictedApps(apps);
3525 }
3526 }
3527 }
3528
Michael Jurkab3e22d92011-10-31 15:58:33 -07003529 void lockAllApps() {
3530 // TODO
3531 }
3532
3533 void unlockAllApps() {
3534 // TODO
3535 }
3536
Winsonf768d932015-09-25 16:12:35 -07003537 public boolean launcherCallbacksProvidesSearch() {
3538 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3539 }
3540
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003541 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003542 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003543 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003544 }
3545
Adam Cohen24ce0b32014-01-14 16:18:14 -08003546 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003547 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3548 if (searchProvider == null) {
3549 return null;
3550 }
3551
3552 Bundle opts = new Bundle();
3553 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003554 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003555
Tony Wickham3a3517f2015-10-06 11:27:04 -07003556 // Determine the min and max dimensions of the widget.
3557 LauncherAppState app = LauncherAppState.getInstance();
3558 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3559 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3560 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003561 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3562 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003563 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003564 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003565 int minWidth = maxWidth;
3566 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003567 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3568 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3569 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3570 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3571 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003572 }
3573 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3574 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3575 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3576 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003577 if (LOGD) {
3578 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3579 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3580 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003581
Tony Wickham775455c2015-10-16 09:49:32 -07003582 if (mLauncherCallbacks != null) {
3583 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3584 }
3585
Sunny Goyalf7258242015-10-19 16:59:07 -07003586 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003587 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003588 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003589 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003590 || (widgetInfo == null)
3591 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003592 // A valid widget is not already bound.
3593 if (widgetId > -1) {
3594 mAppWidgetHost.deleteAppWidgetId(widgetId);
3595 widgetId = -1;
3596 }
3597
3598 // Try to bind a new widget
3599 widgetId = mAppWidgetHost.allocateAppWidgetId();
3600
3601 if (!AppWidgetManagerCompat.getInstance(this)
3602 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3603 mAppWidgetHost.deleteAppWidgetId(widgetId);
3604 widgetId = -1;
3605 }
3606
Sunny Goyalf7258242015-10-19 16:59:07 -07003607 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003608 .putInt(QSB_WIDGET_ID, widgetId)
3609 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003610 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003611 }
3612
Sunny Goyal8d595092015-07-06 12:22:14 -07003613 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003614 if (widgetId != -1) {
3615 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003616 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003617 mQsb.updateAppWidgetOptions(opts);
3618 mQsb.setPadding(0, 0, 0, 0);
3619 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003620 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003621 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003622 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003623 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003624 }
3625
Sunny Goyal22235bc2015-04-03 09:23:43 -07003626 private void reinflateQSBIfNecessary() {
3627 if (mQsb instanceof LauncherAppWidgetHostView &&
3628 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3629 mSearchDropTargetBar.removeView(mQsb);
3630 mQsb = null;
3631 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3632 }
3633 }
3634
Michael Jurkad7c28052012-04-27 15:43:36 -07003635 @Override
3636 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003637 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003638 final List<CharSequence> text = event.getText();
3639 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003640 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003641 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003642 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003643 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003644 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003645 } else if (mWorkspace != null) {
3646 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003647 } else {
3648 text.add(getString(R.string.all_apps_home_button_label));
3649 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003650 return result;
3651 }
3652
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003653 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003654 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003655 */
Adam Cohen091440a2015-03-18 14:16:05 -07003656 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003657 @Override
3658 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003659 closeSystemDialogs();
3660 }
3661 }
3662
3663 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003664 * If the activity is currently paused, signal that we need to run the passed Runnable
3665 * in onResume.
3666 *
3667 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003668 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3669 * wrong when we're not running, and if the activity comes back to what the configuration was
3670 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003671 *
3672 * Implementation of the method from LauncherModel.Callbacks.
3673 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003674 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003675 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003676 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003677 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003678 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003679 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003680 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003681 }
3682 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003683 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003684 return true;
3685 } else {
3686 return false;
3687 }
3688 }
3689
Michael Jurkac402cd92013-05-20 15:49:32 +02003690 private boolean waitUntilResume(Runnable run) {
3691 return waitUntilResume(run, false);
3692 }
3693
Michael Jurka1e2f4652013-07-08 18:03:46 -07003694 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003695 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003696 }
3697
Michael Jurka7607c2f2013-04-03 14:33:19 -07003698 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003699 * If the activity is currently paused, signal that we need to re-run the loader
3700 * in onResume.
3701 *
3702 * This needs to be called from incoming places where resources might have been loaded
3703 * while we are paused. That is becaues the Configuration might be wrong
3704 * when we're not running, and if it comes back to what it was when we
3705 * were paused, we are not restarted.
3706 *
3707 * Implementation of the method from LauncherModel.Callbacks.
3708 *
3709 * @return true if we are currently paused. The caller might be able to
3710 * skip some work in that case since we will come back again.
3711 */
3712 public boolean setLoadOnResume() {
3713 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003714 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003715 mOnResumeNeedsLoad = true;
3716 return true;
3717 } else {
3718 return false;
3719 }
3720 }
3721
3722 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003723 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003724 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003725 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003726 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003727 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003728 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003729 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003730 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003731 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003732
Joe Onorato9c1289c2009-08-17 11:03:03 -04003733 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003734 * Clear any pending bind callbacks. This is called when is loader is planning to
3735 * perform a full rebind from scratch.
3736 */
3737 @Override
3738 public void clearPendingBinds() {
3739 mBindOnResumeCallbacks.clear();
3740 if (mPendingExecutor != null) {
3741 mPendingExecutor.markCompleted();
3742 mPendingExecutor = null;
3743 }
3744 }
3745
3746 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 * Refreshes the shortcuts shown on the workspace.
3748 *
3749 * Implementation of the method from LauncherModel.Callbacks.
3750 */
3751 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003752 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003753
Winson Chungd64d1762013-08-20 14:37:16 -07003754 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003755 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003756 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003757
Michael Jurka05bf644e2011-11-30 20:28:53 -08003758 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003759 if (mHotseat != null) {
3760 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003761 }
3762 }
3763
Adam Cohendcd297f2013-06-18 13:13:40 -07003764 @Override
3765 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003766 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003767
Adam Cohen5084cba2013-09-03 12:01:16 -07003768 // If there are no screens, we need to have an empty screen
3769 if (orderedScreenIds.size() == 0) {
3770 mWorkspace.addExtraEmptyScreen();
3771 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003772
3773 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003774 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003775 if (hasCustomContentToLeft()) {
3776 mWorkspace.createCustomContentContainer();
3777 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003778 }
Winson Chung64359a52013-07-08 17:17:08 -07003779 }
3780
3781 @Override
3782 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003783 int count = orderedScreenIds.size();
3784 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003785 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003786 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003787 }
3788
Winson Chungd64d1762013-08-20 14:37:16 -07003789 public void bindAppsAdded(final ArrayList<Long> newScreens,
3790 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003791 final ArrayList<ItemInfo> addAnimated,
3792 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003793 Runnable r = new Runnable() {
3794 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003795 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003796 }
3797 };
3798 if (waitUntilResume(r)) {
3799 return;
3800 }
3801
Winson Chungd64d1762013-08-20 14:37:16 -07003802 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003803 if (newScreens != null) {
3804 bindAddScreens(newScreens);
3805 }
Winson Chungd64d1762013-08-20 14:37:16 -07003806
3807 // We add the items without animation on non-visible pages, and with
3808 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003809 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003810 bindItems(addNotAnimated, 0,
3811 addNotAnimated.size(), false);
3812 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003813 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003814 bindItems(addAnimated, 0,
3815 addAnimated.size(), true);
3816 }
Winson Chungc58497e2013-09-03 17:48:37 -07003817
Winson Chung87412982013-10-03 18:34:14 -07003818 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003819 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003820
Winson Chungb745afb2015-03-02 11:51:23 -08003821 if (addedApps != null && mAppsView != null) {
3822 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003823 }
Winson Chungd64d1762013-08-20 14:37:16 -07003824 }
3825
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003826 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003827 * Bind the items start-end from the list.
3828 *
3829 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003830 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003831 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003832 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3833 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003834 Runnable r = new Runnable() {
3835 public void run() {
3836 bindItems(shortcuts, start, end, forceAnimateIcons);
3837 }
3838 };
3839 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003840 return;
3841 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003842
Winson Chungf0c6ae02012-03-21 16:10:31 -07003843 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003844 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3845 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003846 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003847 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003848 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003849 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003850 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003851
3852 // Short circuit if we are loading dock items for a configuration which has no dock
3853 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3854 mHotseat == null) {
3855 continue;
3856 }
3857
Sunny Goyal639e9062015-08-19 19:17:06 -07003858 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003859 switch (item.itemType) {
3860 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3861 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003862 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003863 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003864
Winson Chung64359a52013-07-08 17:17:08 -07003865 /*
3866 * TODO: FIX collision case
3867 */
Winson Chungce376632013-07-11 16:12:41 -07003868 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3869 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3870 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003871 View v = cl.getChildAt(item.cellX, item.cellY);
3872 Object tag = v.getTag();
3873 String desc = "Collision while binding workspace item: " + item
3874 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003875 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003876 throw (new RuntimeException(desc));
3877 } else {
3878 Log.d(TAG, desc);
3879 }
Winson Chungce376632013-07-11 16:12:41 -07003880 }
Winson Chung64359a52013-07-08 17:17:08 -07003881 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003882 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003883 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003884 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003885 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003886 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003887 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003888 default:
3889 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003890 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003891
3892 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3893 item.cellY, 1, 1);
3894 if (animateIcons) {
3895 // Animate all the applications up now
3896 view.setAlpha(0f);
3897 view.setScaleX(0f);
3898 view.setScaleY(0f);
3899 bounceAnims.add(createNewAppBounceAnimation(view, i));
3900 newShortcutsScreenId = item.screenId;
3901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003902 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003903
Winson Chung997a9232013-07-24 15:33:46 -07003904 if (animateIcons) {
3905 // Animate to the correct page
3906 if (newShortcutsScreenId > -1) {
3907 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003908 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003909 final Runnable startBounceAnimRunnable = new Runnable() {
3910 public void run() {
3911 anim.playTogether(bounceAnims);
3912 anim.start();
3913 }
3914 };
Winson Chung997a9232013-07-24 15:33:46 -07003915 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003916 // We post the animation slightly delayed to prevent slowdowns
3917 // when we are loading right after we return to launcher.
3918 mWorkspace.postDelayed(new Runnable() {
3919 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003920 if (mWorkspace != null) {
3921 mWorkspace.snapToPage(newScreenIndex);
3922 mWorkspace.postDelayed(startBounceAnimRunnable,
3923 NEW_APPS_ANIMATION_DELAY);
3924 }
Winson Chung94d67682013-09-25 16:29:40 -07003925 }
3926 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003927 } else {
3928 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003929 }
3930 }
Winson Chung64359a52013-07-08 17:17:08 -07003931 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003932 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003933 }
3934
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 /**
3936 * Implementation of the method from LauncherModel.Callbacks.
3937 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003938 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003939 Runnable r = new Runnable() {
3940 public void run() {
3941 bindFolders(folders);
3942 }
3943 };
3944 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003945 return;
3946 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003947 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003948 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003950 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3951 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3952 view.updateIcon(mIconCache);
3953 item.hostView = view;
3954 item.hostView.updateAppWidget(null);
3955 item.hostView.setOnClickListener(this);
3956 addAppWidgetToWorkspace(item, null, false);
3957 mWorkspace.requestLayout();
3958 }
3959
Joe Onorato9c1289c2009-08-17 11:03:03 -04003960 /**
3961 * Add the views for a widget to the workspace.
3962 *
3963 * Implementation of the method from LauncherModel.Callbacks.
3964 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003965 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003966 Runnable r = new Runnable() {
3967 public void run() {
3968 bindAppWidget(item);
3969 }
3970 };
3971 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003972 return;
3973 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003974
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003975 if (mIsSafeModeEnabled) {
3976 bindSafeModeWidget(item);
3977 return;
3978 }
3979
Daniel Sandler843e8602010-06-07 14:59:01 -04003980 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3981 if (DEBUG_WIDGETS) {
3982 Log.d(TAG, "bindAppWidget: " + item);
3983 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003984
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003985 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003986
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003987 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3988 // If the provider is not ready, bind as a pending widget.
3989 appWidgetInfo = null;
3990 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3991 // The widget id is not valid. Try to find the widget based on the provider info.
3992 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3993 } else {
3994 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3995 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003996
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003997 // If the provider is ready, but the width is not yet restored, try to restore it.
3998 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3999 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07004000 if (appWidgetInfo == null) {
4001 if (DEBUG_WIDGETS) {
4002 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4003 + " belongs to component " + item.providerName
4004 + ", as the povider is null");
4005 }
4006 LauncherModel.deleteItemFromDatabase(this, item);
4007 return;
4008 }
Sunny Goyalff572272014-07-23 13:58:07 -07004009
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004010 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004011 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004012 // Note: This assumes that the id remap broadcast is received before this step.
4013 // If that is not the case, the id remap will be ignored and user may see the
4014 // click to setup view.
Sunny Goyal16466f12016-03-10 05:34:30 -08004015 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004016 pendingInfo.spanX = item.spanX;
4017 pendingInfo.spanY = item.spanY;
4018 pendingInfo.minSpanX = item.minSpanX;
4019 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08004020 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004021
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004022 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4023 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4024 newWidgetId, appWidgetInfo, options);
4025
4026 // TODO consider showing a permission dialog when the widget is clicked.
4027 if (!success) {
4028 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4029 if (DEBUG_WIDGETS) {
4030 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4031 + " belongs to component " + item.providerName
4032 + ", as the launcher is unable to bing a new widget id");
4033 }
4034 LauncherModel.deleteItemFromDatabase(this, item);
4035 return;
Sunny Goyalff572272014-07-23 13:58:07 -07004036 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004037
4038 item.appWidgetId = newWidgetId;
4039
4040 // If the widget has a configure activity, it is still needs to set it up, otherwise
4041 // the widget is ready to go.
4042 item.restoreStatus = (appWidgetInfo.configure == null)
4043 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4044 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4045
4046 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004047 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004048 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004049 // The widget was marked as UI not ready, but there is no configure activity to
4050 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004051 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4052 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004053 }
Sunny Goyalff572272014-07-23 13:58:07 -07004054 }
4055
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004056 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004057 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004058 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4059 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004060 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004061
Sunny Goyal56c73602015-09-25 12:55:01 -07004062 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004063 if (appWidgetInfo == null) {
4064 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07004065 deleteWidgetInfo(item);
4066 return;
4067 }
4068
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004069 item.hostView = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004070 item.minSpanX = appWidgetInfo.minSpanX;
4071 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004072 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004073 } else {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004074 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4075 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004076 view.updateIcon(mIconCache);
4077 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004078 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004079 item.hostView.setOnClickListener(this);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004080 addAppWidgetToWorkspace(item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004081 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004082 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004083
Daniel Sandler843e8602010-06-07 14:59:01 -04004084 if (DEBUG_WIDGETS) {
4085 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4086 + (SystemClock.uptimeMillis()-start) + "ms");
4087 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004088 }
4089
Sunny Goyalff572272014-07-23 13:58:07 -07004090 /**
4091 * Restores a pending widget.
4092 *
4093 * @param appWidgetId The app widget id
4094 * @param cellInfo The position on screen where to create the widget.
4095 */
4096 private void completeRestoreAppWidget(final int appWidgetId) {
4097 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4098 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4099 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4100 return;
4101 }
4102
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004103 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004104 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4105
4106 mWorkspace.reinflateWidgetsIfNecessary();
4107 LauncherModel.updateItemInDatabase(this, info);
4108 }
4109
Adam Cohen1462de32012-07-24 22:34:36 -07004110 public void onPageBoundSynchronously(int page) {
4111 mSynchronouslyBoundPages.add(page);
4112 }
4113
Sunny Goyal527c7d32015-08-28 15:19:36 -07004114 @Override
4115 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4116 if (mPendingExecutor != null) {
4117 mPendingExecutor.markCompleted();
4118 }
4119 mPendingExecutor = executor;
4120 executor.attachTo(this);
4121 }
4122
4123 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4124 if (mPendingExecutor == executor) {
4125 mPendingExecutor = null;
4126 }
4127 }
4128
Joe Onorato9c1289c2009-08-17 11:03:03 -04004129 /**
4130 * Callback saying that there aren't any more items to bind.
4131 *
4132 * Implementation of the method from LauncherModel.Callbacks.
4133 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004134 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004135 Runnable r = new Runnable() {
4136 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004137 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004138 }
4139 };
4140 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004141 return;
4142 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004143 if (mSavedState != null) {
4144 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004145 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004146 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004147
Joe Onorato9c1289c2009-08-17 11:03:03 -04004148 mSavedState = null;
4149 }
4150
Adam Cohen1462de32012-07-24 22:34:36 -07004151 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004152
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004153 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004154 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004155
4156 // If we received the result of any pending adds while the loader was running (e.g. the
4157 // widget configuration forced an orientation change), process them now.
4158 if (sPendingAddItem != null) {
4159 final long screenId = completeAdd(sPendingAddItem);
4160
4161 // TODO: this moves the user to the page where the pending item was added. Ideally,
4162 // the screen would be guaranteed to exist after bind, and the page would be set through
4163 // the workspace restore process.
4164 mWorkspace.post(new Runnable() {
4165 @Override
4166 public void run() {
4167 mWorkspace.snapToScreenId(screenId);
4168 }
4169 });
4170 sPendingAddItem = null;
4171 }
4172
Sunny Goyal756adbc2015-04-16 15:20:51 -07004173 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004174
4175 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004176 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004177 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004178 }
4179
Adam Cohen3ed316a2014-07-23 18:21:20 -07004180 private void sendLoadingCompleteBroadcastIfNecessary() {
4181 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4182 String permission =
4183 getResources().getString(R.string.receive_first_load_broadcast_permission);
4184 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4185 sendBroadcast(intent, permission);
4186 SharedPreferences.Editor editor = mSharedPrefs.edit();
4187 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4188 editor.apply();
4189 }
4190 }
4191
Winson Chunga0b7e862013-09-05 16:03:15 -07004192 public boolean isAllAppsButtonRank(int rank) {
4193 if (mHotseat != null) {
4194 return mHotseat.isAllAppsButtonRank(rank);
4195 }
4196 return false;
4197 }
4198
Winson Chunga2413752012-04-03 14:22:34 -07004199 private boolean canRunNewAppsAnimation() {
4200 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004201 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4202 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004203 }
4204
Winson Chungc9168342013-06-26 14:54:55 -07004205 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004206 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004207 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4208 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004209 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004210 return bounceAnim;
4211 }
4212
Adam Cohen27772732013-11-11 14:00:56 +00004213 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004214 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004215 }
4216
Tony Wickham3a3517f2015-10-06 11:27:04 -07004217 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004218 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004219 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004220 }
4221
Tony Wickham55616cd2015-09-23 14:55:17 -07004222 public int getSearchBarHeight() {
4223 if (mLauncherCallbacks != null) {
4224 return mLauncherCallbacks.getSearchBarHeight();
4225 }
4226 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4227 }
4228
Winson Chung88fa7412015-08-03 14:25:28 -07004229 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004230 if (mSearchDropTargetBar == null) {
4231 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004232 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004233 if (mQsb != null) {
4234 mSearchDropTargetBar.removeView(mQsb);
4235 mQsb = null;
4236 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004237 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004238 }
4239
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004240 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004241 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4242 * multiple calls to bind the same list.)
4243 */
4244 @Thunk ArrayList<AppInfo> mTmpAppsList;
4245 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4246 public void run() {
4247 bindAllApplications(mTmpAppsList);
4248 mTmpAppsList = null;
4249 }
4250 };
4251
4252 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004253 * Add the icons for all apps.
4254 *
4255 * Implementation of the method from LauncherModel.Callbacks.
4256 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004257 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004258 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4259 mTmpAppsList = apps;
4260 return;
4261 }
4262
Winson Chungb745afb2015-03-02 11:51:23 -08004263 if (mAppsView != null) {
4264 mAppsView.setApps(apps);
4265 }
Adam Cohen9211d422014-10-07 18:14:53 -07004266 if (mLauncherCallbacks != null) {
4267 mLauncherCallbacks.bindAllApplications(apps);
4268 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004269 }
4270
4271 /**
4272 * A package was updated.
4273 *
4274 * Implementation of the method from LauncherModel.Callbacks.
4275 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004276 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004277 Runnable r = new Runnable() {
4278 public void run() {
4279 bindAppsUpdated(apps);
4280 }
4281 };
4282 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004283 return;
4284 }
4285
Winson Chungb745afb2015-03-02 11:51:23 -08004286 if (mAppsView != null) {
4287 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004288 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004289 }
4290
Sunny Goyal4390ace2014-10-13 11:33:11 -07004291 @Override
4292 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4293 Runnable r = new Runnable() {
4294 public void run() {
4295 bindWidgetsRestored(widgets);
4296 }
4297 };
4298 if (waitUntilResume(r)) {
4299 return;
4300 }
4301 mWorkspace.widgetsRestored(widgets);
4302 }
4303
Joe Onorato9c1289c2009-08-17 11:03:03 -04004304 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004305 * Some shortcuts were updated in the background.
4306 *
4307 * Implementation of the method from LauncherModel.Callbacks.
4308 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004309 @Override
4310 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4311 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004312 Runnable r = new Runnable() {
4313 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004314 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004315 }
4316 };
4317 if (waitUntilResume(r)) {
4318 return;
4319 }
4320
Sunny Goyal4390ace2014-10-13 11:33:11 -07004321 if (!updated.isEmpty()) {
4322 mWorkspace.updateShortcuts(updated);
4323 }
4324
4325 if (!removed.isEmpty()) {
4326 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4327 for (ShortcutInfo si : removed) {
4328 removedComponents.add(si.getTargetComponent());
4329 }
4330 mWorkspace.removeItemsByComponentName(removedComponents, user);
4331 // Notify the drag controller
4332 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004333 }
4334 }
4335
4336 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004337 * Update the state of a package, typically related to install state.
4338 *
4339 * Implementation of the method from LauncherModel.Callbacks.
4340 */
Sunny Goyale755d462014-07-22 13:48:29 -07004341 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004342 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4343 Runnable r = new Runnable() {
4344 public void run() {
4345 bindRestoreItemsChange(updates);
4346 }
4347 };
4348 if (waitUntilResume(r)) {
4349 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004350 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004351
Sunny Goyal756adbc2015-04-16 15:20:51 -07004352 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004353 }
4354
4355 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004356 * A package was uninstalled. We take both the super set of packageNames
4357 * in addition to specific applications to remove, the reason being that
4358 * this can be called when a package is updated as well. In that scenario,
4359 * we only remove specific components from the workspace, where as
4360 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004361 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004362 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004363 * Implementation of the method from LauncherModel.Callbacks.
4364 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004365 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004366 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004367 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004368 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004369 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004370 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004371 }
Winson Chungd64d1762013-08-20 14:37:16 -07004372 };
4373 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004374 return;
4375 }
4376
Sunny Goyal1a745e82014-10-02 15:58:31 -07004377 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004378 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4379 for (AppInfo info : appInfos) {
4380 removedComponents.add(info.componentName);
4381 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004382 if (!packageNames.isEmpty()) {
4383 mWorkspace.removeItemsByPackageName(packageNames, user);
4384 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004385 if (!removedComponents.isEmpty()) {
4386 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004387 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004388 // Notify the drag controller
4389 mDragController.onAppsRemoved(packageNames, removedComponents);
4390
Sunny Goyal1a745e82014-10-02 15:58:31 -07004391 } else {
4392 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004393 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004394
Winson Chungdf95eb12013-10-16 14:57:07 -07004395 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004396 if (mAppsView != null) {
4397 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004398 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004399 }
Joe Onoratobe386092009-11-17 17:32:16 -08004400
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004401 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004402 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004403 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004404 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004405 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004406
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004407 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004408 public void bindWidgetsModel(WidgetsModel model) {
4409 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004410 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004411 return;
4412 }
4413
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004414 if (mWidgetsView != null && model != null) {
4415 mWidgetsView.addWidgets(model);
4416 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004417 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004418 }
4419
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004420 @Override
4421 public void notifyWidgetProvidersChanged() {
4422 if (mWorkspace.getState().shouldUpdateWidget) {
4423 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4424 }
4425 }
4426
Winson Chung400438b2011-01-16 17:53:48 -08004427 private int mapConfigurationOriActivityInfoOri(int configOri) {
4428 final Display d = getWindowManager().getDefaultDisplay();
4429 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4430 switch (d.getRotation()) {
4431 case Surface.ROTATION_0:
4432 case Surface.ROTATION_180:
4433 // We are currently in the same basic orientation as the natural orientation
4434 naturalOri = configOri;
4435 break;
4436 case Surface.ROTATION_90:
4437 case Surface.ROTATION_270:
4438 // We are currently in the other basic orientation to the natural orientation
4439 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4440 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4441 break;
4442 }
4443
4444 int[] oriMap = {
4445 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4446 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4447 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4448 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4449 };
4450 // Since the map starts at portrait, we need to offset if this device's natural orientation
4451 // is landscape.
4452 int indexOffset = 0;
4453 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4454 indexOffset = 1;
4455 }
4456 return oriMap[(d.getRotation() + indexOffset) % 4];
4457 }
Adam Cohen446e9402011-09-15 18:21:21 -07004458
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004459 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004460 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004461 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004462 if (Utilities.ATLEAST_JB_MR2) {
4463 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4464 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004465 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4466 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004467 }
Winson Chung4b919f82012-05-01 10:44:08 -07004468 }
4469 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004470
Winson Chung4b919f82012-05-01 10:44:08 -07004471 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004472 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004473 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004474 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004475 } else {
4476 mHandler.postDelayed(new Runnable() {
4477 public void run() {
4478 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4479 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004480 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004481 }
Winson Chung4b919f82012-05-01 10:44:08 -07004482 }
Winson Chung400438b2011-01-16 17:53:48 -08004483 }
4484
Winson Chunge43a1e72014-01-15 10:33:02 -08004485 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004486 if (mLauncherCallbacks != null) {
4487 return mLauncherCallbacks.isLauncherPreinstalled();
4488 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004489 PackageManager pm = getPackageManager();
4490 try {
4491 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4492 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4493 return true;
4494 } else {
4495 return false;
4496 }
4497 } catch (NameNotFoundException e) {
4498 e.printStackTrace();
4499 return false;
4500 }
4501 }
4502
Adam Cohenea90f832014-05-21 15:03:34 -07004503 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004504 * To be overridden by subclasses to indicate that there is an activity to launch
4505 * before showing the standard launcher experience.
4506 */
4507 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004508 if (mLauncherCallbacks != null) {
4509 return mLauncherCallbacks.hasFirstRunActivity();
4510 }
Adam Cohen432609a2014-03-13 17:03:22 -07004511 return false;
4512 }
4513
4514 /**
4515 * To be overridden by subclasses to launch any first run activity
4516 */
4517 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004518 if (mLauncherCallbacks != null) {
4519 return mLauncherCallbacks.getFirstRunActivity();
4520 }
Adam Cohen432609a2014-03-13 17:03:22 -07004521 return null;
4522 }
4523
Winson Chunga6945242014-01-08 14:04:34 -08004524 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004525 return !ActivityManager.isRunningInTestHarness() &&
4526 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004527 }
4528
Adam Cohen4a9423d2014-03-28 14:22:31 -07004529 protected boolean hasRunFirstRunActivity() {
4530 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4531 }
4532
Adam Cohen432609a2014-03-13 17:03:22 -07004533 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004534 if (shouldRunFirstRunActivity() &&
4535 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004536 Intent firstRunIntent = getFirstRunActivity();
4537 if (firstRunIntent != null) {
4538 startActivity(firstRunIntent);
4539 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004540 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004541 }
4542 }
Adam Cohen432609a2014-03-13 17:03:22 -07004543 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004544 }
4545
4546 private void markFirstRunActivityShown() {
4547 SharedPreferences.Editor editor = mSharedPrefs.edit();
4548 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4549 editor.apply();
4550 }
4551
Adam Cohen432609a2014-03-13 17:03:22 -07004552 /**
4553 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4554 * screen that must be displayed and dismissed.
4555 */
4556 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004557 if (mLauncherCallbacks != null) {
4558 return mLauncherCallbacks.hasDismissableIntroScreen();
4559 }
Adam Cohen432609a2014-03-13 17:03:22 -07004560 return false;
4561 }
4562
4563 /**
4564 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4565 */
4566 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004567 if (mLauncherCallbacks != null) {
4568 return mLauncherCallbacks.getIntroScreen();
4569 }
Adam Cohen432609a2014-03-13 17:03:22 -07004570 return null;
4571 }
4572
4573 /**
4574 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4575 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4576 */
4577 private boolean shouldShowIntroScreen() {
4578 return hasDismissableIntroScreen() &&
4579 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4580 }
4581
4582 protected void showIntroScreen() {
4583 View introScreen = getIntroScreen();
4584 changeWallpaperVisiblity(false);
4585 if (introScreen != null) {
4586 mDragLayer.showOverlayView(introScreen);
4587 }
4588 }
4589
4590 public void dismissIntroScreen() {
4591 markIntroScreenDismissed();
4592 if (showFirstRunActivity()) {
4593 // We delay hiding the intro view until the first run activity is showing. This
4594 // avoids a blip.
4595 mWorkspace.postDelayed(new Runnable() {
4596 @Override
4597 public void run() {
4598 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004599 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004600 }
4601 }, ACTIVITY_START_DELAY);
4602 } else {
4603 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004604 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004605 }
4606 changeWallpaperVisiblity(true);
4607 }
4608
4609 private void markIntroScreenDismissed() {
4610 SharedPreferences.Editor editor = mSharedPrefs.edit();
4611 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4612 editor.apply();
4613 }
4614
Adam Cohen091440a2015-03-18 14:16:05 -07004615 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004616 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4617 // on the device, then we always show the first run cling experience (or if there is no
4618 // launcher2). Otherwise, we prompt the user upon started for migration
4619 LauncherClings launcherClings = new LauncherClings(this);
4620 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004621 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004622 if (mModel.canMigrateFromOldLauncherDb(this)) {
4623 launcherClings.showMigrationCling();
4624 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004625 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004626 }
4627 }
4628 }
4629
Winson Chunga6945242014-01-08 14:04:34 -08004630 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004631 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4632 if (mHotseat != null) mHotseat.setAlpha(1f);
4633 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004634 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4635 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004636 }
4637
4638 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004639 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4640 if (mHotseat != null) mHotseat.setAlpha(0f);
4641 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004642 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4643 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004644 }
4645
Winson Chung5ffd51d2015-06-25 11:36:50 -07004646 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004647 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004648 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004649 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004650 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004651 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004652 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4653 if (userHandle != null) {
4654 user = UserHandleCompat.fromUser(userHandle);
4655 }
4656 }
4657 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004658 }
4659
4660 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004661 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004662 if (user == null) {
4663 user = UserHandleCompat.myUserHandle();
4664 }
4665
4666 // Called from search suggestion, add the profile extra to the intent to ensure that we
4667 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004668 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004669 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004670 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004671 return null;
4672 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004673 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004674 }
4675
Winson Chung5ffd51d2015-06-25 11:36:50 -07004676 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004677 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4678 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004679 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004680 UserHandleCompat.myUserHandle());
4681 }
4682
Winson Chung5ffd51d2015-06-25 11:36:50 -07004683 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004684 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4685 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004686 mWorkspace.onExternalDragStartedWithItem(dragView);
4687 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004688 }
4689
Winson Chung5ffd51d2015-06-25 11:36:50 -07004690 protected void moveWorkspaceToDefaultScreen() {
4691 mWorkspace.moveToDefaultScreen(false);
4692 }
4693
Anjali Koppalf5d29132014-02-28 13:33:27 -08004694 @Override
4695 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004696 if (mLauncherCallbacks != null) {
4697 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4698 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004699 }
4700
Winson Chung80baf5a2010-08-09 16:03:15 -07004701 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004702 * Returns a FastBitmapDrawable with the icon, accurately sized.
4703 */
4704 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4705 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4706 d.setFilterBitmap(true);
4707 resizeIconDrawable(d);
4708 return d;
4709 }
4710
4711 /**
4712 * Resizes an icon drawable to the correct icon size.
4713 */
Winson5fbe0742015-09-30 15:33:00 -07004714 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004715 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004716 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004717 }
4718
4719 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004720 * Prints out out state for debugging.
4721 */
4722 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004723 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004724 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004725 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4726 Log.d(TAG, "mRestoring=" + mRestoring);
4727 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004728 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004729 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004730 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004731
Daniel Sandler325dc232013-06-05 22:57:57 -04004732 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004733 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004734
4735 @Override
4736 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4737 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004738 // Dump workspace
4739 writer.println(prefix + "Workspace Items");
4740 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4741 writer.println(prefix + " Homescreen " + i);
4742
4743 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4744 for (int j = 0; j < layout.getChildCount(); j++) {
4745 Object tag = layout.getChildAt(j).getTag();
4746 if (tag != null) {
4747 writer.println(prefix + " " + tag.toString());
4748 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004749 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004750 }
Sunny Goyala1365452015-10-01 15:46:24 -07004751
4752 writer.println(prefix + " Hotseat");
4753 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4754 for (int j = 0; j < layout.getChildCount(); j++) {
4755 Object tag = layout.getChildAt(j).getTag();
4756 if (tag != null) {
4757 writer.println(prefix + " " + tag.toString());
4758 }
4759 }
4760
4761 synchronized (sDumpLogs) {
4762 writer.println();
4763 writer.println(prefix + "Debug logs");
4764 for (String log : sDumpLogs) {
4765 writer.println(prefix + " " + log);
4766 }
4767 }
4768
Adam Cohen9211d422014-10-07 18:14:53 -07004769 if (mLauncherCallbacks != null) {
4770 mLauncherCallbacks.dump(prefix, fd, writer, args);
4771 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004772 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004773
Sunny Goyala1365452015-10-01 15:46:24 -07004774 public static void addDumpLog(String tag, String log) {
4775 Log.d(tag, log);
4776 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004777 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004778 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004779 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004780 }
4781
Adam Cohen59400422014-03-05 18:07:04 -08004782 public static CustomAppWidget getCustomAppWidget(String name) {
4783 return sCustomAppWidgets.get(name);
4784 }
4785
4786 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4787 return sCustomAppWidgets;
4788 }
4789
Sunny Goyal29538332016-02-18 09:10:19 -08004790 public static List<View> getFolderContents(View icon) {
4791 if (icon instanceof FolderIcon) {
4792 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4793 } else {
4794 return Collections.EMPTY_LIST;
4795 }
4796 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004797}
Michael Jurka2763be32011-02-24 11:19:57 -08004798
Dan Sandlerd5024042014-01-09 15:01:33 -05004799interface DebugIntents {
4800 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4801 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004802}