blob: 7b53f9f8d057c9179a5ffa1521a8040e0efa331b [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyal28c6b962015-10-12 11:42:05 -070019import android.Manifest;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070025import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Sunny Goyal756cd262015-08-20 12:33:21 -070039import android.content.ContentValues;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Adam Cohen3f9c9712014-10-31 11:48:25 -070051import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Tony Wickhama3c74d12015-10-23 11:43:47 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070069import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070078import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.MotionEvent;
80import android.view.Surface;
81import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070082import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070085import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070089import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080093import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070095
Sunny Goyal651077b2014-06-30 14:15:31 -070096import com.android.launcher3.DropTarget.DragObject;
97import com.android.launcher3.PagedView.PageSwitchListener;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070098import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080099import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700100import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100101import com.android.launcher3.compat.LauncherActivityInfoCompat;
102import com.android.launcher3.compat.LauncherAppsCompat;
103import com.android.launcher3.compat.UserHandleCompat;
104import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800105import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700106import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700107import com.android.launcher3.dragndrop.DragController;
108import com.android.launcher3.dragndrop.DragLayer;
109import com.android.launcher3.dragndrop.DragView;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700110import com.android.launcher3.model.WidgetsModel;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800111import com.android.launcher3.userevent.Logger;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700112import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700113import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700114import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700115import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700116import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700117import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700118import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700119import com.android.launcher3.widget.WidgetsContainerView;
Sunny Goyalbd822502016-02-18 15:09:21 -0800120import com.android.wallpaperpicker.WallpaperUtils;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700121
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700122import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700123import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700124import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700126import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800127import java.util.Collections;
Adam Cohen4caf2982013-08-20 18:54:31 -0700128import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700129import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700130import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700131import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133/**
134 * Default launcher application.
135 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100136public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700137 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chung006ee262015-08-03 14:40:11 -0700138 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700139 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700143 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700144 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700146
Dan Sandlerd5024042014-01-09 15:01:33 -0500147 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
148
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700152 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Michael Jurka8b805b12012-04-18 14:23:14 -0700154 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700155 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700156
Sunny Goyal28c6b962015-10-12 11:42:05 -0700157 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
158
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700159 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
160 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
161 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
162
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700163 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
164
Mathew Inwood876a8462013-06-14 14:12:41 +0100165 /**
166 * IntentStarter uses request codes starting with this. This must be greater than all activity
167 * request codes used internally.
168 */
169 protected static final int REQUEST_LAST = 100;
170
Michael Jurka0a457bf2012-11-19 14:05:05 -0800171 // To turn on these properties, type
172 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800173 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
Winson Chung2672ff92012-05-04 16:22:30 -0700175 // The Intent extra that defines whether to ignore the launch animation
176 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400177 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 // Type: int
180 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700181 // Type: int
182 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal08442b82015-10-21 17:15:08 -0700183 // Type: long
184 private static final String RUNTIME_STATE_OPEN_FOLDER_ID = "launcher.open_folder_id";
Sunny Goyal756cd262015-08-20 12:33:21 -0700185 // Type: Content Values / parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700187 // Type: parcelable
188 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000189 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800190 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
Adam Cohen432609a2014-03-13 17:03:22 -0700192 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800193 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
194
Adam Cohen3ed316a2014-07-23 18:21:20 -0700195 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
196 static final String ACTION_FIRST_LOAD_COMPLETE =
197 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
198
Sunny Goyal594d76d2014-11-06 10:12:54 -0800199 private static final String QSB_WIDGET_ID = "qsb_widget_id";
200 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
201
Winson Chunga6945242014-01-08 14:04:34 -0800202 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
203
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700204 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700205 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
206 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700207
Adam Cohen091440a2015-03-18 14:16:05 -0700208 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700209 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700210
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700211 private boolean mIsSafeModeEnabled;
212
Adam Cohenc2d6e892014-10-16 09:49:24 -0700213 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
214 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700215 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700216
Joe Onorato9c1289c2009-08-17 11:03:03 -0400217 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700218 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
219 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700220 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
Winson Chunga2413752012-04-03 14:22:34 -0700222 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700223 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
224 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700225 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700226
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800227 private final BroadcastReceiver mCloseSystemDialogsReceiver
228 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800229
Adam Cohen091440a2015-03-18 14:16:05 -0700230 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700231 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800232 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700233 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800234 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700235
236 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700237
Sunny Goyalffe83f12014-08-14 17:39:34 -0700238 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700239 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700240
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700241 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800242 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800243 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700244
Michael Jurka0280c3b2010-09-17 15:00:07 -0700245 private int[] mTmpAddItemCellCoordinates = new int[2];
246
Sunny Goyal316490e2015-06-02 09:38:28 -0700247 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800248 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700249
Michael Jurka838a4ca2011-02-07 13:33:06 -0800250 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700251 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700252
Winson Chungc51db6a2011-10-05 11:44:49 -0700253 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700254 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700255
256 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700257 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700258
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700259 // Main container view and the model for the widget tray screen.
260 @Thunk WidgetsContainerView mWidgetsView;
261 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700262
Sunny Goyal594d76d2014-11-06 10:12:54 -0800263 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
267 // scroll issues (because the workspace may not have been measured yet) and extra work.
268 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
269 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
271 private SpannableStringBuilder mDefaultKeySsb = null;
272
Adam Cohen091440a2015-03-18 14:16:05 -0700273 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800275 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 private boolean mRestoring;
277 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700278 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279
Michael Jurka1e2f4652013-07-08 18:03:46 -0700280 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700281 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700282 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700283
Joe Onorato9c1289c2009-08-17 11:03:03 -0400284 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800285 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700286 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800287 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700288 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800289 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290
Sunny Goyal639e9062015-08-19 19:17:06 -0700291 private LauncherClings mClings;
292
Sunny Goyale2df0622015-04-24 11:27:00 -0700293 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700294
Adam Cohen61f560d2013-09-30 15:58:20 -0700295 private View.OnTouchListener mHapticFeedbackTouchListener;
296
Adam Cohended9f8d2010-11-03 13:25:16 -0700297 // Related to the auto-advancing of widgets
298 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700299 private static final int ADVANCE_INTERVAL = 20000;
300 private static final int ADVANCE_STAGGER = 250;
301
302 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700303 private long mAutoAdvanceSentTime;
304 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700305 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700306
Winson Chung400438b2011-01-16 17:53:48 -0800307 // Determines how long to wait after a rotation before restoring the screen orientation to
308 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700309 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800310
Adam Cohen091440a2015-03-18 14:16:05 -0700311 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700312
Adam Cohen1462de32012-07-24 22:34:36 -0700313 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700314 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700315
Sunny Goyala1365452015-10-01 15:46:24 -0700316 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
317 private static final Date sDateStamp = new Date();
318 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700319 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700320
Winson Chung46353de2012-02-16 14:05:10 -0800321 // We only want to get the SharedPreferences once since it does an FS stat each time we get
322 // it from the context.
323 private SharedPreferences mSharedPrefs;
324
Winson Chungf0c6ae02012-03-21 16:10:31 -0700325 // Holds the page that we need to animate to, and the icon views that we need to animate up
326 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700327 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700328 private Bitmap mFolderIconBitmap;
329 private Canvas mFolderIconCanvas;
330 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700331
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700332 private DeviceProfile mDeviceProfile;
333
Adam Cohen4b66bf32015-09-18 12:15:19 -0700334 private boolean mMoveToDefaultScreenFromNewIntent;
335
Winson Chung13eb5272015-05-11 16:30:13 -0700336 // This is set to the view that launched the activity that navigated the user away from
337 // launcher. Since there is no callback for when the activity has finished launching, enable
338 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800339 private BubbleTextView mWaitingForResume;
340
Adam Cohen59400422014-03-05 18:07:04 -0800341 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
342 new HashMap<String, CustomAppWidget>();
343
Adam Cohen59400422014-03-05 18:07:04 -0800344 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700345 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
346 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800347 }
348 }
349
Adam Cohen091440a2015-03-18 14:16:05 -0700350 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700351 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700352 if (mWorkspace != null) {
353 mWorkspace.buildPageHardwareLayers();
354 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700355 }
356 };
357
Adam Cohendb364c32014-05-20 14:23:40 -0700358 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800359
Adam Cohen091440a2015-03-18 14:16:05 -0700360 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 int requestCode;
362 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700363 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700364 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 int cellX;
366 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700367 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800368 }
369
Daniel Sandlerff02d492013-08-05 02:12:05 -0400370 private Stats mStats;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800371 private Logger mUserEventLogger;
372
Adam Cohenf9c184a2016-01-15 16:47:43 -0800373 public FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700374 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400375
376 @Thunk void setOrientation() {
377 if (mRotationEnabled) {
378 unlockScreenOrientation(true);
379 } else {
380 setRequestedOrientation(
381 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700382 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400383 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700384
Sunny Goyal7779d622015-06-11 16:18:39 -0700385 private Runnable mUpdateOrientationRunnable = new Runnable() {
386 public void run() {
387 setOrientation();
388 }
389 };
390
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 @Override
392 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700393 if (DEBUG_STRICT_MODE) {
394 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
395 .detectDiskReads()
396 .detectDiskWrites()
397 .detectNetwork() // or .detectAll() for all detectable problems
398 .penaltyLog()
399 .build());
400 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
401 .detectLeakedSqlLiteObjects()
402 .detectLeakedClosableObjects()
403 .penaltyLog()
404 .penaltyDeath()
405 .build());
406 }
407
Adam Cohen9211d422014-10-07 18:14:53 -0700408 if (mLauncherCallbacks != null) {
409 mLauncherCallbacks.preOnCreate();
410 }
411
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800412 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400413
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400414 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700415
Adam Cohen2e6da152015-05-06 11:42:25 -0700416 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700417 mDeviceProfile = getResources().getConfiguration().orientation
418 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700419 app.getInvariantDeviceProfile().landscapeProfile
420 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700421
Sunny Goyalf7258242015-10-19 16:59:07 -0700422 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700423 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800424 mModel = app.setLauncher(this);
425 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700426
Joe Onorato41a12d22009-10-31 18:30:00 -0400427 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700428 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800430 mUserEventLogger = new Logger(this);
Daniel Sandlerff02d492013-08-05 02:12:05 -0400431 mStats = new Stats(this);
432
Sunny Goyalffe83f12014-08-14 17:39:34 -0700433 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700434
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700435 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
436 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700437
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700438 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
439 // this also ensures that any synchronous binding below doesn't re-trigger another
440 // LauncherModel load.
441 mPaused = false;
442
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200444 android.os.Debug.startMethodTracing(
445 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 }
447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700449
Tony Wickhameef44322015-10-20 13:24:36 -0700450 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
451 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700453 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454
Joe Onorato7c312c12009-08-13 21:36:53 -0700455 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 mSavedState = savedInstanceState;
458 restoreState(mSavedState);
459
460 if (PROFILE_STARTUP) {
461 android.os.Debug.stopMethodTracing();
462 }
463
464 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700465 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 // If the user leaves launcher, then we should just load items asynchronously when
467 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700468 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 } else {
470 // We only load the page synchronously if the user rotates (or triggers a
471 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700472 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 }
475
476 // For handling default keys
477 mDefaultKeySsb = new SpannableStringBuilder();
478 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800479
480 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
481 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800482
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700483 mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
484 // In case we are on a device with locked rotation, we should look at preferences to check
485 // if the user has specifically allowed rotation.
486 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700487 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700488 }
489
490 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
491 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400492 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700493
Adam Cohen9211d422014-10-07 18:14:53 -0700494 if (mLauncherCallbacks != null) {
495 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700496 if (mLauncherCallbacks.hasLauncherOverlay()) {
497 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700498 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
499 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
500 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700501 mWorkspace.setLauncherOverlay(mLauncherOverlay);
502 }
Adam Cohen9211d422014-10-07 18:14:53 -0700503 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700504
505 if (shouldShowIntroScreen()) {
506 showIntroScreen();
507 } else {
508 showFirstRunActivity();
509 showFirstRunClings();
510 }
Adam Cohen9211d422014-10-07 18:14:53 -0700511 }
512
Sunny Goyal7779d622015-06-11 16:18:39 -0700513 @Override
514 public void onSettingsChanged(String settings, boolean value) {
515 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
516 mRotationEnabled = value;
517 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
518 mUpdateOrientationRunnable.run();
519 }
520 }
521 }
522
Adam Cohen9211d422014-10-07 18:14:53 -0700523 private LauncherCallbacks mLauncherCallbacks;
524
525 public void onPostCreate(Bundle savedInstanceState) {
526 super.onPostCreate(savedInstanceState);
527 if (mLauncherCallbacks != null) {
528 mLauncherCallbacks.onPostCreate(savedInstanceState);
529 }
530 }
531
532 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 =
538 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
539 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 Songfbf19cc2016-02-19 12:14:47 -0800634 public Logger getLogger() {return mUserEventLogger; }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100635
Hyunyoung Song3f471442015-04-08 19:01:34 -0700636 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700637 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
638 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700639 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700640 }
641
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000642 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700643 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
644 // This cast is safe as long as the id < 0x00FFFFFF
645 // Since we jail all the dynamically generated views, there should be no clashes
646 // with any other views.
647 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000648 }
649
650 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700651 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
652 * a configuration step, this allows the proper animations to run after other transitions.
653 */
Adam Cohendb364c32014-05-20 14:23:40 -0700654 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700655 long screenId = args.screenId;
656 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
657 // When the screen id represents an actual screen (as opposed to a rank) we make sure
658 // that the drop page actually exists.
659 screenId = ensurePendingDropLayoutExists(args.screenId);
660 }
Adam Cohendb364c32014-05-20 14:23:40 -0700661
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800662 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800663 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700664 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700665 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700666 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800667 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700668 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700669 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700670 case REQUEST_RECONFIGURE_APPWIDGET:
671 completeRestoreAppWidget(args.appWidgetId);
672 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800673 }
Michael Jurka27614d22012-04-02 06:40:22 -0700674 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
675 // if you turned the screen off and then back while in All Apps, Launcher would not
676 // return to the workspace. Clearing mAddInfo.container here fixes this issue
677 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700678 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800679 }
680
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800681 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700682 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700683 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700684 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700685 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800686 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700687
Adam Cohenad4e15c2013-10-17 16:21:35 -0700688 Runnable exitSpringLoaded = new Runnable() {
689 @Override
690 public void run() {
691 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
692 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
693 }
694 };
695
Michael Jurka8b805b12012-04-18 14:23:14 -0700696 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700697 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700698 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700699 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
700 if (resultCode == RESULT_CANCELED) {
701 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700702 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700703 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700704 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800705 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700706 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700707
708 // When the user has granted permission to bind widgets, we should check to see if
709 // we can inflate the default search bar widget.
710 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700711 }
712 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200713 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
714 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700715 // User could have free-scrolled between pages before picking a wallpaper; make sure
716 // we move to the closest one now.
717 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700718 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200719 }
720 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700721 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200722
Adam Cohened66b2b2012-01-23 17:28:51 -0800723 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700724 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700725
Adam Cohendb364c32014-05-20 14:23:40 -0700726 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800727 // We have special handling for widgets
728 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800729 final int appWidgetId;
730 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
731 : -1;
732 if (widgetId < 0) {
733 appWidgetId = pendingAddWidgetId;
734 } else {
735 appWidgetId = widgetId;
736 }
737
Adam Cohenad4e15c2013-10-17 16:21:35 -0700738 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800739 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700740 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
741 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700742 result = RESULT_CANCELED;
743 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700744 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700745 @Override
746 public void run() {
747 exitSpringLoadedDragModeDelayed(false, 0, null);
748 }
749 };
Adam Cohendb364c32014-05-20 14:23:40 -0700750 if (workspaceLocked) {
751 // No need to remove the empty screen if we're mid-binding, as the
752 // the bind will not add the empty screen.
753 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
754 } else {
755 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
756 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
757 }
Winson Chung5aaab772012-04-27 15:24:02 -0700758 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700759 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700760 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
761 // When the screen id represents an actual screen (as opposed to a rank)
762 // we make sure that the drop page actually exists.
763 mPendingAddInfo.screenId =
764 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
765 }
Adam Cohendb364c32014-05-20 14:23:40 -0700766 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
767
768 dropLayout.setDropPending(true);
769 final Runnable onComplete = new Runnable() {
770 @Override
771 public void run() {
772 completeTwoStageWidgetDrop(resultCode, appWidgetId);
773 dropLayout.setDropPending(false);
774 }
775 };
776 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
777 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
778 } else {
779 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
780 mPendingAddInfo);
781 sPendingAddItem = args;
782 }
Winson Chung5aaab772012-04-27 15:24:02 -0700783 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800784 return;
785 }
786
Sunny Goyalff572272014-07-23 13:58:07 -0700787 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
788 if (resultCode == RESULT_OK) {
789 // Update the widget view.
790 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
791 pendingAddWidgetId, mPendingAddInfo);
792 if (workspaceLocked) {
793 sPendingAddItem = args;
794 } else {
795 completeAdd(args);
796 }
797 }
798 // Leave the widget in the pending state if the user canceled the configure.
799 return;
800 }
801
Sunny Goyalaad90582015-07-09 14:22:50 -0700802 if (requestCode == REQUEST_CREATE_SHORTCUT) {
803 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
804 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
805 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
806 mPendingAddInfo);
807 if (isWorkspaceLocked()) {
808 sPendingAddItem = args;
809 } else {
810 completeAdd(args);
811 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
812 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
813 }
814 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700815 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
816 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800819 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800820
821 }
822
823 @Override
824 protected void onActivityResult(
825 final int requestCode, final int resultCode, final Intent data) {
826 handleActivityResult(requestCode, resultCode, data);
827 if (mLauncherCallbacks != null) {
828 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
829 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800830 }
831
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600832 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700833 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600834 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700835 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
836 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
837 View v = null;
838 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
839 if (layout != null) {
840 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
841 }
842 Intent intent = sPendingAddItem.intent;
843 sPendingAddItem = null;
844 if (grantResults.length > 0
845 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
846 startActivity(v, intent, null);
847 } else {
848 // TODO: Show a snack bar with link to settings
849 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
850 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
851 }
852 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600853 if (mLauncherCallbacks != null) {
854 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
855 grantResults);
856 }
857 }
858
Adam Cohendb364c32014-05-20 14:23:40 -0700859 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
860 appWidgetId, ItemInfo info) {
861 PendingAddArguments args = new PendingAddArguments();
862 args.requestCode = requestCode;
863 args.intent = data;
864 args.container = info.container;
865 args.screenId = info.screenId;
866 args.cellX = info.cellX;
867 args.cellY = info.cellY;
868 args.appWidgetId = appWidgetId;
869 return args;
870 }
871
872 /**
873 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
874 *
875 * @param screenId the screen id to check
876 * @return the new screen, or screenId if it exists
877 */
878 private long ensurePendingDropLayoutExists(long screenId) {
879 CellLayout dropLayout =
880 (CellLayout) mWorkspace.getScreenWithId(screenId);
881 if (dropLayout == null) {
882 // it's possible that the add screen was removed because it was
883 // empty and a re-bind occurred
884 mWorkspace.addExtraEmptyScreen();
885 return mWorkspace.commitExtraEmptyScreen();
886 } else {
887 return screenId;
888 }
889 }
890
Adam Cohen091440a2015-03-18 14:16:05 -0700891 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800892 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 Runnable onCompleteRunnable = null;
894 int animationType = 0;
895
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700896 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800897 if (resultCode == RESULT_OK) {
898 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
899 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700900 mPendingAddWidgetInfo);
901 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800902 onCompleteRunnable = new Runnable() {
903 @Override
904 public void run() {
905 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700906 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700907 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
908 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800909 }
910 };
911 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800912 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800913 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800914 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700915 if (mDragLayer.getAnimatedView() != null) {
916 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
917 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
918 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700919 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700920 // The animated view may be null in the case of a rotation during widget configuration
921 onCompleteRunnable.run();
922 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800923 }
924
925 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700926 protected void onStop() {
927 super.onStop();
928 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700929
930 if (mLauncherCallbacks != null) {
931 mLauncherCallbacks.onStop();
932 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700933 }
934
935 @Override
936 protected void onStart() {
937 super.onStart();
938 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700939
940 if (mLauncherCallbacks != null) {
941 mLauncherCallbacks.onStart();
942 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700943 }
944
945 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200947 long startTime = 0;
948 if (DEBUG_RESUME_TIME) {
949 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400950 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200951 }
Adam Cohen9211d422014-10-07 18:14:53 -0700952
953 if (mLauncherCallbacks != null) {
954 mLauncherCallbacks.preOnResume();
955 }
956
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800957 super.onResume();
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800958 mUserEventLogger.resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700959
Winson Chung4a2afa32012-07-19 14:53:05 -0700960 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700961 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700962 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800963 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700964 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700965 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700966 // view after launching an app, as they may be depending on the UI to be static to
967 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700968 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700969 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800970 } else if (mOnResumeState == State.WIDGETS) {
971 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700972 }
973 mOnResumeState = State.NONE;
974
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700975 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -0700976 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
977 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -0700978
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800979 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700980 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700981 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700982 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400983 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700984 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700986 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200987 // We might have postponed some bind calls until onResume (see waitUntilResume) --
988 // execute them here
989 long startTimeCallbacks = 0;
990 if (DEBUG_RESUME_TIME) {
991 startTimeCallbacks = System.currentTimeMillis();
992 }
993
Michael Jurka1e2f4652013-07-08 18:03:46 -0700994 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
995 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200996 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700997 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200998 if (DEBUG_RESUME_TIME) {
999 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1000 (System.currentTimeMillis() - startTimeCallbacks));
1001 }
Michael Jurka447bf842013-05-15 14:52:15 +02001002 }
Michael Jurka54554252013-08-01 12:52:23 +02001003 if (mOnResumeCallbacks.size() > 0) {
1004 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1005 mOnResumeCallbacks.get(i).run();
1006 }
1007 mOnResumeCallbacks.clear();
1008 }
Winson Chunge4e50662012-01-23 14:45:13 -08001009
1010 // Reset the pressed state of icons that were locked in the press state while activities
1011 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001012 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001013 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001014 mWaitingForResume.setStayPressed(false);
1015 }
Winson Chung82963d52013-10-09 11:20:57 -07001016
Adam Cohen06dff352012-06-01 17:17:08 -07001017 // It is possible that widgets can receive updates while launcher is not in the foreground.
1018 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1019 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1020 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001021 if (!isWorkspaceLoading()) {
1022 getWorkspace().reinflateWidgetsIfNecessary();
1023 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001024 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001025
Michael Jurka447bf842013-05-15 14:52:15 +02001026 if (DEBUG_RESUME_TIME) {
1027 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1028 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001029
Adam Cohen4b66bf32015-09-18 12:15:19 -07001030 // We want to suppress callbacks about CustomContent being shown if we have just received
1031 // onNewIntent while the user was present within launcher. In that case, we post a call
1032 // to move the user to the main screen (which will occur after onResume). We don't want to
1033 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1034 // suppress here.
1035 if (mWorkspace.getCustomContentCallbacks() != null
1036 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001037 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001038 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001039 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1040 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001041 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001042 }
1043 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001044 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001045 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001046 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001047
Sunny Goyal756adbc2015-04-16 15:20:51 -07001048 if (!isWorkspaceLoading()) {
1049 // Process any items that were added while Launcher was away.
1050 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1051 }
Adam Cohen9211d422014-10-07 18:14:53 -07001052
1053 if (mLauncherCallbacks != null) {
1054 mLauncherCallbacks.onResume();
1055 }
Adam Cohen06dff352012-06-01 17:17:08 -07001056 }
1057
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001059 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001060 // Ensure that items added to Launcher are queued until Launcher returns
1061 InstallShortcutReceiver.enableInstallQueue();
1062
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001063 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001064 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001065 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001066 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001067
1068 // We call onHide() aggressively. The custom content callbacks should be able to
1069 // debounce excess onHide calls.
1070 if (mWorkspace.getCustomContentCallbacks() != null) {
1071 mWorkspace.getCustomContentCallbacks().onHide();
1072 }
Romain Guycbb89e42009-06-08 15:52:54 -07001073
Adam Cohen9211d422014-10-07 18:14:53 -07001074 if (mLauncherCallbacks != null) {
1075 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001076 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001077 }
1078
1079 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001080 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1081 // by a onResume or by scrolling otherwise.
1082 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001083
1084 // Custom content is completely hidden
1085 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001086
1087 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1088 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001089
1090 // Indicates whether the user is allowed to scroll away from the custom content.
1091 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001092 }
1093
Adam Cohenc2d6e892014-10-16 09:49:24 -07001094 public interface LauncherOverlay {
1095
1096 /**
1097 * Touch interaction leading to overscroll has begun
1098 */
1099 public void onScrollInteractionBegin();
1100
1101 /**
1102 * Touch interaction related to overscroll has ended
1103 */
1104 public void onScrollInteractionEnd();
1105
1106 /**
1107 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1108 * screen (or in the case of RTL, the rightmost screen).
1109 */
1110 public void onScrollChange(int progress, boolean rtl);
1111
1112 /**
1113 * Screen has stopped scrolling
1114 */
1115 public void onScrollSettled();
1116
1117 /**
1118 * This method can be called by the Launcher in order to force the LauncherOverlay
1119 * to exit fully immersive mode.
1120 */
1121 public void forceExitFullImmersion();
1122 }
1123
Jun Mukai8af0cd82015-05-12 12:32:12 -07001124 public interface LauncherSearchCallbacks {
1125 /**
1126 * Called when the search overlay is shown.
1127 */
1128 public void onSearchOverlayOpened();
1129
1130 /**
1131 * Called when the search overlay is dismissed.
1132 */
1133 public void onSearchOverlayClosed();
1134 }
1135
Adam Cohenc2d6e892014-10-16 09:49:24 -07001136 public interface LauncherOverlayCallbacks {
1137 /**
1138 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1139 * however it doesn't modify any state within the launcher.
1140 */
1141 public boolean canEnterFullImmersion();
1142
1143 /**
1144 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1145 * eg. by occupying the full screen and handling all touch events.
1146 *
1147 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1148 * case, Launcher will modify any necessary state and assumes the overlay is
1149 * handling all interaction. If false, the LauncherOverlay should cancel any
1150 *
1151 */
1152 public boolean enterFullImmersion();
1153
1154 /**
1155 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1156 * full control over UI and state.
1157 */
1158 public void exitFullImmersion();
1159 }
1160
1161 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1162
1163 @Override
1164 public boolean canEnterFullImmersion() {
1165 return mState == State.WORKSPACE;
1166 }
1167
1168 @Override
1169 public boolean enterFullImmersion() {
1170 if (mState == State.WORKSPACE) {
1171 // When fully immersed, disregard any touches which fall through.
1172 mDragLayer.setBlockTouch(true);
1173 return true;
1174 }
1175 return false;
1176 }
1177
1178 @Override
1179 public void exitFullImmersion() {
1180 mDragLayer.setBlockTouch(false);
1181 }
1182 }
1183
Jorim Jaggid017f882014-01-14 17:08:48 -08001184 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001185 if (mLauncherCallbacks != null) {
1186 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001187 } else {
1188 // On devices with a locked orientation, we will at least have the allow rotation
1189 // setting.
1190 return !Utilities.isRotationAllowedForDevice(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001191 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001192 }
1193
Adam Cohen9211d422014-10-07 18:14:53 -07001194 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001195 CustomContentCallbacks callbacks, String description) {
1196 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001197 }
1198
Adam Cohenedb40762013-07-18 16:45:45 -07001199 // The custom content needs to offset its content to account for the QSB
1200 public int getTopOffsetForCustomContent() {
1201 return mWorkspace.getPaddingTop();
1202 }
1203
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001204 @Override
1205 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001206 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001207 if (mModel.isCurrentCallbacks(this)) {
1208 mModel.stopLoader();
1209 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001210 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1211
Romain Guy13c2e7b2010-03-10 19:45:00 -08001212 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001213 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001214
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001215 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001216 @Override
1217 public void onWindowFocusChanged(boolean hasFocus) {
1218 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001219 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001220
1221 if (mLauncherCallbacks != null) {
1222 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1223 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001224 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001225
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 private boolean acceptFilter() {
1227 final InputMethodManager inputManager = (InputMethodManager)
1228 getSystemService(Context.INPUT_METHOD_SERVICE);
1229 return !inputManager.isFullscreenMode();
1230 }
1231
1232 @Override
1233 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001234 final int uniChar = event.getUnicodeChar();
1235 final boolean handled = super.onKeyDown(keyCode, event);
1236 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1237 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1239 keyCode, event);
1240 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001241 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001242 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001243 // showSearchDialog()
1244 // If there are multiple keystrokes before the search dialog takes focus,
1245 // onSearchRequested() will be called for every keystroke,
1246 // but it is idempotent, so it's fine.
1247 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 }
1249 }
1250
Joe Onorato8a9625e2010-01-28 15:55:35 -08001251 // Eat the long press event so the keyboard doesn't come up.
1252 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1253 return true;
1254 }
1255
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 return handled;
1257 }
1258
Winson46163472015-09-22 17:31:56 -07001259 @Override
1260 public boolean onKeyUp(int keyCode, KeyEvent event) {
1261 if (keyCode == KeyEvent.KEYCODE_MENU) {
1262 // Ignore the menu key if we are currently dragging or are on the custom content screen
1263 if (!isOnCustomContent() && !mDragController.isDragging()) {
1264 // Close any open folders
1265 closeFolder();
1266
1267 // Stop resizing any widgets
1268 mWorkspace.exitWidgetResizeMode();
1269
1270 // Show the overview mode if we are on the workspace
1271 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1272 !mWorkspace.isSwitchingState()) {
1273 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001274 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001275 }
1276 }
1277 return true;
1278 }
1279 return super.onKeyUp(keyCode, event);
1280 }
1281
Karl Rosaen138a0412009-04-23 19:00:21 -07001282 private String getTypedText() {
1283 return mDefaultKeySsb.toString();
1284 }
1285
1286 private void clearTypedText() {
1287 mDefaultKeySsb.clear();
1288 mDefaultKeySsb.clearSpans();
1289 Selection.setSelection(mDefaultKeySsb, 0);
1290 }
1291
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001293 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1294 * State
1295 */
1296 private static State intToState(int stateOrdinal) {
1297 State state = State.WORKSPACE;
1298 final State[] stateValues = State.values();
1299 for (int i = 0; i < stateValues.length; i++) {
1300 if (stateValues[i].ordinal() == stateOrdinal) {
1301 state = stateValues[i];
1302 break;
1303 }
1304 }
1305 return state;
1306 }
1307
1308 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 * Restores the previous state, if it exists.
1310 *
1311 * @param savedState The previous state.
1312 */
1313 private void restoreState(Bundle savedState) {
1314 if (savedState == null) {
1315 return;
1316 }
1317
Michael Jurka883f55b2010-10-21 15:47:14 -07001318 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001319 if (state == State.APPS || state == State.WIDGETS) {
1320 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001321 }
1322
Adam Cohen21cd0022013-10-09 18:57:02 -07001323 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1324 PagedView.INVALID_RESTORE_PAGE);
1325 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001326 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327 }
1328
Sunny Goyal756cd262015-08-20 12:33:21 -07001329 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1330 if (itemValues != null) {
1331 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001332 AppWidgetProviderInfo info = savedState.getParcelable(
1333 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001334 mPendingAddWidgetInfo = info == null ?
1335 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1336
Adam Cohen4637b5a2013-11-04 18:21:24 -08001337 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001338 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 mRestoring = true;
1340 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341 }
1342
1343 /**
1344 * Finds all the views we need and configure them properly.
1345 */
1346 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001347 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001348
Craig Mautner360310b2012-10-26 15:13:08 -07001349 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001350 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001351 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1352 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001353 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001354 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001355
John Spurlock77e1f472013-09-11 10:09:51 -04001356 mLauncherView.setSystemUiVisibility(
1357 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001358 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359
Winson Chung4c98d922011-05-31 16:50:48 -07001360 // Setup the drag layer
1361 mDragLayer.setup(this, dragController);
1362
Winson Chung3d503fb2011-07-13 17:25:49 -07001363 // Setup the hotseat
1364 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1365 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001366 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001367 }
1368
Winsone9f27272015-10-13 10:47:51 -07001369 // Setup the overview panel
1370 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001371
Winson Chung4c98d922011-05-31 16:50:48 -07001372 // Setup the workspace
1373 mWorkspace.setHapticFeedbackEnabled(false);
1374 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001375 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001376 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001377
Tony Wickham34d2c912015-09-11 09:27:58 -07001378 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001379 mSearchDropTargetBar = (SearchDropTargetBar)
1380 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001381 // Get the app info bar
1382 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1383 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001384
Winson Chungef7f8742015-06-04 17:18:17 -07001385 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001386 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001387 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001388 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1389 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1390 } else {
1391 mAppsView.setSearchBarController(new DefaultAppSearchController());
1392 }
Craig Mautner360310b2012-10-26 15:13:08 -07001393
Winson Chung3d503fb2011-07-13 17:25:49 -07001394 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001395 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001396 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001397 dragController.setMoveTarget(mWorkspace);
1398 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001399 if (mSearchDropTargetBar != null) {
1400 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001401 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001402 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001403 if (mAppInfoDropTargetBar != null) {
1404 mAppInfoDropTargetBar.setup(this, dragController);
1405 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001406
Sunny Goyal322d5562015-06-25 19:35:49 -07001407 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1408 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001409 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 }
1411
Winsone9f27272015-10-13 10:47:51 -07001412 private void setupOverviewPanel() {
1413 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1414
1415 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1416 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1417 @Override
1418 public boolean onLongClick(View v) {
1419 return v.performClick();
1420 }
1421 };
1422
1423 // Bind wallpaper button actions
1424 View wallpaperButton = findViewById(R.id.wallpaper_button);
1425 wallpaperButton.setOnClickListener(new OnClickListener() {
1426 @Override
1427 public void onClick(View view) {
1428 if (!mWorkspace.isSwitchingState()) {
1429 onClickWallpaperPicker(view);
1430 }
1431 }
1432 });
1433 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1434 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1435
1436 // Bind widget button actions
1437 mWidgetsButton = findViewById(R.id.widget_button);
1438 mWidgetsButton.setOnClickListener(new OnClickListener() {
1439 @Override
1440 public void onClick(View view) {
1441 if (!mWorkspace.isSwitchingState()) {
1442 onClickAddWidgetButton(view);
1443 }
1444 }
1445 });
1446 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1447 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1448
1449 // Bind settings actions
1450 View settingsButton = findViewById(R.id.settings_button);
1451 boolean hasSettings = hasSettings();
1452 if (hasSettings) {
1453 settingsButton.setOnClickListener(new OnClickListener() {
1454 @Override
1455 public void onClick(View view) {
1456 if (!mWorkspace.isSwitchingState()) {
1457 onClickSettingsButton(view);
1458 }
1459 }
1460 });
1461 settingsButton.setOnLongClickListener(performClickOnLongClick);
1462 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1463 } else {
1464 settingsButton.setVisibility(View.GONE);
1465 }
1466
1467 mOverviewPanel.setAlpha(0f);
1468 }
1469
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001471 * Sets the all apps button. This method is called from {@link Hotseat}.
1472 */
1473 public void setAllAppsButton(View allAppsButton) {
1474 mAllAppsButton = allAppsButton;
1475 }
1476
1477 public View getAllAppsButton() {
1478 return mAllAppsButton;
1479 }
1480
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001481 public View getWidgetsButton() {
1482 return mWidgetsButton;
1483 }
1484
Anjali Koppal5ad44842014-03-10 20:34:39 -07001485 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 * Creates a view representing a shortcut.
1487 *
1488 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001490 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001491 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 }
1493
1494 /**
1495 * Creates a view representing a shortcut inflated from the specified resource.
1496 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 * @param parent The group the shortcut belongs to.
1498 * @param info The data structure describing the shortcut.
1499 *
1500 * @return A View inflated from layoutResId.
1501 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001502 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001503 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001504 parent, false);
1505 favorite.applyFromShortcutInfo(info, mIconCache);
1506 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001508 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 return favorite;
1510 }
1511
1512 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 * Add a shortcut to the workspace.
1514 *
1515 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001517 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001518 int cellY) {
1519 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001520 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001521
Sunny Goyal5c97f512015-05-19 16:03:28 -07001522 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001523 if (info == null) {
1524 return;
1525 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001526 final View view = createShortcut(info);
1527
Sunny Goyal5c97f512015-05-19 16:03:28 -07001528 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001529 // First we check if we already know the exact location where we want to add this item.
1530 if (cellX >= 0 && cellY >= 0) {
1531 cellXY[0] = cellX;
1532 cellXY[1] = cellY;
1533 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001534
1535 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001536 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001537 true, null,null)) {
1538 return;
1539 }
1540 DragObject dragObject = new DragObject();
1541 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001542 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1543 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001544 return;
1545 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001546 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001547 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001548 }
1549
1550 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001551 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001552 return;
1553 }
1554
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001555 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556
1557 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001558 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001559 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 }
1561 }
1562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001564 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001566 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 */
Adam Cohen091440a2015-03-18 14:16:05 -07001568 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001569 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1570
1571 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001572 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001573 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1574 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001575 }
Romain Guycbb89e42009-06-08 15:52:54 -07001576
Adam Cohen59400422014-03-05 18:07:04 -08001577 if (appWidgetInfo.isCustomWidget) {
1578 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001579 }
1580
Adam Cohen59400422014-03-05 18:07:04 -08001581 LauncherAppWidgetInfo launcherInfo;
1582 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1583 launcherInfo.spanX = info.spanX;
1584 launcherInfo.spanY = info.spanY;
1585 launcherInfo.minSpanX = info.minSpanX;
1586 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001587 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001588
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001590 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591
1592 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001593 if (hostView == null) {
1594 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001595 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1596 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001597 } else {
1598 // The AppWidgetHostView has already been inflated and instantiated
1599 launcherInfo.hostView = hostView;
1600 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001601 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001602 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001604 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605 }
Romain Guycbb89e42009-06-08 15:52:54 -07001606
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001607 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1608 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1609 item.hostView.setTag(item);
1610 item.onBindAppWidget(this);
1611
1612 item.hostView.setFocusable(true);
1613 item.hostView.setOnFocusChangeListener(mFocusHandler);
1614
1615 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1616 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1617
1618 if (!item.isCustomWidget()) {
1619 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1620 }
1621 }
1622
Adam Cohended9f8d2010-11-03 13:25:16 -07001623 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1624 @Override
1625 public void onReceive(Context context, Intent intent) {
1626 final String action = intent.getAction();
1627 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1628 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001629 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001630 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001631
Winson Chungc100e8e2011-08-09 16:02:43 -07001632 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001633 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001634 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001635 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001636 if (!showWorkspace(false)) {
1637 // If we are already on the workspace, then manually reset all apps
1638 mAppsView.reset();
1639 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001640 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001641 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1642 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001643 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001644 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1645 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001646 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001647 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1648 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1649 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001650 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001651 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1652 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001653 }
1654 }
1655 };
1656
1657 @Override
1658 public void onAttachedToWindow() {
1659 super.onAttachedToWindow();
1660
1661 // Listen for broadcasts related to user-presence
1662 final IntentFilter filter = new IntentFilter();
1663 filter.addAction(Intent.ACTION_SCREEN_OFF);
1664 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001665 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001666 if (ENABLE_DEBUG_INTENTS) {
1667 filter.addAction(DebugIntents.DELETE_DATABASE);
1668 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1669 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001670 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001671 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001672 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001673 mVisible = true;
1674 }
1675
1676 @Override
1677 public void onDetachedFromWindow() {
1678 super.onDetachedFromWindow();
1679 mVisible = false;
1680
Adam Cohend113e0c2010-11-11 10:48:05 -08001681 if (mAttached) {
1682 unregisterReceiver(mReceiver);
1683 mAttached = false;
1684 }
Winson Chungb745afb2015-03-02 11:51:23 -08001685 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001686 }
1687
1688 public void onWindowVisibilityChanged(int visibility) {
1689 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001690 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001691 // The following code used to be in onResume, but it turns out onResume is called when
1692 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1693 // is a more appropriate event to handle
1694 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001695 if (!mWorkspaceLoading) {
1696 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001697 // We want to let Launcher draw itself at least once before we force it to build
1698 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001699 // apps is nice and speedy.
1700 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001701 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001702 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001703 if (mStarted) return;
1704 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001705 // We delay the layer building a bit in order to give
1706 // other message processing a time to run. In particular
1707 // this avoids a delay in hiding the IME if it was
1708 // currently shown, because doing that may involve
1709 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001710 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001711 final ViewTreeObserver.OnDrawListener listener = this;
1712 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001713 public void run() {
1714 if (mWorkspace != null &&
1715 mWorkspace.getViewTreeObserver() != null) {
1716 mWorkspace.getViewTreeObserver().
1717 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001718 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001719 }
1720 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001721 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001722 }
1723 });
1724 }
1725 clearTypedText();
1726 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001727 }
1728
Adam Cohen091440a2015-03-18 14:16:05 -07001729 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001730 mHandler.removeMessages(ADVANCE_MSG);
1731 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1732 mHandler.sendMessageDelayed(msg, delay);
1733 mAutoAdvanceSentTime = System.currentTimeMillis();
1734 }
1735
Adam Cohen091440a2015-03-18 14:16:05 -07001736 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001737 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1738 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1739 mAutoAdvanceRunning = autoAdvanceRunning;
1740 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001741 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001742 sendAdvanceMessage(delay);
1743 } else {
1744 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001745 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001746 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1747 }
1748 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001749 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001750 }
1751 }
1752 }
1753
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001754 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1755
Adam Cohended9f8d2010-11-03 13:25:16 -07001756 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001757 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001758 if (msg.what == ADVANCE_MSG) {
1759 int i = 0;
1760 for (View key: mWidgetsToAdvance.keySet()) {
1761 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001762 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001764 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001765 public void run() {
1766 ((Advanceable) v).advance();
1767 }
1768 }, delay);
1769 }
1770 i++;
1771 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001772 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001773 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001774 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001775 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001776 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001777
Winsonc0b52fe2015-09-09 16:38:15 -07001778 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001779 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001780 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1781 if (v instanceof Advanceable) {
1782 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001783 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001784 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001785 }
1786 }
1787
Winsonc0b52fe2015-09-09 16:38:15 -07001788 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001789 if (mWidgetsToAdvance.containsKey(hostView)) {
1790 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001791 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001792 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001793 }
1794
Hyunyoung Song3f471442015-04-08 19:01:34 -07001795 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001796 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1797 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001798 }
1799
Winson Chunga6945242014-01-08 14:04:34 -08001800 public DragLayer getDragLayer() {
1801 return mDragLayer;
1802 }
1803
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001804 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001805 return mAppsView;
1806 }
1807
Hyunyoung Song3f471442015-04-08 19:01:34 -07001808 public WidgetsContainerView getWidgetsView() {
1809 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001810 }
1811
Winson Chunga6945242014-01-08 14:04:34 -08001812 public Workspace getWorkspace() {
1813 return mWorkspace;
1814 }
1815
1816 public Hotseat getHotseat() {
1817 return mHotseat;
1818 }
1819
Jorim Jaggid017f882014-01-14 17:08:48 -08001820 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001821 return mOverviewPanel;
1822 }
1823
Winson Chung006ee262015-08-03 14:40:11 -07001824 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001825 return mSearchDropTargetBar;
1826 }
1827
Tony Wickham34d2c912015-09-11 09:27:58 -07001828 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1829 return mAppInfoDropTargetBar;
1830 }
1831
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001832 public LauncherAppWidgetHost getAppWidgetHost() {
1833 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 }
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Winson Chunga9abd0e2010-10-27 17:18:37 -07001836 public LauncherModel getModel() {
1837 return mModel;
1838 }
1839
Winson Chunga6945242014-01-08 14:04:34 -08001840 protected SharedPreferences getSharedPrefs() {
1841 return mSharedPrefs;
1842 }
1843
Adam Cohen2e6da152015-05-06 11:42:25 -07001844 public DeviceProfile getDeviceProfile() {
1845 return mDeviceProfile;
1846 }
1847
Bjorn Bringertc459e522013-06-07 19:36:01 +01001848 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001849 getWindow().closeAllPanels();
1850
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001851 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001852 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001853 }
1854
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 @Override
1856 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001857 long startTime = 0;
1858 if (DEBUG_RESUME_TIME) {
1859 startTime = System.currentTimeMillis();
1860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 super.onNewIntent(intent);
1862
1863 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001864 Folder openFolder = mWorkspace.getOpenFolder();
1865 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1866 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1867 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1868 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1869 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001870 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001871 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001872
Adam Cohen6fecd412013-10-02 17:41:50 -07001873 if (mWorkspace == null) {
1874 // Can be cases where mWorkspace is null, this prevents a NPE
1875 return;
1876 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001877 // In all these cases, only animate if we're already on home
1878 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001879
Sunny Goyal935fca12015-10-13 10:19:01 -07001880 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001881 exitSpringLoadedDragMode();
1882
1883 // If we are already on home, then just animate back to the workspace,
1884 // otherwise, just wait until onResume to set the state back to Workspace
1885 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001886 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001887 } else {
1888 mOnResumeState = State.WORKSPACE;
1889 }
1890
1891 final View v = getWindow().peekDecorView();
1892 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001893 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001894 INPUT_METHOD_SERVICE);
1895 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1896 }
1897
Winson Chungb745afb2015-03-02 11:51:23 -08001898 // Reset the apps view
1899 if (!alreadyOnHome && mAppsView != null) {
1900 mAppsView.scrollToTop();
1901 }
1902
Hyunyoung Song3f471442015-04-08 19:01:34 -07001903 // Reset the widgets view
1904 if (!alreadyOnHome && mWidgetsView != null) {
1905 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001906 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001907
Adam Cohen9211d422014-10-07 18:14:53 -07001908 if (mLauncherCallbacks != null) {
1909 mLauncherCallbacks.onHomeIntent();
1910 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 }
Adam Cohened307df2013-10-02 09:37:31 -07001912
Adam Cohen9211d422014-10-07 18:14:53 -07001913 if (mLauncherCallbacks != null) {
1914 mLauncherCallbacks.onNewIntent(intent);
1915 }
Winson15f8b172015-08-19 11:02:39 -07001916
1917 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1918 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1919 // animation.
1920 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001921 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1922 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001923 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1924 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001925
1926 // We use this flag to suppress noisy callbacks above custom content state
1927 // from onResume.
1928 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001929 mWorkspace.post(new Runnable() {
1930 @Override
1931 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001932 if (mWorkspace != null) {
1933 mWorkspace.moveToDefaultScreen(true);
1934 }
Winson15f8b172015-08-19 11:02:39 -07001935 }
1936 });
1937 }
1938 }
1939
1940 if (DEBUG_RESUME_TIME) {
1941 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1942 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001943 }
1944
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001946 public void onRestoreInstanceState(Bundle state) {
1947 super.onRestoreInstanceState(state);
1948 for (int page: mSynchronouslyBoundPages) {
1949 mWorkspace.restoreInstanceStateForChild(page);
1950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 }
1952
1953 @Override
1954 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001955 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001956 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1957 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001958 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001959 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960
Michael Jurka883f55b2010-10-21 15:47:14 -07001961 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal08442b82015-10-21 17:15:08 -07001962 Folder openFolder = mWorkspace.getOpenFolder();
1963 if (openFolder != null) {
1964 outState.putLong(RUNTIME_STATE_OPEN_FOLDER_ID, openFolder.mInfo.id);
1965 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966
Adam Cohendcd297f2013-06-18 13:13:40 -07001967 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001968 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001969 ContentValues itemValues = new ContentValues();
1970 mPendingAddInfo.writeToValues(itemValues);
1971 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001972 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001973 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001974 }
1975
Hyunyoung Song3f471442015-04-08 19:01:34 -07001976 // Save the current widgets tray?
1977 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001978
1979 if (mLauncherCallbacks != null) {
1980 mLauncherCallbacks.onSaveInstanceState(outState);
1981 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001982 }
1983
1984 @Override
1985 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001987
Winson Chunge7a03942011-08-05 15:05:12 -07001988 // Remove all pending runnables
1989 mHandler.removeMessages(ADVANCE_MSG);
1990 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001991 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001992
Winson Chungcd2b0142011-06-08 16:02:26 -07001993 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001994 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07001995
1996 // It's possible to receive onDestroy after a new Launcher activity has
1997 // been created. In this case, don't interfere with the new Launcher.
1998 if (mModel.isCurrentCallbacks(this)) {
1999 mModel.stopLoader();
2000 app.setLauncher(null);
2001 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002002
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002004 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002006 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002008 mAppWidgetHost = null;
2009
2010 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011
2012 TextKeyListener.getInstance().release();
2013
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002014 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002015
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002016 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002017 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002018 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002019 mWorkspace = null;
2020 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002021
Michael Jurka2ecf9952012-06-18 12:52:28 -07002022 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002023
2024 if (mLauncherCallbacks != null) {
2025 mLauncherCallbacks.onDestroy();
2026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
Adam Cohena9cf38f2011-05-02 15:36:58 -07002029 public DragController getDragController() {
2030 return mDragController;
2031 }
2032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 @Override
2034 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002035 onStartForResult(requestCode);
2036 super.startActivityForResult(intent, requestCode);
2037 }
2038
2039 @Override
2040 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2041 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2042 onStartForResult(requestCode);
2043 try {
2044 super.startIntentSenderForResult(intent, requestCode,
2045 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2046 } catch (IntentSender.SendIntentException e) {
2047 throw new ActivityNotFoundException();
2048 }
2049 }
2050
2051 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002052 if (requestCode >= 0) {
2053 setWaitingForResult(true);
2054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 }
2056
Winson Chung70d72102011-08-12 11:24:35 -07002057 /**
2058 * Indicates that we want global search for this activity by setting the globalSearch
2059 * argument for {@link #startSearch} to true.
2060 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002062 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002064
Karl Rosaen138a0412009-04-23 19:00:21 -07002065 if (initialQuery == null) {
2066 // Use any text typed in the launcher as the initial query
2067 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002068 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 if (appSearchData == null) {
2070 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002071 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002072 }
Winson Chungadf0c182012-08-23 14:59:07 -07002073 Rect sourceBounds = new Rect();
2074 if (mSearchDropTargetBar != null) {
2075 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2076 }
Romain Guycbb89e42009-06-08 15:52:54 -07002077
Ian Parkinson047036e2014-09-01 15:40:53 +01002078 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002079 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002080 if (clearTextImmediately) {
2081 clearTypedText();
2082 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002083
2084 // We need to show the workspace after starting the search
2085 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002086 }
2087
Ian Parkinson047036e2014-09-01 15:40:53 +01002088 /**
2089 * Start a text search.
2090 *
2091 * @return {@code true} if the search will start immediately, so any further keypresses
2092 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2093 * to buffer keypresses.
2094 */
2095 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002096 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002097 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2098 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2099 sourceBounds);
2100 }
2101
Michael Jurkaa33411c2012-06-14 16:18:21 -07002102 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002103 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002104 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002105 }
2106
2107 /**
2108 * Starts the global search activity. This code is a copied from SearchManager
2109 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002110 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002111 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002112 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002113 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2114 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2115 if (globalSearchActivity == null) {
2116 Log.w(TAG, "No global search activity found.");
2117 return;
2118 }
2119 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2120 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2121 intent.setComponent(globalSearchActivity);
2122 // Make sure that we have a Bundle to put source in
2123 if (appSearchData == null) {
2124 appSearchData = new Bundle();
2125 } else {
2126 appSearchData = new Bundle(appSearchData);
2127 }
Adam Cohen9211d422014-10-07 18:14:53 -07002128 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002129 if (!appSearchData.containsKey("source")) {
2130 appSearchData.putString("source", getPackageName());
2131 }
2132 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2133 if (!TextUtils.isEmpty(initialQuery)) {
2134 intent.putExtra(SearchManager.QUERY, initialQuery);
2135 }
2136 if (selectInitialQuery) {
2137 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2138 }
2139 intent.setSourceBounds(sourceBounds);
2140 try {
2141 startActivity(intent);
2142 } catch (ActivityNotFoundException ex) {
2143 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2144 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145 }
2146
Yura4f93ec62014-02-04 14:15:21 +00002147 public boolean isOnCustomContent() {
2148 return mWorkspace.isOnOrMovingToCustomContent();
2149 }
2150
Winson Chung70d72102011-08-12 11:24:35 -07002151 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002152 public boolean onPrepareOptionsMenu(Menu menu) {
2153 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002154 if (mLauncherCallbacks != null) {
2155 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2156 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002157 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002158 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002160 @Override
2161 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002162 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002163 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002164 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002165 }
2166
Joe Onorato9c1289c2009-08-17 11:03:03 -04002167 public boolean isWorkspaceLocked() {
2168 return mWorkspaceLoading || mWaitingForResult;
2169 }
2170
Adam Cohen517a7f52014-03-01 12:12:59 -08002171 public boolean isWorkspaceLoading() {
2172 return mWorkspaceLoading;
2173 }
2174
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002175 private void setWorkspaceLoading(boolean value) {
2176 boolean isLocked = isWorkspaceLocked();
2177 mWorkspaceLoading = value;
2178 if (isLocked != isWorkspaceLocked()) {
2179 onWorkspaceLockedChanged();
2180 }
2181 }
2182
2183 private void setWaitingForResult(boolean value) {
2184 boolean isLocked = isWorkspaceLocked();
2185 mWaitingForResult = value;
2186 if (isLocked != isWorkspaceLocked()) {
2187 onWorkspaceLockedChanged();
2188 }
2189 }
2190
Adam Cohen9211d422014-10-07 18:14:53 -07002191 protected void onWorkspaceLockedChanged() {
2192 if (mLauncherCallbacks != null) {
2193 mLauncherCallbacks.onWorkspaceLockedChanged();
2194 }
2195 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002196
Michael Jurka0280c3b2010-09-17 15:00:07 -07002197 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002198 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002199 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002200 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2201 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002202 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002204
Tony Wickhama0628cc2015-10-14 15:23:04 -07002205 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002206 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002207 if (LOGD) {
2208 Log.d(TAG, "Adding widget from drop");
2209 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002210 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2211 }
2212
Sunny Goyale6b63a32015-01-16 16:14:29 -08002213 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002214 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2215 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002216 if (appWidgetInfo.configure != null) {
2217 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002218 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002219
Bjorn Bringert7984c942009-12-09 15:38:25 +00002220 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002221 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2222 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2223
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002224 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002225 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002226 Runnable onComplete = new Runnable() {
2227 @Override
2228 public void run() {
2229 // Exit spring loaded mode if necessary after adding the widget
2230 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2231 null);
2232 }
2233 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002234 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002235 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002236 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002237 }
2238 }
Romain Guycbb89e42009-06-08 15:52:54 -07002239
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002240 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002241 // Close any folders that may be open.
2242 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002243 mWorkspace.moveToCustomContentScreen(animate);
2244 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002245
2246 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2247 int[] cell, int spanX, int spanY) {
2248 switch (info.itemType) {
2249 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2250 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2251 int span[] = new int[2];
2252 span[0] = spanX;
2253 span[1] = spanY;
2254 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2255 container, screenId, cell, span);
2256 break;
2257 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2258 processShortcutFromDrop(info.componentName, container, screenId, cell);
2259 break;
2260 default:
2261 throw new IllegalStateException("Unknown item type: " + info.itemType);
2262 }
2263 }
2264
Adam Cohenfbba09b2011-07-18 21:43:05 -07002265 /**
2266 * Process a shortcut drop.
2267 *
2268 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002269 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002270 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002271 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002272 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2273 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002274 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002275 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002276 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002277
2278 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002279 mPendingAddInfo.cellX = cell[0];
2280 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002281 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002282
2283 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2284 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002285 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002286 }
2287
Adam Cohenfbba09b2011-07-18 21:43:05 -07002288 /**
2289 * Process a widget drop.
2290 *
2291 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002292 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002293 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002294 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002295 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2296 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002297 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002298 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002299 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002300 mPendingAddInfo.minSpanX = info.minSpanX;
2301 mPendingAddInfo.minSpanY = info.minSpanY;
2302
Adam Cohenfbba09b2011-07-18 21:43:05 -07002303 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 mPendingAddInfo.cellX = cell[0];
2305 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002306 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002307 if (span != null) {
2308 mPendingAddInfo.spanX = span[0];
2309 mPendingAddInfo.spanY = span[1];
2310 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002311
Adam Cohened66b2b2012-01-23 17:28:51 -08002312 AppWidgetHostView hostView = info.boundWidget;
2313 int appWidgetId;
2314 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002315 // In the case where we've prebound the widget, we remove it from the DragLayer
2316 if (LOGD) {
2317 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2318 }
2319 getDragLayer().removeView(hostView);
2320
Adam Cohened66b2b2012-01-23 17:28:51 -08002321 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002322 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002323
2324 // Clear the boundWidget so that it doesn't get destroyed.
2325 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002326 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002327 // In this case, we either need to start an activity to get permission to bind
2328 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002329 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002330 Bundle options = info.bindOptions;
2331
Sunny Goyalffe83f12014-08-14 17:39:34 -07002332 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2333 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002334 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002335 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002336 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002337 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002338 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2339 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2340 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002341 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2342 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002343 // TODO: we need to make sure that this accounts for the options bundle.
2344 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002345 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2346 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002347 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002348 }
2349
Adam Cohendcd297f2013-06-18 13:13:40 -07002350 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002351 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002352 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002353 folderInfo.title = getText(R.string.folder_name);
2354
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002355 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002356 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2357 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002358 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002359
2360 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002361 FolderIcon newFolder =
2362 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002363 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002364 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002365 // Force measure the new folder icon
2366 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2367 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002368 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 }
Romain Guycbb89e42009-06-08 15:52:54 -07002370
Winsonc0b52fe2015-09-09 16:38:15 -07002371 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002372 * Unbinds the view for the specified item, and removes the item and all its children.
2373 *
2374 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002375 * @param itemInfo the {@link ItemInfo} for this view.
2376 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002377 */
Winson2949fb52015-09-24 09:56:11 -07002378 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002379 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002380 // Remove the shortcut from the folder before removing it from launcher
Winson2949fb52015-09-24 09:56:11 -07002381 FolderInfo folderInfo = sFolders.get(itemInfo.container);
2382 if (folderInfo != null) {
2383 folderInfo.remove((ShortcutInfo) itemInfo);
Winsonfa56b3f2015-09-14 12:01:13 -07002384 } else {
2385 mWorkspace.removeWorkspaceItem(v);
2386 }
Winsonc0b52fe2015-09-09 16:38:15 -07002387 if (deleteFromDb) {
2388 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2389 }
2390 } else if (itemInfo instanceof FolderInfo) {
2391 final FolderInfo folderInfo = (FolderInfo) itemInfo;
2392 unbindFolder(folderInfo);
2393 mWorkspace.removeWorkspaceItem(v);
2394 if (deleteFromDb) {
2395 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2396 }
2397 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2398 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002399 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002400 removeWidgetToAutoAdvance(widgetInfo.hostView);
2401 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002402 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002403 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002404 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002405
Winsonc0b52fe2015-09-09 16:38:15 -07002406 } else {
2407 return false;
2408 }
2409 return true;
2410 }
2411
2412 /**
2413 * Unbinds any launcher references to the folder.
2414 */
2415 private void unbindFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002416 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002417 }
2418
Winsonc0b52fe2015-09-09 16:38:15 -07002419 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002420 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002421 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002422 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002423 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002424 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002425 // Deleting an app widget ID is a void call but writes to disk before returning
2426 // to the caller...
2427 new AsyncTask<Void, Void, Void>() {
2428 public Void doInBackground(Void ... args) {
2429 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2430 return null;
2431 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002432 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002433 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002434 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002435 }
2436
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002437 @Override
2438 public boolean dispatchKeyEvent(KeyEvent event) {
2439 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2440 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002441 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002442 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002443 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002444 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002445 dumpState();
2446 return true;
2447 }
2448 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002449 }
2450 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2451 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002452 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002453 return true;
2454 }
2455 }
2456
2457 return super.dispatchKeyEvent(event);
2458 }
2459
Joe Onorato88ec0992009-11-19 13:16:06 -08002460 @Override
2461 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002462 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2463 return;
2464 }
2465
Sunny Goyal45478022015-06-08 16:52:41 -07002466 if (mDragController.isDragging()) {
2467 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002468 return;
2469 }
2470
Winson Chungb745afb2015-03-02 11:51:23 -08002471 if (isAppsViewVisible()) {
2472 showWorkspace(true);
2473 } else if (isWidgetsViewVisible()) {
2474 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002475 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002476 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002477 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002478 Folder openFolder = mWorkspace.getOpenFolder();
2479 if (openFolder.isEditingName()) {
2480 openFolder.dismissEditingName();
2481 } else {
2482 closeFolder();
2483 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002484 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002485 mWorkspace.exitWidgetResizeMode();
2486
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002487 // Back button is a no-op here, but give at least some feedback for the button press
2488 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002489 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002490 }
2491
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002492 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002493 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002494 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002495 @Override
2496 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002497 if (mAppWidgetHost != null) {
2498 mAppWidgetHost.startListening();
2499 }
Sunny Goyal655daae2015-12-08 09:28:23 -08002500
2501 // Recreate the QSB, as the widget has been reset.
2502 bindSearchProviderChanged();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002503 }
2504
2505 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002506 * Launches the intent referred by the clicked shortcut.
2507 *
2508 * @param v The view representing the clicked shortcut.
2509 */
2510 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002511 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2512 // view has detached (it's possible for this to happen if the view is removed mid touch).
2513 if (v.getWindowToken() == null) {
2514 return;
2515 }
2516
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002517 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002518 return;
2519 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002520
Adam Cohen1697b792013-09-17 19:08:21 -07002521 if (v instanceof Workspace) {
2522 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002523 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002524 }
2525 return;
2526 }
2527
2528 if (v instanceof CellLayout) {
2529 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002530 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2531 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002532 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002533 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002534 }
2535
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002536 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002537 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002538 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002539 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002540 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002541 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002542 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002543 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002544 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002545 } else if (tag instanceof AppInfo) {
2546 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002547 } else if (tag instanceof LauncherAppWidgetInfo) {
2548 if (v instanceof PendingAppWidgetHostView) {
2549 onClickPendingWidget((PendingAppWidgetHostView) v);
2550 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002551 }
2552 }
2553
Sunny Goyal70660032015-05-14 00:07:08 -07002554 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002555 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002556 return false;
2557 }
2558
Michael Jurkaaf442092010-06-10 17:01:57 -07002559 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002560 * Event handler for the app widget view which has not fully restored.
2561 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002562 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002563 if (mIsSafeModeEnabled) {
2564 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2565 return;
2566 }
2567
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002568 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002569 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002570 int widgetId = info.appWidgetId;
2571 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2572 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002573 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2574 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002575 mPendingAddInfo.copyFrom(info);
2576 mPendingAddWidgetId = widgetId;
2577
Sunny Goyalffe83f12014-08-14 17:39:34 -07002578 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2579 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002580 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002581 } else if (info.installProgress < 0) {
2582 // The install has not been queued
2583 final String packageName = info.providerName.getPackageName();
2584 showBrokenAppInstallDialog(packageName,
2585 new DialogInterface.OnClickListener() {
2586 public void onClick(DialogInterface dialog, int id) {
2587 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2588 }
2589 });
2590 } else {
2591 // Download has started.
2592 final String packageName = info.providerName.getPackageName();
2593 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002594 }
2595 }
2596
2597 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002598 * Event handler for the "grid" button that appears on the home screen, which
2599 * enters all apps mode.
2600 *
2601 * @param v The view that was clicked.
2602 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002603 protected void onClickAllAppsButton(View v) {
2604 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002605 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002606 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002607 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002608
2609 if (mLauncherCallbacks != null) {
2610 mLauncherCallbacks.onClickAllAppsButton(v);
2611 }
Winson Chung76648c52015-07-10 14:33:23 -07002612 }
2613 }
2614
2615 protected void onLongClickAllAppsButton(View v) {
2616 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2617 if (!isAppsViewVisible()) {
2618 showAppsView(true /* animated */, false /* resetListToTop */,
2619 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002620 }
2621 }
2622
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002623 private void showBrokenAppInstallDialog(final String packageName,
2624 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002625 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002626 .setTitle(R.string.abandoned_promises_title)
2627 .setMessage(R.string.abandoned_promise_explanation)
2628 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2629 .setNeutralButton(R.string.abandoned_clean_this,
2630 new DialogInterface.OnClickListener() {
2631 public void onClick(DialogInterface dialog, int id) {
2632 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2633 mWorkspace.removeAbandonedPromise(packageName, user);
2634 }
2635 })
2636 .create().show();
2637 return;
2638 }
2639
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002640 /**
2641 * Event handler for an app shortcut click.
2642 *
2643 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2644 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002645 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002646 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2647 Object tag = v.getTag();
2648 if (!(tag instanceof ShortcutInfo)) {
2649 throw new IllegalArgumentException("Input must be a Shortcut");
2650 }
2651
2652 // Open shortcut
2653 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002654
2655 if (shortcut.isDisabled != 0) {
Kenny Guyff05f432016-01-22 17:48:29 +00002656 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SUSPENDED) != 0
2657 || (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_QUIET_USER) != 0) {
Kenny Guy44cba692016-01-21 19:50:02 +00002658 // Launch activity anyway, framework will tell the user why the app is suspended.
2659 } else {
2660 int error = R.string.activity_not_available;
2661 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2662 error = R.string.safemode_shortcut_error;
2663 }
2664 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2665 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002666 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002667 }
2668
Chris Wren40c5ed32014-06-24 18:24:23 -04002669 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002670 if ((v instanceof BubbleTextView)
2671 && shortcut.isPromise()
2672 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002673 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002674 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002675 new DialogInterface.OnClickListener() {
2676 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002677 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002678 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002679 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002680 return;
2681 }
2682
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002683 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002684 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002685
2686 if (mLauncherCallbacks != null) {
2687 mLauncherCallbacks.onClickAppShortcut(v);
2688 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002689 }
2690
Adam Cohen091440a2015-03-18 14:16:05 -07002691 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002692 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002693 final ShortcutInfo shortcut;
2694 final Intent intent;
2695 if (tag instanceof ShortcutInfo) {
2696 shortcut = (ShortcutInfo) tag;
2697 intent = shortcut.intent;
2698 int[] pos = new int[2];
2699 v.getLocationOnScreen(pos);
2700 intent.setSourceBounds(new Rect(pos[0], pos[1],
2701 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002702
Sunny Goyal508da152014-08-14 10:53:27 -07002703 } else if (tag instanceof AppInfo) {
2704 shortcut = null;
2705 intent = ((AppInfo) tag).intent;
2706 } else {
2707 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2708 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002709
2710 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002711 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002712
2713 if (success && v instanceof BubbleTextView) {
2714 mWaitingForResume = (BubbleTextView) v;
2715 mWaitingForResume.setStayPressed(true);
2716 }
2717 }
2718
2719 /**
2720 * Event handler for a folder icon click.
2721 *
2722 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2723 */
2724 protected void onClickFolderIcon(View v) {
2725 if (LOGD) Log.d(TAG, "onClickFolder");
2726 if (!(v instanceof FolderIcon)){
2727 throw new IllegalArgumentException("Input must be a FolderIcon");
2728 }
2729
2730 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002731 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002732 // Open the requested folder
Sunny Goyal08442b82015-10-21 17:15:08 -07002733 openFolder(folderIcon, true);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002734 }
Adam Cohen9211d422014-10-07 18:14:53 -07002735
2736 if (mLauncherCallbacks != null) {
2737 mLauncherCallbacks.onClickFolderIcon(v);
2738 }
Michael Jurka5130e402011-10-13 04:55:35 -07002739 }
2740
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002741 /**
2742 * Event handler for the (Add) Widgets button that appears after a long press
2743 * on the home screen.
2744 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002745 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002746 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002747 if (mIsSafeModeEnabled) {
2748 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2749 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002750 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002751 if (mLauncherCallbacks != null) {
2752 mLauncherCallbacks.onClickAddWidgetButton(view);
2753 }
Adam Cohen9211d422014-10-07 18:14:53 -07002754 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002755 }
2756
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002757 /**
2758 * Event handler for the wallpaper picker button that appears after a long press
2759 * on the home screen.
2760 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002761 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002762 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002763 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2764 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
2765 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
Sunny Goyal5abb9f82016-02-09 15:22:42 -08002766 .putExtra(WallpaperUtils.EXTRA_WALLPAPER_OFFSET, offset),
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002767 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002768
2769 if (mLauncherCallbacks != null) {
2770 mLauncherCallbacks.onClickWallpaperPicker(v);
2771 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002772 }
2773
2774 /**
2775 * Event handler for a click on the settings button that appears after a long press
2776 * on the home screen.
2777 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002778 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002779 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002780 if (mLauncherCallbacks != null) {
2781 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002782 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002783 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002784 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002785 }
2786
Adam Cohen61f560d2013-09-30 15:58:20 -07002787 public View.OnTouchListener getHapticFeedbackTouchListener() {
2788 if (mHapticFeedbackTouchListener == null) {
2789 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002790 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002791 @Override
2792 public boolean onTouch(View v, MotionEvent event) {
2793 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2794 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2795 }
2796 return false;
2797 }
2798 };
2799 }
2800 return mHapticFeedbackTouchListener;
2801 }
2802
Adam Cohen9211d422014-10-07 18:14:53 -07002803 public void onDragStarted(View view) {
2804 if (isOnCustomContent()) {
2805 // Custom content screen doesn't participate in drag and drop. If on custom
2806 // content screen, move to default.
2807 moveWorkspaceToDefaultScreen();
2808 }
2809
2810 if (mLauncherCallbacks != null) {
2811 mLauncherCallbacks.onDragStarted(view);
2812 }
2813 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002814
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002815 /**
2816 * Called when the user stops interacting with the launcher.
2817 * This implies that the user is now on the homescreen and is not doing housekeeping.
2818 */
Adam Cohen9211d422014-10-07 18:14:53 -07002819 protected void onInteractionEnd() {
2820 if (mLauncherCallbacks != null) {
2821 mLauncherCallbacks.onInteractionEnd();
2822 }
2823 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002824
2825 /**
2826 * Called when the user starts interacting with the launcher.
2827 * The possible interactions are:
2828 * - open all apps
2829 * - reorder an app shortcut, or a widget
2830 * - open the overview mode.
2831 * This is a good time to stop doing things that only make sense
2832 * when the user is on the homescreen and not doing housekeeping.
2833 */
Adam Cohen9211d422014-10-07 18:14:53 -07002834 protected void onInteractionBegin() {
2835 if (mLauncherCallbacks != null) {
2836 mLauncherCallbacks.onInteractionBegin();
2837 }
2838 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002839
Winson Chungcd99cd32015-04-29 11:03:24 -07002840 /** Updates the interaction state. */
2841 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002842 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002843 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002844 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2845 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002846 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002847 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002848 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002849 onInteractionEnd();
2850 }
2851 }
2852
Kenny Guyf07af7b2014-07-31 11:39:16 +01002853 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002854 try {
2855 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002856 launcherApps.showAppDetailsForProfile(componentName, user);
2857 } catch (SecurityException e) {
2858 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2859 Log.e(TAG, "Launcher does not have permission to launch settings");
2860 } catch (ActivityNotFoundException e) {
2861 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2862 Log.e(TAG, "Unable to launch settings");
2863 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002864 }
2865
Michael Jurka1e2f4652013-07-08 18:03:46 -07002866 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002867 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2868 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002869 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002870 // System applications cannot be installed. For now, show a toast explaining that.
2871 // We may give them the option of disabling apps this way.
2872 int messageId = R.string.uninstall_system_app_text;
2873 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002874 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002875 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002876 String packageName = componentName.getPackageName();
2877 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002878 Intent intent = new Intent(
2879 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002880 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2881 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002882 if (user != null) {
2883 user.addToIntent(intent, Intent.EXTRA_USER);
2884 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002885 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002886 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002887 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002888 }
2889
Winson Chung8f1eff72015-05-28 17:33:40 -07002890 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002891 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002892 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002893 // Only launch using the new animation if the shortcut has not opted out (this is a
2894 // private contract between launcher and may be ignored in the future).
2895 boolean useLaunchAnimation = (v != null) &&
2896 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002897 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2898 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002899
Kenny Guy1317e2d2014-05-08 18:52:50 +01002900 UserHandleCompat user = null;
2901 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2902 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2903 user = userManager.getUserForSerialNumber(serialNumber);
2904 }
2905
2906 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002907 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002908 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002909 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002910 int left = 0, top = 0;
2911 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2912 if (v instanceof TextView) {
2913 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002914 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2915 if (icon != null) {
2916 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002917 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002918 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002919 width = bounds.width();
2920 height = bounds.height();
2921 }
2922 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002923 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2924 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002925 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002926 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002927 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002928 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002929 // On L devices, we use the device default slide-up transition.
2930 // On L MR1 devices, we a custom version of the slide-up transition which
2931 // doesn't have the delay present in the device default.
2932 opts = ActivityOptions.makeCustomAnimation(this,
2933 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002934 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002935 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002936 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002937
2938 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2939 // Could be launching some bookkeeping activity
2940 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002941 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002942 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002943 launcherApps.startActivityForProfile(intent.getComponent(), user,
2944 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002945 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002946 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002947 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002948 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2949 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2950 // corresponding permission. Show the appropriate permission prompt if that
2951 // is the case.
2952 if (intent.getComponent() == null
2953 && Intent.ACTION_CALL.equals(intent.getAction())
2954 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2955 PackageManager.PERMISSION_GRANTED) {
2956 // TODO: Rename sPendingAddItem to a generic name.
2957 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2958 0, (ItemInfo) tag);
2959 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2960 REQUEST_PERMISSION_CALL_PHONE);
2961 return false;
2962 }
2963 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002964 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002965 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002966 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002967 "or use the exported attribute for this activity. "
2968 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002969 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002970 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002971 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002972
Winson Chungbedf9232015-07-10 12:38:30 -07002973 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002974 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002975 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2976 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2977 return false;
2978 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002979 try {
2980 success = startActivity(v, intent, tag);
2981 } catch (ActivityNotFoundException e) {
2982 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2983 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2984 }
2985 return success;
2986 }
2987
Adam Cohen268c4752012-06-06 17:47:33 -07002988 /**
2989 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2990 * in the DragLayer in the exact absolute location of the original FolderIcon.
2991 */
2992 private void copyFolderIconToImage(FolderIcon fi) {
2993 final int width = fi.getMeasuredWidth();
2994 final int height = fi.getMeasuredHeight();
2995
2996 // Lazy load ImageView, Bitmap and Canvas
2997 if (mFolderIconImageView == null) {
2998 mFolderIconImageView = new ImageView(this);
2999 }
3000 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3001 mFolderIconBitmap.getHeight() != height) {
3002 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3003 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3004 }
3005
3006 DragLayer.LayoutParams lp;
3007 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3008 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3009 } else {
3010 lp = new DragLayer.LayoutParams(width, height);
3011 }
3012
Adam Cohen307fe232012-08-16 17:55:58 -07003013 // The layout from which the folder is being opened may be scaled, adjust the starting
3014 // view size by this scale factor.
3015 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003016 lp.customPosition = true;
3017 lp.x = mRectForFolderAnimation.left;
3018 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003019 lp.width = (int) (scale * width);
3020 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003021
3022 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3023 fi.draw(mFolderIconCanvas);
3024 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003025 if (fi.getFolder() != null) {
3026 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3027 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003028 }
Adam Cohen268c4752012-06-06 17:47:33 -07003029 // Just in case this image view is still in the drag layer from a previous animation,
3030 // we remove it and re-add it.
3031 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3032 mDragLayer.removeView(mFolderIconImageView);
3033 }
3034 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003035 if (fi.getFolder() != null) {
3036 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003037 }
Adam Cohen268c4752012-06-06 17:47:33 -07003038 }
3039
Sunny Goyal08442b82015-10-21 17:15:08 -07003040 private void growAndFadeOutFolderIcon(FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003041 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003042 FolderInfo info = (FolderInfo) fi.getTag();
3043 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3044 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003045 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3046 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003047 }
3048
Adam Cohen268c4752012-06-06 17:47:33 -07003049 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3050 copyFolderIconToImage(fi);
3051 fi.setVisibility(View.INVISIBLE);
3052
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003053 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3054 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003055 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003056 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3057 }
3058 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003059 oa.start();
Sunny Goyal08442b82015-10-21 17:15:08 -07003060 if (!animate) {
Tony Wickham112ac952015-11-12 12:31:50 -08003061 oa.end();
3062 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003063 }
3064
Sunny Goyal935fca12015-10-13 10:19:01 -07003065 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003066 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003067 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003068
Adam Cohen268c4752012-06-06 17:47:33 -07003069 // We remove and re-draw the FolderIcon in-case it has changed
3070 mDragLayer.removeView(mFolderIconImageView);
3071 copyFolderIconToImage(fi);
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003072 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003073 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003074 oa.addListener(new AnimatorListenerAdapter() {
3075 @Override
3076 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003077 if (cl != null) {
3078 cl.clearFolderLeaveBehind();
3079 // Remove the ImageView copy of the FolderIcon and make the original visible.
3080 mDragLayer.removeView(mFolderIconImageView);
3081 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003082 }
3083 }
3084 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003085 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003086 if (!animate) {
3087 oa.end();
3088 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003089 }
3090
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003091 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003092 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003093 * is animated relative to the specified View. If the View is null, no animation
3094 * is played.
3095 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003096 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003097 */
Sunny Goyal08442b82015-10-21 17:15:08 -07003098 public void openFolder(FolderIcon folderIcon, boolean animate) {
3099 animate &= !Utilities.isPowerSaverOn(this);
3100
Adam Cohenfb91f302012-06-11 15:45:18 -07003101 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003102 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3103 if (openFolder != null && openFolder != folder) {
3104 // Close any open folder before opening a folder.
3105 closeFolder();
3106 }
3107
Adam Cohena9cf38f2011-05-02 15:36:58 -07003108 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003109
Adam Cohena9cf38f2011-05-02 15:36:58 -07003110 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003111
Sunny Goyalf4066152015-04-15 09:42:19 -07003112 // While the folder is open, the position of the icon cannot change.
3113 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3114
Adam Cohen4554ee12011-08-03 16:13:21 -07003115 // Just verify that the folder hasn't already been added to the DragLayer.
3116 // There was a one-off crash where the folder had a parent already.
3117 if (folder.getParent() == null) {
3118 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003119 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003120 } else {
3121 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3122 folder.getParent() + ").");
3123 }
Sunny Goyal08442b82015-10-21 17:15:08 -07003124 if (animate) {
3125 folder.animateOpen();
3126 } else {
3127 folder.open();
3128 }
3129 growAndFadeOutFolderIcon(folderIcon, animate);
Winson Chung83ca4802013-04-12 15:10:52 -07003130
3131 // Notify the accessibility manager that this folder "window" has appeared and occluded
3132 // the workspace items
3133 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3134 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003135 }
3136
3137 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003138 closeFolder(true);
3139 }
3140
3141 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003142 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003143 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003144 if (folder.isEditingName()) {
3145 folder.dismissEditingName();
3146 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003147 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003148 }
3149 }
3150
Sunny Goyal935fca12015-10-13 10:19:01 -07003151 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003152 animate &= !Utilities.isPowerSaverOn(this);
3153
Adam Cohen4554ee12011-08-03 16:13:21 -07003154 folder.getInfo().opened = false;
3155
3156 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3157 if (parent != null) {
3158 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003159 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003160 if (fi != null) {
3161 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3162 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003163 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003164 if (animate) {
3165 folder.animateClosed();
3166 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003167 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003168 }
Winson Chung83ca4802013-04-12 15:10:52 -07003169
Sunny Goyal935fca12015-10-13 10:19:01 -07003170 // Notify the accessibility manager that this folder "window" has disappeared and no
3171 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003172 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003173 }
3174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003175 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003176 if (!isDraggingEnabled()) return false;
3177 if (isWorkspaceLocked()) return false;
3178 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003179
Winson Chung76648c52015-07-10 14:33:23 -07003180 if (v == mAllAppsButton) {
3181 onLongClickAllAppsButton(v);
3182 return true;
3183 }
3184
Adam Cohen1697b792013-09-17 19:08:21 -07003185 if (v instanceof Workspace) {
3186 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003187 if (!mWorkspace.isTouchActive()) {
3188 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003189 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3190 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3191 return true;
3192 } else {
3193 return false;
3194 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003195 } else {
3196 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003197 }
Adam Cohen1697b792013-09-17 19:08:21 -07003198 }
3199
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003200 CellLayout.CellInfo longClickCellInfo = null;
3201 View itemUnderLongClick = null;
3202 if (v.getTag() instanceof ItemInfo) {
3203 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003204 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003205 itemUnderLongClick = longClickCellInfo.cell;
3206 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003207 }
3208
Winson Chung3d503fb2011-07-13 17:25:49 -07003209 // The hotseat touch handling does not go through Workspace, and we always allow long press
3210 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003211 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003212 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003213 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003214 // User long pressed on empty space
3215 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3216 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003217 if (mWorkspace.isInOverviewMode()) {
3218 mWorkspace.startReordering(v);
3219 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003220 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003222 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003223 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3224 mHotseat.getOrderInHotseat(
3225 longClickCellInfo.cellX,
3226 longClickCellInfo.cellY));
3227 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003228 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003229 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003230 }
3231 }
3232 }
3233 return true;
3234 }
3235
Winson Chung3d503fb2011-07-13 17:25:49 -07003236 boolean isHotseatLayout(View layout) {
3237 return mHotseat != null && layout != null &&
3238 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3239 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003240
Winson Chung3d503fb2011-07-13 17:25:49 -07003241 /**
3242 * Returns the CellLayout of the specified container at the specified screen.
3243 */
Sunny Goyal92820592015-03-02 11:31:35 -08003244 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003245 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3246 if (mHotseat != null) {
3247 return mHotseat.getLayout();
3248 } else {
3249 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003250 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003251 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003252 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003253 }
3254 }
3255
Winson Chungb745afb2015-03-02 11:51:23 -08003256 /**
3257 * For overridden classes.
3258 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003259 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003260 return isAppsViewVisible();
3261 }
3262
3263 public boolean isAppsViewVisible() {
3264 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3265 }
3266
3267 public boolean isWidgetsViewVisible() {
3268 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003269 }
3270
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003271 private void setWorkspaceBackground(int background) {
3272 switch (background) {
3273 case WORKSPACE_BACKGROUND_TRANSPARENT:
3274 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3275 break;
3276 case WORKSPACE_BACKGROUND_BLACK:
3277 getWindow().setBackgroundDrawable(null);
3278 break;
3279 default:
3280 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3281 }
Craig Mautner360310b2012-10-26 15:13:08 -07003282 }
3283
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003284 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003285 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3286 int curflags = getWindow().getAttributes().flags
3287 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3288 if (wpflags != curflags) {
3289 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3290 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003291 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003292 }
3293
Michael Jurkae326f182011-11-21 14:05:46 -08003294 @Override
3295 public void onTrimMemory(int level) {
3296 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003297 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3298 // The widget preview db can result in holding onto over
3299 // 3MB of memory for caching which isn't necessary.
3300 SQLiteDatabase.releaseMemory();
3301
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003302 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003303 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003304 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003305 if (mLauncherCallbacks != null) {
3306 mLauncherCallbacks.onTrimMemory(level);
3307 }
Michael Jurkae326f182011-11-21 14:05:46 -08003308 }
3309
Winson5c6bdbb2015-09-03 11:36:19 -07003310 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003311 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003312 }
3313
Winson5c6bdbb2015-09-03 11:36:19 -07003314 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003315 boolean changed = mState != State.WORKSPACE ||
3316 mWorkspace.getState() != Workspace.State.NORMAL;
3317 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003318 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003319 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003320 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003321
Michael Jurkab3e22d92011-10-31 15:58:33 -07003322 // Set focus to the AppsCustomize button
3323 if (mAllAppsButton != null) {
3324 mAllAppsButton.requestFocus();
3325 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003326 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003327
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003328 // Change the state *after* we've called all the transition code
3329 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003330
Winson Chung5fb63472011-02-02 17:03:37 -08003331 // Resume the auto-advance of widgets
3332 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003333 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003334
Winson Chung0f785722015-04-08 10:27:49 -07003335 if (changed) {
3336 // Send an accessibility event to announce the context change
3337 getWindow().getDecorView()
3338 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003339 }
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -08003340 mUserEventLogger.resetElapsedContainerMillis();
Winson5c6bdbb2015-09-03 11:36:19 -07003341 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003342 }
3343
Winsone9f27272015-10-13 10:47:51 -07003344 /**
3345 * Shows the overview button.
3346 */
Adam Cohened307df2013-10-02 09:37:31 -07003347 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003348 showOverviewMode(animated, false);
3349 }
3350
3351 /**
3352 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3353 * onto one of the overview panel buttons.
3354 */
3355 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3356 Runnable postAnimRunnable = null;
3357 if (requestButtonFocus) {
3358 postAnimRunnable = new Runnable() {
3359 @Override
3360 public void run() {
3361 // Hitting the menu button when in touch mode does not trigger touch mode to
3362 // be disabled, so if requested, force focus on one of the overview panel
3363 // buttons.
3364 mOverviewPanel.requestFocusFromTouch();
3365 }
3366 };
3367 }
Adam Cohened307df2013-10-02 09:37:31 -07003368 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003369 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003370 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003371 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003372 }
3373
Winson Chungb745afb2015-03-02 11:51:23 -08003374 /**
3375 * Shows the apps view.
3376 */
Winson Chung76648c52015-07-10 14:33:23 -07003377 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3378 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003379 if (resetListToTop) {
3380 mAppsView.scrollToTop();
3381 }
Winson Chung4ac30062015-05-08 17:34:17 -07003382 if (updatePredictedApps) {
3383 tryAndUpdatePredictedApps();
3384 }
Winson Chung76648c52015-07-10 14:33:23 -07003385 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003386 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003387
Winson Chungb745afb2015-03-02 11:51:23 -08003388 /**
3389 * Shows the widgets view.
3390 */
3391 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003392 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003393 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003394 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003395 }
Winson Chung76648c52015-07-10 14:33:23 -07003396 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003397
3398 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003399 @Override
3400 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003401 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003402 }
3403 });
Winson Chungb745afb2015-03-02 11:51:23 -08003404 }
3405
3406 /**
3407 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003408 *
3409 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003410 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003411 // TODO: calling method should use the return value so that when {@code false} is returned
3412 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003413 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003414 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3415 mState != State.WIDGETS_SPRING_LOADED) {
3416 return false;
3417 }
3418 if (toState != State.APPS && toState != State.WIDGETS) {
3419 return false;
3420 }
Winson Chungb745afb2015-03-02 11:51:23 -08003421
3422 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003423 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3424 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003425 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003426 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003427 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003428
Michael Jurkab3e22d92011-10-31 15:58:33 -07003429 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003430 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003431
3432 // Pause the auto-advance of widgets until we are out of AllApps
3433 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003434 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003435 closeFolder();
3436
3437 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003438 getWindow().getDecorView()
3439 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003440 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003441 }
3442
Winson Chungcd99cd32015-04-29 11:03:24 -07003443 /**
3444 * Updates the workspace and interaction state on state change, and return the animation to this
3445 * new state.
3446 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003447 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003448 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003449 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003450 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003451 updateInteraction(fromState, toState);
3452 return anim;
3453 }
3454
Jun Mukaif0033da2015-08-04 18:34:30 -07003455 public void onLauncherClingShown() {
3456 // When a launcher cling appears, it should cover the underlying layers, so their focus
3457 // should be blocked.
3458 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3459 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3460 }
3461 }
3462
3463 public void onLauncherClingDismissed() {
3464 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3465 }
3466
Hyunyoung Song3f471442015-04-08 19:01:34 -07003467 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003468 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003469 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003470 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003471 }
Winson Chungb745afb2015-03-02 11:51:23 -08003472
Winson Chung006ee262015-08-03 14:40:11 -07003473 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003474 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003475 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003476
3477 if (isAppsViewVisible()) {
3478 mState = State.APPS_SPRING_LOADED;
3479 } else if (isWidgetsViewVisible()) {
3480 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003481 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003482 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003483 } else {
3484 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003485 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003486 }
Adam Cohen7777d962011-08-18 18:58:38 -07003487
Hyunyoung Song3f471442015-04-08 19:01:34 -07003488 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003489 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003490 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003491
Winson Chunge7a03942011-08-05 15:05:12 -07003492 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003493 @Override
3494 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003495 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003496 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3497 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003498 // Before we show workspace, hide all apps again because
3499 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3500 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003501 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003502 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003503 } else {
3504 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003505 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003506 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003507 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003508 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003509
Tony Wickhame0c33232016-02-08 11:37:04 -08003510 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003511 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3512 || mState == State.WIDGETS_SPRING_LOADED;
3513 }
3514
Michael Jurkad3ef3062010-11-23 16:23:58 -08003515 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003516 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003517 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003518 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003519 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003520 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003521 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3522 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003523 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003524 }
3525
Winson Chung4ac30062015-05-08 17:34:17 -07003526 /**
3527 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3528 * resumed.
3529 */
3530 private void tryAndUpdatePredictedApps() {
3531 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003532 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003533 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003534 mAppsView.setPredictedApps(apps);
3535 }
3536 }
3537 }
3538
Michael Jurkab3e22d92011-10-31 15:58:33 -07003539 void lockAllApps() {
3540 // TODO
3541 }
3542
3543 void unlockAllApps() {
3544 // TODO
3545 }
3546
Sunny Goyal594d76d2014-11-06 10:12:54 -08003547 protected void disableVoiceButtonProxy(boolean disable) {
3548 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003549 }
3550
Winsonf768d932015-09-25 16:12:35 -07003551 public boolean launcherCallbacksProvidesSearch() {
3552 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3553 }
3554
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003555 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003556 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003557 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003558 }
3559
Adam Cohen24ce0b32014-01-14 16:18:14 -08003560 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003561 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3562 if (searchProvider == null) {
3563 return null;
3564 }
3565
3566 Bundle opts = new Bundle();
3567 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003568 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003569
Tony Wickham3a3517f2015-10-06 11:27:04 -07003570 // Determine the min and max dimensions of the widget.
3571 LauncherAppState app = LauncherAppState.getInstance();
3572 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3573 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3574 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003575 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3576 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003577 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003578 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003579 int minWidth = maxWidth;
3580 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003581 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3582 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3583 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3584 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3585 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003586 }
3587 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3588 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3589 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3590 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003591 if (LOGD) {
3592 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3593 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3594 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003595
Tony Wickham775455c2015-10-16 09:49:32 -07003596 if (mLauncherCallbacks != null) {
3597 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3598 }
3599
Sunny Goyalf7258242015-10-19 16:59:07 -07003600 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003601 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003602 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003603 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003604 || (widgetInfo == null)
3605 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003606 // A valid widget is not already bound.
3607 if (widgetId > -1) {
3608 mAppWidgetHost.deleteAppWidgetId(widgetId);
3609 widgetId = -1;
3610 }
3611
3612 // Try to bind a new widget
3613 widgetId = mAppWidgetHost.allocateAppWidgetId();
3614
3615 if (!AppWidgetManagerCompat.getInstance(this)
3616 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3617 mAppWidgetHost.deleteAppWidgetId(widgetId);
3618 widgetId = -1;
3619 }
3620
Sunny Goyalf7258242015-10-19 16:59:07 -07003621 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003622 .putInt(QSB_WIDGET_ID, widgetId)
3623 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
Sunny Goyald8043982015-12-17 22:23:02 -08003624 .apply();
Sunny Goyal594d76d2014-11-06 10:12:54 -08003625 }
3626
Sunny Goyal8d595092015-07-06 12:22:14 -07003627 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003628 if (widgetId != -1) {
3629 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003630 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003631 mQsb.updateAppWidgetOptions(opts);
3632 mQsb.setPadding(0, 0, 0, 0);
3633 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003634 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003635 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003636 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003637 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003638 }
3639
Sunny Goyal22235bc2015-04-03 09:23:43 -07003640 private void reinflateQSBIfNecessary() {
3641 if (mQsb instanceof LauncherAppWidgetHostView &&
3642 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3643 mSearchDropTargetBar.removeView(mQsb);
3644 mQsb = null;
3645 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3646 }
3647 }
3648
Michael Jurkad7c28052012-04-27 15:43:36 -07003649 @Override
3650 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003651 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003652 final List<CharSequence> text = event.getText();
3653 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003654 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003655 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003656 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003657 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003658 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003659 } else if (mWorkspace != null) {
3660 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003661 } else {
3662 text.add(getString(R.string.all_apps_home_button_label));
3663 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003664 return result;
3665 }
3666
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003667 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003668 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003669 */
Adam Cohen091440a2015-03-18 14:16:05 -07003670 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003671 @Override
3672 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003673 closeSystemDialogs();
3674 }
3675 }
3676
3677 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003678 * If the activity is currently paused, signal that we need to run the passed Runnable
3679 * in onResume.
3680 *
3681 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003682 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3683 * wrong when we're not running, and if the activity comes back to what the configuration was
3684 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003685 *
3686 * Implementation of the method from LauncherModel.Callbacks.
3687 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003688 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003689 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003690 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003691 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003692 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003693 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003694 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003695 }
3696 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003697 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003698 return true;
3699 } else {
3700 return false;
3701 }
3702 }
3703
Michael Jurkac402cd92013-05-20 15:49:32 +02003704 private boolean waitUntilResume(Runnable run) {
3705 return waitUntilResume(run, false);
3706 }
3707
Michael Jurka1e2f4652013-07-08 18:03:46 -07003708 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003709 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003710 }
3711
Michael Jurka7607c2f2013-04-03 14:33:19 -07003712 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003713 * If the activity is currently paused, signal that we need to re-run the loader
3714 * in onResume.
3715 *
3716 * This needs to be called from incoming places where resources might have been loaded
3717 * while we are paused. That is becaues the Configuration might be wrong
3718 * when we're not running, and if it comes back to what it was when we
3719 * were paused, we are not restarted.
3720 *
3721 * Implementation of the method from LauncherModel.Callbacks.
3722 *
3723 * @return true if we are currently paused. The caller might be able to
3724 * skip some work in that case since we will come back again.
3725 */
3726 public boolean setLoadOnResume() {
3727 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003728 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003729 mOnResumeNeedsLoad = true;
3730 return true;
3731 } else {
3732 return false;
3733 }
3734 }
3735
3736 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003738 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003739 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003740 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003741 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003742 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003743 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003744 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003745 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003746
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003748 * Clear any pending bind callbacks. This is called when is loader is planning to
3749 * perform a full rebind from scratch.
3750 */
3751 @Override
3752 public void clearPendingBinds() {
3753 mBindOnResumeCallbacks.clear();
3754 if (mPendingExecutor != null) {
3755 mPendingExecutor.markCompleted();
3756 mPendingExecutor = null;
3757 }
3758 }
3759
3760 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003761 * Refreshes the shortcuts shown on the workspace.
3762 *
3763 * Implementation of the method from LauncherModel.Callbacks.
3764 */
3765 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003766 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003767
Winson Chungd64d1762013-08-20 14:37:16 -07003768 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003769 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003770 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003771
Michael Jurka05bf644e2011-11-30 20:28:53 -08003772 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003773 if (mHotseat != null) {
3774 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003775 }
3776 }
3777
Adam Cohendcd297f2013-06-18 13:13:40 -07003778 @Override
3779 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003780 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003781
Adam Cohen5084cba2013-09-03 12:01:16 -07003782 // If there are no screens, we need to have an empty screen
3783 if (orderedScreenIds.size() == 0) {
3784 mWorkspace.addExtraEmptyScreen();
3785 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003786
3787 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003788 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003789 if (hasCustomContentToLeft()) {
3790 mWorkspace.createCustomContentContainer();
3791 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003792 }
Winson Chung64359a52013-07-08 17:17:08 -07003793 }
3794
3795 @Override
3796 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003797 int count = orderedScreenIds.size();
3798 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003799 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003800 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003801 }
3802
Winson Chungd64d1762013-08-20 14:37:16 -07003803 public void bindAppsAdded(final ArrayList<Long> newScreens,
3804 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003805 final ArrayList<ItemInfo> addAnimated,
3806 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003807 Runnable r = new Runnable() {
3808 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003809 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003810 }
3811 };
3812 if (waitUntilResume(r)) {
3813 return;
3814 }
3815
Winson Chungd64d1762013-08-20 14:37:16 -07003816 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003817 if (newScreens != null) {
3818 bindAddScreens(newScreens);
3819 }
Winson Chungd64d1762013-08-20 14:37:16 -07003820
3821 // We add the items without animation on non-visible pages, and with
3822 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003823 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003824 bindItems(addNotAnimated, 0,
3825 addNotAnimated.size(), false);
3826 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003827 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003828 bindItems(addAnimated, 0,
3829 addAnimated.size(), true);
3830 }
Winson Chungc58497e2013-09-03 17:48:37 -07003831
Winson Chung87412982013-10-03 18:34:14 -07003832 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003833 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003834
Winson Chungb745afb2015-03-02 11:51:23 -08003835 if (addedApps != null && mAppsView != null) {
3836 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003837 }
Winson Chungd64d1762013-08-20 14:37:16 -07003838 }
3839
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003840 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003841 * Bind the items start-end from the list.
3842 *
3843 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003844 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003845 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003846 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3847 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003848 Runnable r = new Runnable() {
3849 public void run() {
3850 bindItems(shortcuts, start, end, forceAnimateIcons);
3851 }
3852 };
3853 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003854 return;
3855 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003856
Winson Chungf0c6ae02012-03-21 16:10:31 -07003857 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003858 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3859 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003860 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003861 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003862 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003863 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003864 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003865
3866 // Short circuit if we are loading dock items for a configuration which has no dock
3867 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3868 mHotseat == null) {
3869 continue;
3870 }
3871
Sunny Goyal639e9062015-08-19 19:17:06 -07003872 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003873 switch (item.itemType) {
3874 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3875 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003876 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003877 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003878
Winson Chung64359a52013-07-08 17:17:08 -07003879 /*
3880 * TODO: FIX collision case
3881 */
Winson Chungce376632013-07-11 16:12:41 -07003882 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3883 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3884 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003885 View v = cl.getChildAt(item.cellX, item.cellY);
3886 Object tag = v.getTag();
3887 String desc = "Collision while binding workspace item: " + item
3888 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003889 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003890 throw (new RuntimeException(desc));
3891 } else {
3892 Log.d(TAG, desc);
3893 }
Winson Chungce376632013-07-11 16:12:41 -07003894 }
Winson Chung64359a52013-07-08 17:17:08 -07003895 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003896 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003897 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003898 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003899 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003900 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003901 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003902 default:
3903 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003904 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003905
3906 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3907 item.cellY, 1, 1);
3908 if (animateIcons) {
3909 // Animate all the applications up now
3910 view.setAlpha(0f);
3911 view.setScaleX(0f);
3912 view.setScaleY(0f);
3913 bounceAnims.add(createNewAppBounceAnimation(view, i));
3914 newShortcutsScreenId = item.screenId;
3915 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003916 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003917
Winson Chung997a9232013-07-24 15:33:46 -07003918 if (animateIcons) {
3919 // Animate to the correct page
3920 if (newShortcutsScreenId > -1) {
3921 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003922 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003923 final Runnable startBounceAnimRunnable = new Runnable() {
3924 public void run() {
3925 anim.playTogether(bounceAnims);
3926 anim.start();
3927 }
3928 };
Winson Chung997a9232013-07-24 15:33:46 -07003929 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003930 // We post the animation slightly delayed to prevent slowdowns
3931 // when we are loading right after we return to launcher.
3932 mWorkspace.postDelayed(new Runnable() {
3933 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003934 if (mWorkspace != null) {
3935 mWorkspace.snapToPage(newScreenIndex);
3936 mWorkspace.postDelayed(startBounceAnimRunnable,
3937 NEW_APPS_ANIMATION_DELAY);
3938 }
Winson Chung94d67682013-09-25 16:29:40 -07003939 }
3940 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003941 } else {
3942 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003943 }
3944 }
Winson Chung64359a52013-07-08 17:17:08 -07003945 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003946 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003947 }
3948
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 /**
3950 * Implementation of the method from LauncherModel.Callbacks.
3951 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003952 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003953 Runnable r = new Runnable() {
3954 public void run() {
3955 bindFolders(folders);
3956 }
3957 };
3958 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003959 return;
3960 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003961 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003963
3964 /**
3965 * Add the views for a widget to the workspace.
3966 *
3967 * Implementation of the method from LauncherModel.Callbacks.
3968 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003969 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003970 Runnable r = new Runnable() {
3971 public void run() {
3972 bindAppWidget(item);
3973 }
3974 };
3975 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003976 return;
3977 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003978
Daniel Sandler843e8602010-06-07 14:59:01 -04003979 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3980 if (DEBUG_WIDGETS) {
3981 Log.d(TAG, "bindAppWidget: " + item);
3982 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003983 final Workspace workspace = mWorkspace;
3984
Adam Cohen59400422014-03-05 18:07:04 -08003985 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00003986 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08003987
Sunny Goyal9b4b0812014-10-08 10:47:28 -07003988 if (!mIsSafeModeEnabled
3989 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003990 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
3991
Sunny Goyalff572272014-07-23 13:58:07 -07003992 if (appWidgetInfo == null) {
3993 if (DEBUG_WIDGETS) {
3994 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3995 + " belongs to component " + item.providerName
3996 + ", as the povider is null");
3997 }
3998 LauncherModel.deleteItemFromDatabase(this, item);
3999 return;
4000 }
Sunny Goyalff572272014-07-23 13:58:07 -07004001
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004002 // If we do not have a valid id, try to bind an id.
4003 if ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0) {
4004 // Note: This assumes that the id remap broadcast is received before this step.
4005 // If that is not the case, the id remap will be ignored and user may see the
4006 // click to setup view.
4007 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
4008 pendingInfo.spanX = item.spanX;
4009 pendingInfo.spanY = item.spanY;
4010 pendingInfo.minSpanX = item.minSpanX;
4011 pendingInfo.minSpanY = item.minSpanY;
Sunny Goyalb740f592015-12-17 23:22:42 -08004012 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004013
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004014 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4015 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4016 newWidgetId, appWidgetInfo, options);
4017
4018 // TODO consider showing a permission dialog when the widget is clicked.
4019 if (!success) {
4020 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4021 if (DEBUG_WIDGETS) {
4022 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4023 + " belongs to component " + item.providerName
4024 + ", as the launcher is unable to bing a new widget id");
4025 }
4026 LauncherModel.deleteItemFromDatabase(this, item);
4027 return;
Sunny Goyalff572272014-07-23 13:58:07 -07004028 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004029
4030 item.appWidgetId = newWidgetId;
4031
4032 // If the widget has a configure activity, it is still needs to set it up, otherwise
4033 // the widget is ready to go.
4034 item.restoreStatus = (appWidgetInfo.configure == null)
4035 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4036 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4037
4038 LauncherModel.updateItemInDatabase(this, item);
4039 } else if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0)
4040 && (appWidgetInfo.configure == null)) {
4041 // If the ID is already valid, verify if we need to configure or not.
4042 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4043 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004044 }
Sunny Goyalff572272014-07-23 13:58:07 -07004045 }
4046
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004047 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004048 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004049 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004050 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4051 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004052 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004053
Sunny Goyal56c73602015-09-25 12:55:01 -07004054 // Verify that we own the widget
4055 AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4056 if (info == null || appWidgetInfo == null ||
4057 !info.provider.equals(appWidgetInfo.provider)) {
Hyunyoung Song70264a92016-02-03 15:28:47 -08004058 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId + " info=" + info
4059 + " appWidgetInfo=" + appWidgetInfo);
Sunny Goyal56c73602015-09-25 12:55:01 -07004060 deleteWidgetInfo(item);
4061 return;
4062 }
4063
Sunny Goyal651077b2014-06-30 14:15:31 -07004064 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004065 item.minSpanX = appWidgetInfo.minSpanX;
4066 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal651077b2014-06-30 14:15:31 -07004067 } else {
4068 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004069 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4070 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004071 view.updateIcon(mIconCache);
4072 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004073 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004074 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004075 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004076
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07004077 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004078 workspace.requestLayout();
4079
Daniel Sandler843e8602010-06-07 14:59:01 -04004080 if (DEBUG_WIDGETS) {
4081 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4082 + (SystemClock.uptimeMillis()-start) + "ms");
4083 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004084 }
4085
Sunny Goyalff572272014-07-23 13:58:07 -07004086 /**
4087 * Restores a pending widget.
4088 *
4089 * @param appWidgetId The app widget id
4090 * @param cellInfo The position on screen where to create the widget.
4091 */
4092 private void completeRestoreAppWidget(final int appWidgetId) {
4093 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4094 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4095 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4096 return;
4097 }
4098
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004099 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004100 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4101
4102 mWorkspace.reinflateWidgetsIfNecessary();
4103 LauncherModel.updateItemInDatabase(this, info);
4104 }
4105
Adam Cohen1462de32012-07-24 22:34:36 -07004106 public void onPageBoundSynchronously(int page) {
4107 mSynchronouslyBoundPages.add(page);
4108 }
4109
Sunny Goyal527c7d32015-08-28 15:19:36 -07004110 @Override
4111 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4112 if (mPendingExecutor != null) {
4113 mPendingExecutor.markCompleted();
4114 }
4115 mPendingExecutor = executor;
4116 executor.attachTo(this);
4117 }
4118
4119 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4120 if (mPendingExecutor == executor) {
4121 mPendingExecutor = null;
4122 }
4123 }
4124
Joe Onorato9c1289c2009-08-17 11:03:03 -04004125 /**
4126 * Callback saying that there aren't any more items to bind.
4127 *
4128 * Implementation of the method from LauncherModel.Callbacks.
4129 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004130 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004131 Runnable r = new Runnable() {
4132 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004133 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004134 }
4135 };
4136 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004137 return;
4138 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 if (mSavedState != null) {
4140 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004141 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004142 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004143
4144 long folderId = mSavedState.getLong(RUNTIME_STATE_OPEN_FOLDER_ID);
4145 if (folderId != 0) {
4146 View view = mWorkspace.getHomescreenIconByItemId(folderId);
4147 if (view instanceof FolderIcon) {
4148 FolderIcon icon = (FolderIcon) view;
4149 FolderInfo info = icon.getFolderInfo();
4150 long currentScreenId = mWorkspace.getScreenIdForPageIndex(
4151 mWorkspace.getNextPage());
4152 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
4153 || info.screenId == currentScreenId) {
4154 // We can show the folder
4155 openFolder(icon, false);
4156 } else {
4157 Launcher.addDumpLog(TAG, "Saved state contains folder " + info +
4158 " but current screen is " + currentScreenId);
4159 }
4160 }
4161 }
4162
Joe Onorato9c1289c2009-08-17 11:03:03 -04004163 mSavedState = null;
4164 }
4165
Adam Cohen1462de32012-07-24 22:34:36 -07004166 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004167
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004168 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004169 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004170
4171 // If we received the result of any pending adds while the loader was running (e.g. the
4172 // widget configuration forced an orientation change), process them now.
4173 if (sPendingAddItem != null) {
4174 final long screenId = completeAdd(sPendingAddItem);
4175
4176 // TODO: this moves the user to the page where the pending item was added. Ideally,
4177 // the screen would be guaranteed to exist after bind, and the page would be set through
4178 // the workspace restore process.
4179 mWorkspace.post(new Runnable() {
4180 @Override
4181 public void run() {
4182 mWorkspace.snapToScreenId(screenId);
4183 }
4184 });
4185 sPendingAddItem = null;
4186 }
4187
Sunny Goyal756adbc2015-04-16 15:20:51 -07004188 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004189
4190 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004191 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004192 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004193 }
4194
Adam Cohen3ed316a2014-07-23 18:21:20 -07004195 private void sendLoadingCompleteBroadcastIfNecessary() {
4196 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4197 String permission =
4198 getResources().getString(R.string.receive_first_load_broadcast_permission);
4199 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4200 sendBroadcast(intent, permission);
4201 SharedPreferences.Editor editor = mSharedPrefs.edit();
4202 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4203 editor.apply();
4204 }
4205 }
4206
Winson Chunga0b7e862013-09-05 16:03:15 -07004207 public boolean isAllAppsButtonRank(int rank) {
4208 if (mHotseat != null) {
4209 return mHotseat.isAllAppsButtonRank(rank);
4210 }
4211 return false;
4212 }
4213
Winson Chunga2413752012-04-03 14:22:34 -07004214 private boolean canRunNewAppsAnimation() {
4215 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004216 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4217 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004218 }
4219
Winson Chungc9168342013-06-26 14:54:55 -07004220 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004221 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004222 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4223 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004224 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004225 return bounceAnim;
4226 }
4227
Adam Cohen27772732013-11-11 14:00:56 +00004228 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004229 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004230 }
4231
Tony Wickham3a3517f2015-10-06 11:27:04 -07004232 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004233 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004234 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004235 }
4236
Tony Wickham55616cd2015-09-23 14:55:17 -07004237 public int getSearchBarHeight() {
4238 if (mLauncherCallbacks != null) {
4239 return mLauncherCallbacks.getSearchBarHeight();
4240 }
4241 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4242 }
4243
Winson Chung88fa7412015-08-03 14:25:28 -07004244 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004245 if (mSearchDropTargetBar == null) {
4246 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004247 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004248 if (mQsb != null) {
4249 mSearchDropTargetBar.removeView(mQsb);
4250 mQsb = null;
4251 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004252 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004253 }
4254
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004255 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004256 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4257 * multiple calls to bind the same list.)
4258 */
4259 @Thunk ArrayList<AppInfo> mTmpAppsList;
4260 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4261 public void run() {
4262 bindAllApplications(mTmpAppsList);
4263 mTmpAppsList = null;
4264 }
4265 };
4266
4267 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004268 * Add the icons for all apps.
4269 *
4270 * Implementation of the method from LauncherModel.Callbacks.
4271 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004272 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004273 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4274 mTmpAppsList = apps;
4275 return;
4276 }
4277
Winson Chungb745afb2015-03-02 11:51:23 -08004278 if (mAppsView != null) {
4279 mAppsView.setApps(apps);
4280 }
Adam Cohen9211d422014-10-07 18:14:53 -07004281 if (mLauncherCallbacks != null) {
4282 mLauncherCallbacks.bindAllApplications(apps);
4283 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004284 }
4285
4286 /**
4287 * A package was updated.
4288 *
4289 * Implementation of the method from LauncherModel.Callbacks.
4290 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004291 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004292 Runnable r = new Runnable() {
4293 public void run() {
4294 bindAppsUpdated(apps);
4295 }
4296 };
4297 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004298 return;
4299 }
4300
Winson Chungb745afb2015-03-02 11:51:23 -08004301 if (mAppsView != null) {
4302 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004303 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004304 }
4305
Sunny Goyal4390ace2014-10-13 11:33:11 -07004306 @Override
4307 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4308 Runnable r = new Runnable() {
4309 public void run() {
4310 bindWidgetsRestored(widgets);
4311 }
4312 };
4313 if (waitUntilResume(r)) {
4314 return;
4315 }
4316 mWorkspace.widgetsRestored(widgets);
4317 }
4318
Joe Onorato9c1289c2009-08-17 11:03:03 -04004319 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004320 * Some shortcuts were updated in the background.
4321 *
4322 * Implementation of the method from LauncherModel.Callbacks.
4323 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004324 @Override
4325 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4326 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004327 Runnable r = new Runnable() {
4328 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004329 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004330 }
4331 };
4332 if (waitUntilResume(r)) {
4333 return;
4334 }
4335
Sunny Goyal4390ace2014-10-13 11:33:11 -07004336 if (!updated.isEmpty()) {
4337 mWorkspace.updateShortcuts(updated);
4338 }
4339
4340 if (!removed.isEmpty()) {
4341 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4342 for (ShortcutInfo si : removed) {
4343 removedComponents.add(si.getTargetComponent());
4344 }
4345 mWorkspace.removeItemsByComponentName(removedComponents, user);
4346 // Notify the drag controller
4347 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004348 }
4349 }
4350
4351 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004352 * Update the state of a package, typically related to install state.
4353 *
4354 * Implementation of the method from LauncherModel.Callbacks.
4355 */
Sunny Goyale755d462014-07-22 13:48:29 -07004356 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004357 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4358 Runnable r = new Runnable() {
4359 public void run() {
4360 bindRestoreItemsChange(updates);
4361 }
4362 };
4363 if (waitUntilResume(r)) {
4364 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004365 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004366
Sunny Goyal756adbc2015-04-16 15:20:51 -07004367 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004368 }
4369
4370 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004371 * A package was uninstalled. We take both the super set of packageNames
4372 * in addition to specific applications to remove, the reason being that
4373 * this can be called when a package is updated as well. In that scenario,
4374 * we only remove specific components from the workspace, where as
4375 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004376 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004377 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004378 * Implementation of the method from LauncherModel.Callbacks.
4379 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004380 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004381 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004382 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004383 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004384 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004385 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004386 }
Winson Chungd64d1762013-08-20 14:37:16 -07004387 };
4388 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004389 return;
4390 }
4391
Sunny Goyal1a745e82014-10-02 15:58:31 -07004392 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004393 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4394 for (AppInfo info : appInfos) {
4395 removedComponents.add(info.componentName);
4396 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004397 if (!packageNames.isEmpty()) {
4398 mWorkspace.removeItemsByPackageName(packageNames, user);
4399 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004400 if (!removedComponents.isEmpty()) {
4401 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004402 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004403 // Notify the drag controller
4404 mDragController.onAppsRemoved(packageNames, removedComponents);
4405
Sunny Goyal1a745e82014-10-02 15:58:31 -07004406 } else {
4407 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004408 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004409
Winson Chungdf95eb12013-10-16 14:57:07 -07004410 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004411 if (mAppsView != null) {
4412 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004413 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004414 }
Joe Onoratobe386092009-11-17 17:32:16 -08004415
Michael Jurkac402cd92013-05-20 15:49:32 +02004416 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004417 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004418 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004419 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004420 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004421
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004422 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004423 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004424 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004425 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004426 return;
4427 }
4428
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004429 if (mWidgetsView != null && model != null) {
4430 mWidgetsView.addWidgets(model);
4431 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004432 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004433 }
4434
Winson Chung400438b2011-01-16 17:53:48 -08004435 private int mapConfigurationOriActivityInfoOri(int configOri) {
4436 final Display d = getWindowManager().getDefaultDisplay();
4437 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4438 switch (d.getRotation()) {
4439 case Surface.ROTATION_0:
4440 case Surface.ROTATION_180:
4441 // We are currently in the same basic orientation as the natural orientation
4442 naturalOri = configOri;
4443 break;
4444 case Surface.ROTATION_90:
4445 case Surface.ROTATION_270:
4446 // We are currently in the other basic orientation to the natural orientation
4447 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4448 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4449 break;
4450 }
4451
4452 int[] oriMap = {
4453 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4454 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4455 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4456 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4457 };
4458 // Since the map starts at portrait, we need to offset if this device's natural orientation
4459 // is landscape.
4460 int indexOffset = 0;
4461 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4462 indexOffset = 1;
4463 }
4464 return oriMap[(d.getRotation() + indexOffset) % 4];
4465 }
Adam Cohen446e9402011-09-15 18:21:21 -07004466
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004467 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004468 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004469 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004470 if (Utilities.ATLEAST_JB_MR2) {
4471 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4472 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004473 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4474 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004475 }
Winson Chung4b919f82012-05-01 10:44:08 -07004476 }
4477 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004478
Winson Chung4b919f82012-05-01 10:44:08 -07004479 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004480 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004481 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004482 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004483 } else {
4484 mHandler.postDelayed(new Runnable() {
4485 public void run() {
4486 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4487 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004488 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004489 }
Winson Chung4b919f82012-05-01 10:44:08 -07004490 }
Winson Chung400438b2011-01-16 17:53:48 -08004491 }
4492
Winson Chunge43a1e72014-01-15 10:33:02 -08004493 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004494 if (mLauncherCallbacks != null) {
4495 return mLauncherCallbacks.isLauncherPreinstalled();
4496 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004497 PackageManager pm = getPackageManager();
4498 try {
4499 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4500 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4501 return true;
4502 } else {
4503 return false;
4504 }
4505 } catch (NameNotFoundException e) {
4506 e.printStackTrace();
4507 return false;
4508 }
4509 }
4510
Adam Cohenea90f832014-05-21 15:03:34 -07004511 /**
4512 * This method indicates whether or not we should suggest default wallpaper dimensions
4513 * when our wallpaper cropper was not yet used to set a wallpaper.
4514 */
4515 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004516 if (mLauncherCallbacks != null) {
4517 return mLauncherCallbacks.overrideWallpaperDimensions();
4518 }
Adam Cohenea90f832014-05-21 15:03:34 -07004519 return true;
4520 }
4521
Adam Cohen432609a2014-03-13 17:03:22 -07004522 /**
4523 * To be overridden by subclasses to indicate that there is an activity to launch
4524 * before showing the standard launcher experience.
4525 */
4526 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004527 if (mLauncherCallbacks != null) {
4528 return mLauncherCallbacks.hasFirstRunActivity();
4529 }
Adam Cohen432609a2014-03-13 17:03:22 -07004530 return false;
4531 }
4532
4533 /**
4534 * To be overridden by subclasses to launch any first run activity
4535 */
4536 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004537 if (mLauncherCallbacks != null) {
4538 return mLauncherCallbacks.getFirstRunActivity();
4539 }
Adam Cohen432609a2014-03-13 17:03:22 -07004540 return null;
4541 }
4542
Winson Chunga6945242014-01-08 14:04:34 -08004543 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004544 return !ActivityManager.isRunningInTestHarness() &&
4545 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004546 }
4547
Adam Cohen4a9423d2014-03-28 14:22:31 -07004548 protected boolean hasRunFirstRunActivity() {
4549 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4550 }
4551
Adam Cohen432609a2014-03-13 17:03:22 -07004552 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004553 if (shouldRunFirstRunActivity() &&
4554 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004555 Intent firstRunIntent = getFirstRunActivity();
4556 if (firstRunIntent != null) {
4557 startActivity(firstRunIntent);
4558 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004559 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004560 }
4561 }
Adam Cohen432609a2014-03-13 17:03:22 -07004562 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004563 }
4564
4565 private void markFirstRunActivityShown() {
4566 SharedPreferences.Editor editor = mSharedPrefs.edit();
4567 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4568 editor.apply();
4569 }
4570
Adam Cohen432609a2014-03-13 17:03:22 -07004571 /**
4572 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4573 * screen that must be displayed and dismissed.
4574 */
4575 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004576 if (mLauncherCallbacks != null) {
4577 return mLauncherCallbacks.hasDismissableIntroScreen();
4578 }
Adam Cohen432609a2014-03-13 17:03:22 -07004579 return false;
4580 }
4581
4582 /**
4583 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4584 */
4585 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004586 if (mLauncherCallbacks != null) {
4587 return mLauncherCallbacks.getIntroScreen();
4588 }
Adam Cohen432609a2014-03-13 17:03:22 -07004589 return null;
4590 }
4591
4592 /**
4593 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4594 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4595 */
4596 private boolean shouldShowIntroScreen() {
4597 return hasDismissableIntroScreen() &&
4598 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4599 }
4600
4601 protected void showIntroScreen() {
4602 View introScreen = getIntroScreen();
4603 changeWallpaperVisiblity(false);
4604 if (introScreen != null) {
4605 mDragLayer.showOverlayView(introScreen);
4606 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004607 if (mLauncherOverlayContainer != null) {
4608 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4609 }
Adam Cohen432609a2014-03-13 17:03:22 -07004610 }
4611
4612 public void dismissIntroScreen() {
4613 markIntroScreenDismissed();
4614 if (showFirstRunActivity()) {
4615 // We delay hiding the intro view until the first run activity is showing. This
4616 // avoids a blip.
4617 mWorkspace.postDelayed(new Runnable() {
4618 @Override
4619 public void run() {
4620 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004621 if (mLauncherOverlayContainer != null) {
4622 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4623 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004624 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004625 }
4626 }, ACTIVITY_START_DELAY);
4627 } else {
4628 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004629 if (mLauncherOverlayContainer != null) {
4630 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4631 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004632 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004633 }
4634 changeWallpaperVisiblity(true);
4635 }
4636
4637 private void markIntroScreenDismissed() {
4638 SharedPreferences.Editor editor = mSharedPrefs.edit();
4639 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4640 editor.apply();
4641 }
4642
Adam Cohen091440a2015-03-18 14:16:05 -07004643 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004644 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4645 // on the device, then we always show the first run cling experience (or if there is no
4646 // launcher2). Otherwise, we prompt the user upon started for migration
4647 LauncherClings launcherClings = new LauncherClings(this);
4648 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004649 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004650 if (mModel.canMigrateFromOldLauncherDb(this)) {
4651 launcherClings.showMigrationCling();
4652 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004653 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004654 }
4655 }
4656 }
4657
Winson Chunga6945242014-01-08 14:04:34 -08004658 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004659 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4660 if (mHotseat != null) mHotseat.setAlpha(1f);
4661 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004662 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4663 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004664 }
4665
4666 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004667 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4668 if (mHotseat != null) mHotseat.setAlpha(0f);
4669 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004670 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4671 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004672 }
4673
Winson Chung5ffd51d2015-06-25 11:36:50 -07004674 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004675 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004676 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004677 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004678 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004679 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004680 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4681 if (userHandle != null) {
4682 user = UserHandleCompat.fromUser(userHandle);
4683 }
4684 }
4685 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004686 }
4687
4688 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004689 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004690 if (user == null) {
4691 user = UserHandleCompat.myUserHandle();
4692 }
4693
4694 // Called from search suggestion, add the profile extra to the intent to ensure that we
4695 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004696 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004697 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004698 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004699 return null;
4700 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004701 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004702 }
4703
Winson Chung5ffd51d2015-06-25 11:36:50 -07004704 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004705 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4706 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004707 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004708 UserHandleCompat.myUserHandle());
4709 }
4710
Winson Chung5ffd51d2015-06-25 11:36:50 -07004711 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004712 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4713 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004714 mWorkspace.onExternalDragStartedWithItem(dragView);
4715 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004716 }
4717
Winson Chung5ffd51d2015-06-25 11:36:50 -07004718 protected void moveWorkspaceToDefaultScreen() {
4719 mWorkspace.moveToDefaultScreen(false);
4720 }
4721
Anjali Koppalf5d29132014-02-28 13:33:27 -08004722 @Override
4723 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004724 if (mLauncherCallbacks != null) {
4725 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4726 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004727 }
4728
Winson Chung80baf5a2010-08-09 16:03:15 -07004729 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004730 * Returns a FastBitmapDrawable with the icon, accurately sized.
4731 */
4732 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4733 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4734 d.setFilterBitmap(true);
4735 resizeIconDrawable(d);
4736 return d;
4737 }
4738
4739 /**
4740 * Resizes an icon drawable to the correct icon size.
4741 */
Winson5fbe0742015-09-30 15:33:00 -07004742 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004743 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004744 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004745 }
4746
4747 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004748 * Prints out out state for debugging.
4749 */
4750 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004751 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004752 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004753 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4754 Log.d(TAG, "mRestoring=" + mRestoring);
4755 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004756 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004757 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004758 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004759
Daniel Sandler325dc232013-06-05 22:57:57 -04004760 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004761 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004762
4763 @Override
4764 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4765 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004766 // Dump workspace
4767 writer.println(prefix + "Workspace Items");
4768 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4769 writer.println(prefix + " Homescreen " + i);
4770
4771 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4772 for (int j = 0; j < layout.getChildCount(); j++) {
4773 Object tag = layout.getChildAt(j).getTag();
4774 if (tag != null) {
4775 writer.println(prefix + " " + tag.toString());
4776 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004777 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004778 }
Sunny Goyala1365452015-10-01 15:46:24 -07004779
4780 writer.println(prefix + " Hotseat");
4781 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4782 for (int j = 0; j < layout.getChildCount(); j++) {
4783 Object tag = layout.getChildAt(j).getTag();
4784 if (tag != null) {
4785 writer.println(prefix + " " + tag.toString());
4786 }
4787 }
4788
4789 synchronized (sDumpLogs) {
4790 writer.println();
4791 writer.println(prefix + "Debug logs");
4792 for (String log : sDumpLogs) {
4793 writer.println(prefix + " " + log);
4794 }
4795 }
4796
Adam Cohen9211d422014-10-07 18:14:53 -07004797 if (mLauncherCallbacks != null) {
4798 mLauncherCallbacks.dump(prefix, fd, writer, args);
4799 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004800 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004801
Sunny Goyala1365452015-10-01 15:46:24 -07004802 public static void addDumpLog(String tag, String log) {
4803 Log.d(tag, log);
4804 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004805 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004806 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004807 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004808 }
4809
Adam Cohen59400422014-03-05 18:07:04 -08004810 public static CustomAppWidget getCustomAppWidget(String name) {
4811 return sCustomAppWidgets.get(name);
4812 }
4813
4814 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4815 return sCustomAppWidgets;
4816 }
4817
Sunny Goyal29538332016-02-18 09:10:19 -08004818 public static List<View> getFolderContents(View icon) {
4819 if (icon instanceof FolderIcon) {
4820 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4821 } else {
4822 return Collections.EMPTY_LIST;
4823 }
4824 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004825}
Michael Jurka2763be32011-02-24 11:19:57 -08004826
Dan Sandlerd5024042014-01-09 15:01:33 -05004827interface DebugIntents {
4828 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4829 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004830}