blob: 1af2c4fbe2df6563e4b41653e75ceb843f8b2856 [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 Goyalffe83f12014-08-14 17:39:34 -070099import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100100import com.android.launcher3.compat.LauncherActivityInfoCompat;
101import com.android.launcher3.compat.LauncherAppsCompat;
102import com.android.launcher3.compat.UserHandleCompat;
103import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700104import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700105import com.android.launcher3.dragndrop.DragController;
106import com.android.launcher3.dragndrop.DragLayer;
107import com.android.launcher3.dragndrop.DragView;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700108import com.android.launcher3.model.WidgetsModel;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700109import com.android.launcher3.util.ComponentKey;
Sunny Goyale2df0622015-04-24 11:27:00 -0700110import com.android.launcher3.util.LongArrayMap;
Sunny Goyal322d5562015-06-25 19:35:49 -0700111import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700112import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700113import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700114import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700115import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700116import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700117
Adam Cohen4caf2982013-08-20 18:54:31 -0700118import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700119import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700120import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700121import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700122import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700123import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700124import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700125import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700126import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700128import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700129import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131/**
132 * Default launcher application.
133 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100134public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700135 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chung006ee262015-08-03 14:40:11 -0700136 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700137 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700138 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Daniel Sandlerf061f822013-06-27 13:59:36 -0400140 static final boolean PROFILE_STARTUP = false;
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700141 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700142 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400143 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700144
Dan Sandlerd5024042014-01-09 15:01:33 -0500145 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700148 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700149 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700150 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Michael Jurka8b805b12012-04-18 14:23:14 -0700152 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700153 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700154
Sunny Goyal28c6b962015-10-12 11:42:05 -0700155 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
156
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700157 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
158 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
159 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
160
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700161 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
162
Mathew Inwood876a8462013-06-14 14:12:41 +0100163 /**
164 * IntentStarter uses request codes starting with this. This must be greater than all activity
165 * request codes used internally.
166 */
167 protected static final int REQUEST_LAST = 100;
168
Michael Jurka0a457bf2012-11-19 14:05:05 -0800169 // To turn on these properties, type
170 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800171 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172
Winson Chung2672ff92012-05-04 16:22:30 -0700173 // The Intent extra that defines whether to ignore the launch animation
174 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400175 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700176
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: int
178 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700179 // Type: int
180 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700181 // Type: Content Values / parcelable
182 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700183 // Type: parcelable
184 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000185 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Adam Cohen432609a2014-03-13 17:03:22 -0700188 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800189 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
190
Adam Cohen3ed316a2014-07-23 18:21:20 -0700191 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
192 static final String ACTION_FIRST_LOAD_COMPLETE =
193 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
194
Sunny Goyal594d76d2014-11-06 10:12:54 -0800195 private static final String QSB_WIDGET_ID = "qsb_widget_id";
196 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
197
Winson Chunga6945242014-01-08 14:04:34 -0800198 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
199
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700200 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700201 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
202 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700203
Adam Cohen091440a2015-03-18 14:16:05 -0700204 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700205 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700206
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700207 private boolean mIsSafeModeEnabled;
208
Adam Cohenc2d6e892014-10-16 09:49:24 -0700209 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
210 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700211 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700212
Joe Onorato9c1289c2009-08-17 11:03:03 -0400213 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700214 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
215 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700216 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217
Winson Chunga2413752012-04-03 14:22:34 -0700218 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700219 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
220 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700221 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700222
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800223 private final BroadcastReceiver mCloseSystemDialogsReceiver
224 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800225
Adam Cohen091440a2015-03-18 14:16:05 -0700226 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700227 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800228 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700229 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800230 private DragController mDragController;
Sunny Goyal322d5562015-06-25 19:35:49 -0700231
232 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700233
Sunny Goyalffe83f12014-08-14 17:39:34 -0700234 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700235 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700237 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800238 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800239 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700240
Michael Jurka0280c3b2010-09-17 15:00:07 -0700241 private int[] mTmpAddItemCellCoordinates = new int[2];
242
Sunny Goyal316490e2015-06-02 09:38:28 -0700243 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800244 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700245
Michael Jurka838a4ca2011-02-07 13:33:06 -0800246 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700247 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700248
Winson Chungc51db6a2011-10-05 11:44:49 -0700249 private SearchDropTargetBar mSearchDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -0700250 private AppInfoDropTargetBar mAppInfoDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700251
252 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700253 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700254
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700255 // Main container view and the model for the widget tray screen.
256 @Thunk WidgetsContainerView mWidgetsView;
257 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700258
Sunny Goyal594d76d2014-11-06 10:12:54 -0800259 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700262 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
263 // scroll issues (because the workspace may not have been measured yet) and extra work.
264 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
265 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266
267 private SpannableStringBuilder mDefaultKeySsb = null;
268
Adam Cohen091440a2015-03-18 14:16:05 -0700269 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400270
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800271 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 private boolean mRestoring;
273 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700274 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275
Michael Jurka1e2f4652013-07-08 18:03:46 -0700276 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700277 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700278 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700279
Joe Onorato9c1289c2009-08-17 11:03:03 -0400280 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800281 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700282 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800283 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700284 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800285 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400286
Sunny Goyal639e9062015-08-19 19:17:06 -0700287 private LauncherClings mClings;
288
Sunny Goyale2df0622015-04-24 11:27:00 -0700289 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700290
Adam Cohen61f560d2013-09-30 15:58:20 -0700291 private View.OnTouchListener mHapticFeedbackTouchListener;
292
Adam Cohended9f8d2010-11-03 13:25:16 -0700293 // Related to the auto-advancing of widgets
294 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700295 private static final int ADVANCE_INTERVAL = 20000;
296 private static final int ADVANCE_STAGGER = 250;
297
298 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700299 private long mAutoAdvanceSentTime;
300 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700301 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700302
Winson Chung400438b2011-01-16 17:53:48 -0800303 // Determines how long to wait after a rotation before restoring the screen orientation to
304 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700305 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800306
Adam Cohen091440a2015-03-18 14:16:05 -0700307 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700308
Adam Cohen1462de32012-07-24 22:34:36 -0700309 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700310 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700311
Sunny Goyala1365452015-10-01 15:46:24 -0700312 private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
313 private static final Date sDateStamp = new Date();
314 private static final DateFormat sDateFormat =
Adam Cohen4caf2982013-08-20 18:54:31 -0700315 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700316
Winson Chung46353de2012-02-16 14:05:10 -0800317 // We only want to get the SharedPreferences once since it does an FS stat each time we get
318 // it from the context.
319 private SharedPreferences mSharedPrefs;
320
Winson Chungf0c6ae02012-03-21 16:10:31 -0700321 // Holds the page that we need to animate to, and the icon views that we need to animate up
322 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700323 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700324 private Bitmap mFolderIconBitmap;
325 private Canvas mFolderIconCanvas;
326 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700327
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700328 private DeviceProfile mDeviceProfile;
329
Adam Cohen4b66bf32015-09-18 12:15:19 -0700330 private boolean mMoveToDefaultScreenFromNewIntent;
331
Winson Chung13eb5272015-05-11 16:30:13 -0700332 // This is set to the view that launched the activity that navigated the user away from
333 // launcher. Since there is no callback for when the activity has finished launching, enable
334 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800335 private BubbleTextView mWaitingForResume;
336
Adam Cohen59400422014-03-05 18:07:04 -0800337 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
338 new HashMap<String, CustomAppWidget>();
339
Adam Cohen59400422014-03-05 18:07:04 -0800340 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700341 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
342 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800343 }
344 }
345
Adam Cohen091440a2015-03-18 14:16:05 -0700346 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700347 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700348 if (mWorkspace != null) {
349 mWorkspace.buildPageHardwareLayers();
350 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700351 }
352 };
353
Adam Cohendb364c32014-05-20 14:23:40 -0700354 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800355
Adam Cohen091440a2015-03-18 14:16:05 -0700356 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800357 int requestCode;
358 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700359 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700360 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 int cellX;
362 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700363 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800364 }
365
Daniel Sandlerff02d492013-08-05 02:12:05 -0400366 private Stats mStats;
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700367 FocusIndicatorView mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700368 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400369
370 @Thunk void setOrientation() {
371 if (mRotationEnabled) {
372 unlockScreenOrientation(true);
373 } else {
374 setRequestedOrientation(
375 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700376 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400377 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700378
Sunny Goyal7779d622015-06-11 16:18:39 -0700379 private Runnable mUpdateOrientationRunnable = new Runnable() {
380 public void run() {
381 setOrientation();
382 }
383 };
384
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 @Override
386 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700387 if (DEBUG_STRICT_MODE) {
388 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
389 .detectDiskReads()
390 .detectDiskWrites()
391 .detectNetwork() // or .detectAll() for all detectable problems
392 .penaltyLog()
393 .build());
394 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
395 .detectLeakedSqlLiteObjects()
396 .detectLeakedClosableObjects()
397 .penaltyLog()
398 .penaltyDeath()
399 .build());
400 }
401
Adam Cohen9211d422014-10-07 18:14:53 -0700402 if (mLauncherCallbacks != null) {
403 mLauncherCallbacks.preOnCreate();
404 }
405
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400407
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400408 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700409
Adam Cohen2e6da152015-05-06 11:42:25 -0700410 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700411 mDeviceProfile = getResources().getConfiguration().orientation
412 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700413 app.getInvariantDeviceProfile().landscapeProfile
414 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700415
Sunny Goyalf7258242015-10-19 16:59:07 -0700416 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700417 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800418 mModel = app.setLauncher(this);
419 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700420
Joe Onorato41a12d22009-10-31 18:30:00 -0400421 mDragController = new DragController(this);
Winson Chung006ee262015-08-03 14:40:11 -0700422 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);
Romain Guycbb89e42009-06-08 15:52:54 -0700423
Daniel Sandlerff02d492013-08-05 02:12:05 -0400424 mStats = new Stats(this);
425
Sunny Goyalffe83f12014-08-14 17:39:34 -0700426 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700427
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700428 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
429 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700430
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700431 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
432 // this also ensures that any synchronous binding below doesn't re-trigger another
433 // LauncherModel load.
434 mPaused = false;
435
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200437 android.os.Debug.startMethodTracing(
438 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 }
440
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700442
Tony Wickhameef44322015-10-20 13:24:36 -0700443 app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
444 app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700446 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447
Joe Onorato7c312c12009-08-13 21:36:53 -0700448 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 mSavedState = savedInstanceState;
451 restoreState(mSavedState);
452
453 if (PROFILE_STARTUP) {
454 android.os.Debug.stopMethodTracing();
455 }
456
457 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700458 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700459 // If the user leaves launcher, then we should just load items asynchronously when
460 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700461 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700462 } else {
463 // We only load the page synchronously if the user rotates (or triggers a
464 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700465 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 }
468
469 // For handling default keys
470 mDefaultKeySsb = new SpannableStringBuilder();
471 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800472
473 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
474 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800475
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700476 mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
477 // In case we are on a device with locked rotation, we should look at preferences to check
478 // if the user has specifically allowed rotation.
479 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700480 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700481 }
482
483 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
484 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400485 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700486
Adam Cohen9211d422014-10-07 18:14:53 -0700487 if (mLauncherCallbacks != null) {
488 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700489 if (mLauncherCallbacks.hasLauncherOverlay()) {
490 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700491 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
492 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
493 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700494 mWorkspace.setLauncherOverlay(mLauncherOverlay);
495 }
Adam Cohen9211d422014-10-07 18:14:53 -0700496 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700497
498 if (shouldShowIntroScreen()) {
499 showIntroScreen();
500 } else {
501 showFirstRunActivity();
502 showFirstRunClings();
503 }
Adam Cohen9211d422014-10-07 18:14:53 -0700504 }
505
Sunny Goyal7779d622015-06-11 16:18:39 -0700506 @Override
507 public void onSettingsChanged(String settings, boolean value) {
508 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
509 mRotationEnabled = value;
510 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
511 mUpdateOrientationRunnable.run();
512 }
513 }
514 }
515
Adam Cohen9211d422014-10-07 18:14:53 -0700516 private LauncherCallbacks mLauncherCallbacks;
517
518 public void onPostCreate(Bundle savedInstanceState) {
519 super.onPostCreate(savedInstanceState);
520 if (mLauncherCallbacks != null) {
521 mLauncherCallbacks.onPostCreate(savedInstanceState);
522 }
523 }
524
525 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
526 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700527 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700528 private boolean mWorkspaceImportanceStored = false;
529 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700530 private int mWorkspaceImportanceForAccessibility =
531 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
532 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
533
534 @Override
535 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700536 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700537 return;
538 }
539 // The underlying workspace and hotseat are temporarily suppressed by the search
540 // overlay. So they sholudn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700541 if (mWorkspace != null) {
542 mWorkspaceImportanceForAccessibility =
543 mWorkspace.getImportantForAccessibility();
544 mWorkspace.setImportantForAccessibility(
545 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
546 mWorkspaceImportanceStored = true;
547 }
548 if (mHotseat != null) {
549 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
550 mHotseat.setImportantForAccessibility(
551 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
552 mHotseatImportanceStored = true;
553 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700554 }
555
556 @Override
557 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700558 if (mWorkspaceImportanceStored && mWorkspace != null) {
559 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
560 }
561 if (mHotseatImportanceStored && mHotseat != null) {
562 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
563 }
564 mWorkspaceImportanceStored = false;
565 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700566 }
567 });
Adam Cohen9211d422014-10-07 18:14:53 -0700568 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700569 }
570
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700571 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700572 public void onLauncherProviderChange() {
573 if (mLauncherCallbacks != null) {
574 mLauncherCallbacks.onLauncherProviderChange();
575 }
576 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700577
Winson Chungef7f8742015-06-04 17:18:17 -0700578 /**
579 * Updates the bounds of all the overlays to match the new fixed bounds.
580 */
581 public void updateOverlayBounds(Rect newBounds) {
582 mAppsView.setSearchBarBounds(newBounds);
583 mWidgetsView.setSearchBarBounds(newBounds);
584 }
585
Adam Cohen9211d422014-10-07 18:14:53 -0700586 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700587 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700588 if (mLauncherCallbacks != null) {
589 return mLauncherCallbacks.hasCustomContentToLeft();
590 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700591 return false;
592 }
593
Dave Hawkeya8881582013-09-17 15:55:33 -0600594 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500595 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600596 * {@link #addToCustomContentPage}. This will only be invoked if
597 * {@link #hasCustomContentToLeft()} is {@code true}.
598 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500599 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700600 if (mLauncherCallbacks != null) {
601 mLauncherCallbacks.populateCustomContentContainer();
602 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600603 }
604
605 /**
606 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
607 * ensure the custom content page is added or removed if necessary.
608 */
609 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600610 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600611 // Not bound yet, wait for bindScreens to be called.
612 return;
613 }
614
615 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
616 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500617 mWorkspace.createCustomContentContainer();
618 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600619 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
620 mWorkspace.removeCustomContentPage();
621 }
622 }
623
Anton Hanssona2f665f2013-09-26 12:18:32 +0100624 public Stats getStats() {
625 return mStats;
626 }
627
Hyunyoung Song3f471442015-04-08 19:01:34 -0700628 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700629 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
630 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700631 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700632 }
633
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000634 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700635 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
636 // This cast is safe as long as the id < 0x00FFFFFF
637 // Since we jail all the dynamically generated views, there should be no clashes
638 // with any other views.
639 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000640 }
641
642 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700643 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
644 * a configuration step, this allows the proper animations to run after other transitions.
645 */
Adam Cohendb364c32014-05-20 14:23:40 -0700646 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700647 long screenId = args.screenId;
648 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
649 // When the screen id represents an actual screen (as opposed to a rank) we make sure
650 // that the drop page actually exists.
651 screenId = ensurePendingDropLayoutExists(args.screenId);
652 }
Adam Cohendb364c32014-05-20 14:23:40 -0700653
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800654 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800655 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700656 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700657 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700658 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800659 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700660 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700661 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700662 case REQUEST_RECONFIGURE_APPWIDGET:
663 completeRestoreAppWidget(args.appWidgetId);
664 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800665 }
Michael Jurka27614d22012-04-02 06:40:22 -0700666 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
667 // if you turned the screen off and then back while in All Apps, Launcher would not
668 // return to the workspace. Clearing mAddInfo.container here fixes this issue
669 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700670 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800671 }
672
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800673 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700674 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700675 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700676 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700677 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800678 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700679
Adam Cohenad4e15c2013-10-17 16:21:35 -0700680 Runnable exitSpringLoaded = new Runnable() {
681 @Override
682 public void run() {
683 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
684 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
685 }
686 };
687
Michael Jurka8b805b12012-04-18 14:23:14 -0700688 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700689 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700690 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700691 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
692 if (resultCode == RESULT_CANCELED) {
693 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700694 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700695 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700696 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800697 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700698 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Winsona1f79d32015-08-05 14:00:45 -0700699
700 // When the user has granted permission to bind widgets, we should check to see if
701 // we can inflate the default search bar widget.
702 getOrCreateQsbBar();
Michael Jurka8b805b12012-04-18 14:23:14 -0700703 }
704 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200705 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
706 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700707 // User could have free-scrolled between pages before picking a wallpaper; make sure
708 // we move to the closest one now.
709 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700710 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200711 }
712 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700713 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200714
Adam Cohened66b2b2012-01-23 17:28:51 -0800715 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700716 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700717
Adam Cohendb364c32014-05-20 14:23:40 -0700718 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800719 // We have special handling for widgets
720 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800721 final int appWidgetId;
722 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
723 : -1;
724 if (widgetId < 0) {
725 appWidgetId = pendingAddWidgetId;
726 } else {
727 appWidgetId = widgetId;
728 }
729
Adam Cohenad4e15c2013-10-17 16:21:35 -0700730 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800731 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700732 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
733 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700734 result = RESULT_CANCELED;
735 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700736 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700737 @Override
738 public void run() {
739 exitSpringLoadedDragModeDelayed(false, 0, null);
740 }
741 };
Adam Cohendb364c32014-05-20 14:23:40 -0700742 if (workspaceLocked) {
743 // No need to remove the empty screen if we're mid-binding, as the
744 // the bind will not add the empty screen.
745 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
746 } else {
747 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
748 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
749 }
Winson Chung5aaab772012-04-27 15:24:02 -0700750 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700751 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700752 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
753 // When the screen id represents an actual screen (as opposed to a rank)
754 // we make sure that the drop page actually exists.
755 mPendingAddInfo.screenId =
756 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
757 }
Adam Cohendb364c32014-05-20 14:23:40 -0700758 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
759
760 dropLayout.setDropPending(true);
761 final Runnable onComplete = new Runnable() {
762 @Override
763 public void run() {
764 completeTwoStageWidgetDrop(resultCode, appWidgetId);
765 dropLayout.setDropPending(false);
766 }
767 };
768 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
769 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
770 } else {
771 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
772 mPendingAddInfo);
773 sPendingAddItem = args;
774 }
Winson Chung5aaab772012-04-27 15:24:02 -0700775 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 return;
777 }
778
Sunny Goyalff572272014-07-23 13:58:07 -0700779 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
780 if (resultCode == RESULT_OK) {
781 // Update the widget view.
782 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
783 pendingAddWidgetId, mPendingAddInfo);
784 if (workspaceLocked) {
785 sPendingAddItem = args;
786 } else {
787 completeAdd(args);
788 }
789 }
790 // Leave the widget in the pending state if the user canceled the configure.
791 return;
792 }
793
Sunny Goyalaad90582015-07-09 14:22:50 -0700794 if (requestCode == REQUEST_CREATE_SHORTCUT) {
795 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
796 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
797 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
798 mPendingAddInfo);
799 if (isWorkspaceLocked()) {
800 sPendingAddItem = args;
801 } else {
802 completeAdd(args);
803 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
804 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
805 }
806 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700807 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
808 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800811 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800812
813 }
814
815 @Override
816 protected void onActivityResult(
817 final int requestCode, final int resultCode, final Intent data) {
818 handleActivityResult(requestCode, resultCode, data);
819 if (mLauncherCallbacks != null) {
820 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
821 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800822 }
823
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600824 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700825 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600826 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700827 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
828 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
829 View v = null;
830 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
831 if (layout != null) {
832 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
833 }
834 Intent intent = sPendingAddItem.intent;
835 sPendingAddItem = null;
836 if (grantResults.length > 0
837 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
838 startActivity(v, intent, null);
839 } else {
840 // TODO: Show a snack bar with link to settings
841 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
842 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
843 }
844 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600845 if (mLauncherCallbacks != null) {
846 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
847 grantResults);
848 }
849 }
850
Adam Cohendb364c32014-05-20 14:23:40 -0700851 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
852 appWidgetId, ItemInfo info) {
853 PendingAddArguments args = new PendingAddArguments();
854 args.requestCode = requestCode;
855 args.intent = data;
856 args.container = info.container;
857 args.screenId = info.screenId;
858 args.cellX = info.cellX;
859 args.cellY = info.cellY;
860 args.appWidgetId = appWidgetId;
861 return args;
862 }
863
864 /**
865 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
866 *
867 * @param screenId the screen id to check
868 * @return the new screen, or screenId if it exists
869 */
870 private long ensurePendingDropLayoutExists(long screenId) {
871 CellLayout dropLayout =
872 (CellLayout) mWorkspace.getScreenWithId(screenId);
873 if (dropLayout == null) {
874 // it's possible that the add screen was removed because it was
875 // empty and a re-bind occurred
876 mWorkspace.addExtraEmptyScreen();
877 return mWorkspace.commitExtraEmptyScreen();
878 } else {
879 return screenId;
880 }
881 }
882
Adam Cohen091440a2015-03-18 14:16:05 -0700883 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800884 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800885 Runnable onCompleteRunnable = null;
886 int animationType = 0;
887
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700888 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800889 if (resultCode == RESULT_OK) {
890 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
891 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700892 mPendingAddWidgetInfo);
893 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800894 onCompleteRunnable = new Runnable() {
895 @Override
896 public void run() {
897 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700898 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700899 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
900 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800901 }
902 };
903 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800904 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800905 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800906 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700907 if (mDragLayer.getAnimatedView() != null) {
908 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
909 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
910 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700911 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700912 // The animated view may be null in the case of a rotation during widget configuration
913 onCompleteRunnable.run();
914 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 }
916
917 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700918 protected void onStop() {
919 super.onStop();
920 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700921
922 if (mLauncherCallbacks != null) {
923 mLauncherCallbacks.onStop();
924 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700925 }
926
927 @Override
928 protected void onStart() {
929 super.onStart();
930 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700931
932 if (mLauncherCallbacks != null) {
933 mLauncherCallbacks.onStart();
934 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700935 }
936
937 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800938 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200939 long startTime = 0;
940 if (DEBUG_RESUME_TIME) {
941 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400942 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200943 }
Adam Cohen9211d422014-10-07 18:14:53 -0700944
945 if (mLauncherCallbacks != null) {
946 mLauncherCallbacks.preOnResume();
947 }
948
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700950
Winson Chung4a2afa32012-07-19 14:53:05 -0700951 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -0700952 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700953 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -0800954 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -0700955 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -0700956 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -0700957 // view after launching an app, as they may be depending on the UI to be static to
958 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -0700959 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -0700960 !launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -0800961 } else if (mOnResumeState == State.WIDGETS) {
962 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700963 }
964 mOnResumeState = State.NONE;
965
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700966 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -0700967 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
968 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -0700969
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800970 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700971 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700972 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700973 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400974 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700975 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700977 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200978 // We might have postponed some bind calls until onResume (see waitUntilResume) --
979 // execute them here
980 long startTimeCallbacks = 0;
981 if (DEBUG_RESUME_TIME) {
982 startTimeCallbacks = System.currentTimeMillis();
983 }
984
Michael Jurka1e2f4652013-07-08 18:03:46 -0700985 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
986 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200987 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700988 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200989 if (DEBUG_RESUME_TIME) {
990 Log.d(TAG, "Time spent processing callbacks in onResume: " +
991 (System.currentTimeMillis() - startTimeCallbacks));
992 }
Michael Jurka447bf842013-05-15 14:52:15 +0200993 }
Michael Jurka54554252013-08-01 12:52:23 +0200994 if (mOnResumeCallbacks.size() > 0) {
995 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
996 mOnResumeCallbacks.get(i).run();
997 }
998 mOnResumeCallbacks.clear();
999 }
Winson Chunge4e50662012-01-23 14:45:13 -08001000
1001 // Reset the pressed state of icons that were locked in the press state while activities
1002 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001003 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001004 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001005 mWaitingForResume.setStayPressed(false);
1006 }
Winson Chung82963d52013-10-09 11:20:57 -07001007
Adam Cohen06dff352012-06-01 17:17:08 -07001008 // It is possible that widgets can receive updates while launcher is not in the foreground.
1009 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1010 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1011 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001012 if (!isWorkspaceLoading()) {
1013 getWorkspace().reinflateWidgetsIfNecessary();
1014 }
Sunny Goyal22235bc2015-04-03 09:23:43 -07001015 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001016
Michael Jurka447bf842013-05-15 14:52:15 +02001017 if (DEBUG_RESUME_TIME) {
1018 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1019 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001020
Adam Cohen4b66bf32015-09-18 12:15:19 -07001021 // We want to suppress callbacks about CustomContent being shown if we have just received
1022 // onNewIntent while the user was present within launcher. In that case, we post a call
1023 // to move the user to the main screen (which will occur after onResume). We don't want to
1024 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1025 // suppress here.
1026 if (mWorkspace.getCustomContentCallbacks() != null
1027 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001028 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001029 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001030 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1031 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001032 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001033 }
1034 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001035 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001036 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001037 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001038
Sunny Goyal756adbc2015-04-16 15:20:51 -07001039 if (!isWorkspaceLoading()) {
1040 // Process any items that were added while Launcher was away.
1041 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1042 }
Adam Cohen9211d422014-10-07 18:14:53 -07001043
1044 if (mLauncherCallbacks != null) {
1045 mLauncherCallbacks.onResume();
1046 }
Adam Cohen06dff352012-06-01 17:17:08 -07001047 }
1048
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001050 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001051 // Ensure that items added to Launcher are queued until Launcher returns
1052 InstallShortcutReceiver.enableInstallQueue();
1053
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001054 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001055 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001056 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001057 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001058
1059 // We call onHide() aggressively. The custom content callbacks should be able to
1060 // debounce excess onHide calls.
1061 if (mWorkspace.getCustomContentCallbacks() != null) {
1062 mWorkspace.getCustomContentCallbacks().onHide();
1063 }
Romain Guycbb89e42009-06-08 15:52:54 -07001064
Adam Cohen9211d422014-10-07 18:14:53 -07001065 if (mLauncherCallbacks != null) {
1066 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001067 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001068 }
1069
1070 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001071 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1072 // by a onResume or by scrolling otherwise.
1073 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001074
1075 // Custom content is completely hidden
1076 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001077
1078 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1079 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001080
1081 // Indicates whether the user is allowed to scroll away from the custom content.
1082 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001083 }
1084
Adam Cohenc2d6e892014-10-16 09:49:24 -07001085 public interface LauncherOverlay {
1086
1087 /**
1088 * Touch interaction leading to overscroll has begun
1089 */
1090 public void onScrollInteractionBegin();
1091
1092 /**
1093 * Touch interaction related to overscroll has ended
1094 */
1095 public void onScrollInteractionEnd();
1096
1097 /**
1098 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1099 * screen (or in the case of RTL, the rightmost screen).
1100 */
1101 public void onScrollChange(int progress, boolean rtl);
1102
1103 /**
1104 * Screen has stopped scrolling
1105 */
1106 public void onScrollSettled();
1107
1108 /**
1109 * This method can be called by the Launcher in order to force the LauncherOverlay
1110 * to exit fully immersive mode.
1111 */
1112 public void forceExitFullImmersion();
1113 }
1114
Jun Mukai8af0cd82015-05-12 12:32:12 -07001115 public interface LauncherSearchCallbacks {
1116 /**
1117 * Called when the search overlay is shown.
1118 */
1119 public void onSearchOverlayOpened();
1120
1121 /**
1122 * Called when the search overlay is dismissed.
1123 */
1124 public void onSearchOverlayClosed();
1125 }
1126
Adam Cohenc2d6e892014-10-16 09:49:24 -07001127 public interface LauncherOverlayCallbacks {
1128 /**
1129 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1130 * however it doesn't modify any state within the launcher.
1131 */
1132 public boolean canEnterFullImmersion();
1133
1134 /**
1135 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1136 * eg. by occupying the full screen and handling all touch events.
1137 *
1138 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1139 * case, Launcher will modify any necessary state and assumes the overlay is
1140 * handling all interaction. If false, the LauncherOverlay should cancel any
1141 *
1142 */
1143 public boolean enterFullImmersion();
1144
1145 /**
1146 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1147 * full control over UI and state.
1148 */
1149 public void exitFullImmersion();
1150 }
1151
1152 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1153
1154 @Override
1155 public boolean canEnterFullImmersion() {
1156 return mState == State.WORKSPACE;
1157 }
1158
1159 @Override
1160 public boolean enterFullImmersion() {
1161 if (mState == State.WORKSPACE) {
1162 // When fully immersed, disregard any touches which fall through.
1163 mDragLayer.setBlockTouch(true);
1164 return true;
1165 }
1166 return false;
1167 }
1168
1169 @Override
1170 public void exitFullImmersion() {
1171 mDragLayer.setBlockTouch(false);
1172 }
1173 }
1174
Jorim Jaggid017f882014-01-14 17:08:48 -08001175 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001176 if (mLauncherCallbacks != null) {
1177 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001178 } else {
1179 // On devices with a locked orientation, we will at least have the allow rotation
1180 // setting.
1181 return !Utilities.isRotationAllowedForDevice(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001182 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001183 }
1184
Adam Cohen9211d422014-10-07 18:14:53 -07001185 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001186 CustomContentCallbacks callbacks, String description) {
1187 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001188 }
1189
Adam Cohenedb40762013-07-18 16:45:45 -07001190 // The custom content needs to offset its content to account for the QSB
1191 public int getTopOffsetForCustomContent() {
1192 return mWorkspace.getPaddingTop();
1193 }
1194
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001195 @Override
1196 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001197 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001198 if (mModel.isCurrentCallbacks(this)) {
1199 mModel.stopLoader();
1200 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001201 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1202
Romain Guy13c2e7b2010-03-10 19:45:00 -08001203 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001204 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001205
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001206 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001207 @Override
1208 public void onWindowFocusChanged(boolean hasFocus) {
1209 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001210 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001211
1212 if (mLauncherCallbacks != null) {
1213 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1214 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001215 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001216
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 private boolean acceptFilter() {
1218 final InputMethodManager inputManager = (InputMethodManager)
1219 getSystemService(Context.INPUT_METHOD_SERVICE);
1220 return !inputManager.isFullscreenMode();
1221 }
1222
1223 @Override
1224 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001225 final int uniChar = event.getUnicodeChar();
1226 final boolean handled = super.onKeyDown(keyCode, event);
1227 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1228 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1230 keyCode, event);
1231 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001232 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001233 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001234 // showSearchDialog()
1235 // If there are multiple keystrokes before the search dialog takes focus,
1236 // onSearchRequested() will be called for every keystroke,
1237 // but it is idempotent, so it's fine.
1238 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240 }
1241
Joe Onorato8a9625e2010-01-28 15:55:35 -08001242 // Eat the long press event so the keyboard doesn't come up.
1243 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1244 return true;
1245 }
1246
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001247 return handled;
1248 }
1249
Winson46163472015-09-22 17:31:56 -07001250 @Override
1251 public boolean onKeyUp(int keyCode, KeyEvent event) {
1252 if (keyCode == KeyEvent.KEYCODE_MENU) {
1253 // Ignore the menu key if we are currently dragging or are on the custom content screen
1254 if (!isOnCustomContent() && !mDragController.isDragging()) {
1255 // Close any open folders
1256 closeFolder();
1257
1258 // Stop resizing any widgets
1259 mWorkspace.exitWidgetResizeMode();
1260
1261 // Show the overview mode if we are on the workspace
1262 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1263 !mWorkspace.isSwitchingState()) {
1264 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001265 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001266 }
1267 }
1268 return true;
1269 }
1270 return super.onKeyUp(keyCode, event);
1271 }
1272
Karl Rosaen138a0412009-04-23 19:00:21 -07001273 private String getTypedText() {
1274 return mDefaultKeySsb.toString();
1275 }
1276
1277 private void clearTypedText() {
1278 mDefaultKeySsb.clear();
1279 mDefaultKeySsb.clearSpans();
1280 Selection.setSelection(mDefaultKeySsb, 0);
1281 }
1282
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001284 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1285 * State
1286 */
1287 private static State intToState(int stateOrdinal) {
1288 State state = State.WORKSPACE;
1289 final State[] stateValues = State.values();
1290 for (int i = 0; i < stateValues.length; i++) {
1291 if (stateValues[i].ordinal() == stateOrdinal) {
1292 state = stateValues[i];
1293 break;
1294 }
1295 }
1296 return state;
1297 }
1298
1299 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 * Restores the previous state, if it exists.
1301 *
1302 * @param savedState The previous state.
1303 */
1304 private void restoreState(Bundle savedState) {
1305 if (savedState == null) {
1306 return;
1307 }
1308
Michael Jurka883f55b2010-10-21 15:47:14 -07001309 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001310 if (state == State.APPS || state == State.WIDGETS) {
1311 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001312 }
1313
Adam Cohen21cd0022013-10-09 18:57:02 -07001314 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1315 PagedView.INVALID_RESTORE_PAGE);
1316 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001317 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 }
1319
Sunny Goyal756cd262015-08-20 12:33:21 -07001320 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1321 if (itemValues != null) {
1322 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001323 AppWidgetProviderInfo info = savedState.getParcelable(
1324 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001325 mPendingAddWidgetInfo = info == null ?
1326 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1327
Adam Cohen4637b5a2013-11-04 18:21:24 -08001328 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001329 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330 mRestoring = true;
1331 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 }
1333
1334 /**
1335 * Finds all the views we need and configure them properly.
1336 */
1337 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001338 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001339
Craig Mautner360310b2012-10-26 15:13:08 -07001340 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001341 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001342 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1343 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001344 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001345 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001346
John Spurlock77e1f472013-09-11 10:09:51 -04001347 mLauncherView.setSystemUiVisibility(
1348 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001349 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350
Winson Chung4c98d922011-05-31 16:50:48 -07001351 // Setup the drag layer
1352 mDragLayer.setup(this, dragController);
1353
Winson Chung3d503fb2011-07-13 17:25:49 -07001354 // Setup the hotseat
1355 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1356 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001357 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001358 }
1359
Winsone9f27272015-10-13 10:47:51 -07001360 // Setup the overview panel
1361 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001362
Winson Chung4c98d922011-05-31 16:50:48 -07001363 // Setup the workspace
1364 mWorkspace.setHapticFeedbackEnabled(false);
1365 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001366 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001367 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001368
Tony Wickham34d2c912015-09-11 09:27:58 -07001369 // Get the search/delete/uninstall bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001370 mSearchDropTargetBar = (SearchDropTargetBar)
1371 mDragLayer.findViewById(R.id.search_drop_target_bar);
Tony Wickham34d2c912015-09-11 09:27:58 -07001372 // Get the app info bar
1373 mAppInfoDropTargetBar = (AppInfoDropTargetBar)
1374 mDragLayer.findViewById(R.id.app_info_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001375
Winson Chungef7f8742015-06-04 17:18:17 -07001376 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001377 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001378 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Winson Chungef7f8742015-06-04 17:18:17 -07001379 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1380 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1381 } else {
1382 mAppsView.setSearchBarController(mAppsView.newDefaultAppSearchController());
1383 }
Craig Mautner360310b2012-10-26 15:13:08 -07001384
Winson Chung3d503fb2011-07-13 17:25:49 -07001385 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001386 dragController.setDragScoller(mWorkspace);
Tony Wickham0f97b782015-12-02 17:55:07 -08001387 dragController.setScrollView(mDragLayer);
Winson Chung4c98d922011-05-31 16:50:48 -07001388 dragController.setMoveTarget(mWorkspace);
1389 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001390 if (mSearchDropTargetBar != null) {
1391 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001392 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001393 }
Tony Wickham34d2c912015-09-11 09:27:58 -07001394 if (mAppInfoDropTargetBar != null) {
1395 mAppInfoDropTargetBar.setup(this, dragController);
1396 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001397
Sunny Goyal322d5562015-06-25 19:35:49 -07001398 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1399 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001400 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401 }
1402
Winsone9f27272015-10-13 10:47:51 -07001403 private void setupOverviewPanel() {
1404 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1405
1406 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1407 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1408 @Override
1409 public boolean onLongClick(View v) {
1410 return v.performClick();
1411 }
1412 };
1413
1414 // Bind wallpaper button actions
1415 View wallpaperButton = findViewById(R.id.wallpaper_button);
1416 wallpaperButton.setOnClickListener(new OnClickListener() {
1417 @Override
1418 public void onClick(View view) {
1419 if (!mWorkspace.isSwitchingState()) {
1420 onClickWallpaperPicker(view);
1421 }
1422 }
1423 });
1424 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1425 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1426
1427 // Bind widget button actions
1428 mWidgetsButton = findViewById(R.id.widget_button);
1429 mWidgetsButton.setOnClickListener(new OnClickListener() {
1430 @Override
1431 public void onClick(View view) {
1432 if (!mWorkspace.isSwitchingState()) {
1433 onClickAddWidgetButton(view);
1434 }
1435 }
1436 });
1437 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1438 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1439
1440 // Bind settings actions
1441 View settingsButton = findViewById(R.id.settings_button);
1442 boolean hasSettings = hasSettings();
1443 if (hasSettings) {
1444 settingsButton.setOnClickListener(new OnClickListener() {
1445 @Override
1446 public void onClick(View view) {
1447 if (!mWorkspace.isSwitchingState()) {
1448 onClickSettingsButton(view);
1449 }
1450 }
1451 });
1452 settingsButton.setOnLongClickListener(performClickOnLongClick);
1453 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1454 } else {
1455 settingsButton.setVisibility(View.GONE);
1456 }
1457
1458 mOverviewPanel.setAlpha(0f);
1459 }
1460
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001462 * Sets the all apps button. This method is called from {@link Hotseat}.
1463 */
1464 public void setAllAppsButton(View allAppsButton) {
1465 mAllAppsButton = allAppsButton;
1466 }
1467
1468 public View getAllAppsButton() {
1469 return mAllAppsButton;
1470 }
1471
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001472 public View getWidgetsButton() {
1473 return mWidgetsButton;
1474 }
1475
Anjali Koppal5ad44842014-03-10 20:34:39 -07001476 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001477 * Creates a view representing a shortcut.
1478 *
1479 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001480 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001481 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001482 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 }
1484
1485 /**
1486 * Creates a view representing a shortcut inflated from the specified resource.
1487 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 * @param parent The group the shortcut belongs to.
1489 * @param info The data structure describing the shortcut.
1490 *
1491 * @return A View inflated from layoutResId.
1492 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001493 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001494 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001495 parent, false);
1496 favorite.applyFromShortcutInfo(info, mIconCache);
1497 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001499 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001500 return favorite;
1501 }
1502
1503 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 * Add a shortcut to the workspace.
1505 *
1506 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001508 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001509 int cellY) {
1510 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001511 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001512
Sunny Goyal5c97f512015-05-19 16:03:28 -07001513 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001514 if (info == null) {
1515 return;
1516 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001517 final View view = createShortcut(info);
1518
Sunny Goyal5c97f512015-05-19 16:03:28 -07001519 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001520 // First we check if we already know the exact location where we want to add this item.
1521 if (cellX >= 0 && cellY >= 0) {
1522 cellXY[0] = cellX;
1523 cellXY[1] = cellY;
1524 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001525
1526 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001527 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001528 true, null,null)) {
1529 return;
1530 }
1531 DragObject dragObject = new DragObject();
1532 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001533 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1534 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001535 return;
1536 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001537 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001539 }
1540
1541 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001542 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 return;
1544 }
1545
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001546 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547
1548 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001549 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001550 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 }
1552 }
1553
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001555 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001557 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 */
Adam Cohen091440a2015-03-18 14:16:05 -07001559 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001560 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1561
1562 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001563 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001564 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1565 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001566 }
Romain Guycbb89e42009-06-08 15:52:54 -07001567
Adam Cohen59400422014-03-05 18:07:04 -08001568 if (appWidgetInfo.isCustomWidget) {
1569 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001570 }
1571
Adam Cohen59400422014-03-05 18:07:04 -08001572 LauncherAppWidgetInfo launcherInfo;
1573 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1574 launcherInfo.spanX = info.spanX;
1575 launcherInfo.spanY = info.spanY;
1576 launcherInfo.minSpanX = info.minSpanX;
1577 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001578 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001579
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001581 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001582
1583 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001584 if (hostView == null) {
1585 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001586 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1587 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001588 } else {
1589 // The AppWidgetHostView has already been inflated and instantiated
1590 launcherInfo.hostView = hostView;
1591 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001592 launcherInfo.hostView.setVisibility(View.VISIBLE);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001593 addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001595 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 }
Romain Guycbb89e42009-06-08 15:52:54 -07001597
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001598 private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
1599 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
1600 item.hostView.setTag(item);
1601 item.onBindAppWidget(this);
1602
1603 item.hostView.setFocusable(true);
1604 item.hostView.setOnFocusChangeListener(mFocusHandler);
1605
1606 mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
1607 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1608
1609 if (!item.isCustomWidget()) {
1610 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
1611 }
1612 }
1613
Adam Cohended9f8d2010-11-03 13:25:16 -07001614 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1615 @Override
1616 public void onReceive(Context context, Intent intent) {
1617 final String action = intent.getAction();
1618 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1619 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001620 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001621 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001622
Winson Chungc100e8e2011-08-09 16:02:43 -07001623 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001624 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001625 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001626 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001627 if (!showWorkspace(false)) {
1628 // If we are already on the workspace, then manually reset all apps
1629 mAppsView.reset();
1630 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001631 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001632 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1633 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001634 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001635 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1636 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001637 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001638 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1639 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1640 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001641 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001642 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1643 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001644 }
1645 }
1646 };
1647
1648 @Override
1649 public void onAttachedToWindow() {
1650 super.onAttachedToWindow();
1651
1652 // Listen for broadcasts related to user-presence
1653 final IntentFilter filter = new IntentFilter();
1654 filter.addAction(Intent.ACTION_SCREEN_OFF);
1655 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001656 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001657 if (ENABLE_DEBUG_INTENTS) {
1658 filter.addAction(DebugIntents.DELETE_DATABASE);
1659 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1660 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001661 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001662 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001663 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001664 mVisible = true;
1665 }
1666
1667 @Override
1668 public void onDetachedFromWindow() {
1669 super.onDetachedFromWindow();
1670 mVisible = false;
1671
Adam Cohend113e0c2010-11-11 10:48:05 -08001672 if (mAttached) {
1673 unregisterReceiver(mReceiver);
1674 mAttached = false;
1675 }
Winson Chungb745afb2015-03-02 11:51:23 -08001676 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001677 }
1678
1679 public void onWindowVisibilityChanged(int visibility) {
1680 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001681 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001682 // The following code used to be in onResume, but it turns out onResume is called when
1683 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1684 // is a more appropriate event to handle
1685 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001686 if (!mWorkspaceLoading) {
1687 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001688 // We want to let Launcher draw itself at least once before we force it to build
1689 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001690 // apps is nice and speedy.
1691 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001692 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001693 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001694 if (mStarted) return;
1695 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001696 // We delay the layer building a bit in order to give
1697 // other message processing a time to run. In particular
1698 // this avoids a delay in hiding the IME if it was
1699 // currently shown, because doing that may involve
1700 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001701 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001702 final ViewTreeObserver.OnDrawListener listener = this;
1703 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001704 public void run() {
1705 if (mWorkspace != null &&
1706 mWorkspace.getViewTreeObserver() != null) {
1707 mWorkspace.getViewTreeObserver().
1708 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001709 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001710 }
1711 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001712 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001713 }
1714 });
1715 }
1716 clearTypedText();
1717 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001718 }
1719
Adam Cohen091440a2015-03-18 14:16:05 -07001720 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001721 mHandler.removeMessages(ADVANCE_MSG);
1722 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1723 mHandler.sendMessageDelayed(msg, delay);
1724 mAutoAdvanceSentTime = System.currentTimeMillis();
1725 }
1726
Adam Cohen091440a2015-03-18 14:16:05 -07001727 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1729 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1730 mAutoAdvanceRunning = autoAdvanceRunning;
1731 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001732 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001733 sendAdvanceMessage(delay);
1734 } else {
1735 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001736 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001737 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1738 }
1739 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001740 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001741 }
1742 }
1743 }
1744
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001745 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1746
Adam Cohended9f8d2010-11-03 13:25:16 -07001747 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001748 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001749 if (msg.what == ADVANCE_MSG) {
1750 int i = 0;
1751 for (View key: mWidgetsToAdvance.keySet()) {
1752 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001753 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001754 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001755 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001756 public void run() {
1757 ((Advanceable) v).advance();
1758 }
1759 }, delay);
1760 }
1761 i++;
1762 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001763 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001764 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001765 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001766 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001767 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001768
Winsonc0b52fe2015-09-09 16:38:15 -07001769 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001770 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001771 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1772 if (v instanceof Advanceable) {
1773 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001774 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001775 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001776 }
1777 }
1778
Winsonc0b52fe2015-09-09 16:38:15 -07001779 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001780 if (mWidgetsToAdvance.containsKey(hostView)) {
1781 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001782 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001783 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001784 }
1785
Hyunyoung Song3f471442015-04-08 19:01:34 -07001786 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001787 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1788 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001789 }
1790
Winson Chunga6945242014-01-08 14:04:34 -08001791 public DragLayer getDragLayer() {
1792 return mDragLayer;
1793 }
1794
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001795 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001796 return mAppsView;
1797 }
1798
Hyunyoung Song3f471442015-04-08 19:01:34 -07001799 public WidgetsContainerView getWidgetsView() {
1800 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001801 }
1802
Winson Chunga6945242014-01-08 14:04:34 -08001803 public Workspace getWorkspace() {
1804 return mWorkspace;
1805 }
1806
1807 public Hotseat getHotseat() {
1808 return mHotseat;
1809 }
1810
Jorim Jaggid017f882014-01-14 17:08:48 -08001811 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001812 return mOverviewPanel;
1813 }
1814
Winson Chung006ee262015-08-03 14:40:11 -07001815 public SearchDropTargetBar getSearchDropTargetBar() {
Winson Chunga6945242014-01-08 14:04:34 -08001816 return mSearchDropTargetBar;
1817 }
1818
Tony Wickham34d2c912015-09-11 09:27:58 -07001819 public AppInfoDropTargetBar getAppInfoDropTargetBar() {
1820 return mAppInfoDropTargetBar;
1821 }
1822
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001823 public LauncherAppWidgetHost getAppWidgetHost() {
1824 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 }
Romain Guycbb89e42009-06-08 15:52:54 -07001826
Winson Chunga9abd0e2010-10-27 17:18:37 -07001827 public LauncherModel getModel() {
1828 return mModel;
1829 }
1830
Winson Chunga6945242014-01-08 14:04:34 -08001831 protected SharedPreferences getSharedPrefs() {
1832 return mSharedPrefs;
1833 }
1834
Adam Cohen2e6da152015-05-06 11:42:25 -07001835 public DeviceProfile getDeviceProfile() {
1836 return mDeviceProfile;
1837 }
1838
Bjorn Bringertc459e522013-06-07 19:36:01 +01001839 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001840 getWindow().closeAllPanels();
1841
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001842 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001843 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001844 }
1845
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 @Override
1847 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001848 long startTime = 0;
1849 if (DEBUG_RESUME_TIME) {
1850 startTime = System.currentTimeMillis();
1851 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 super.onNewIntent(intent);
1853
1854 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001855 Folder openFolder = mWorkspace.getOpenFolder();
1856 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1857 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1858 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1859 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1860 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001861 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001862 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001863
Adam Cohen6fecd412013-10-02 17:41:50 -07001864 if (mWorkspace == null) {
1865 // Can be cases where mWorkspace is null, this prevents a NPE
1866 return;
1867 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001868 // In all these cases, only animate if we're already on home
1869 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001870
Sunny Goyal935fca12015-10-13 10:19:01 -07001871 closeFolder(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001872 exitSpringLoadedDragMode();
1873
1874 // If we are already on home, then just animate back to the workspace,
1875 // otherwise, just wait until onResume to set the state back to Workspace
1876 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001877 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001878 } else {
1879 mOnResumeState = State.WORKSPACE;
1880 }
1881
1882 final View v = getWindow().peekDecorView();
1883 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001884 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001885 INPUT_METHOD_SERVICE);
1886 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1887 }
1888
Winson Chungb745afb2015-03-02 11:51:23 -08001889 // Reset the apps view
1890 if (!alreadyOnHome && mAppsView != null) {
1891 mAppsView.scrollToTop();
1892 }
1893
Hyunyoung Song3f471442015-04-08 19:01:34 -07001894 // Reset the widgets view
1895 if (!alreadyOnHome && mWidgetsView != null) {
1896 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001897 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001898
Adam Cohen9211d422014-10-07 18:14:53 -07001899 if (mLauncherCallbacks != null) {
1900 mLauncherCallbacks.onHomeIntent();
1901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902 }
Adam Cohened307df2013-10-02 09:37:31 -07001903
Adam Cohen9211d422014-10-07 18:14:53 -07001904 if (mLauncherCallbacks != null) {
1905 mLauncherCallbacks.onNewIntent(intent);
1906 }
Winson15f8b172015-08-19 11:02:39 -07001907
1908 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1909 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1910 // animation.
1911 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001912 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1913 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001914 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1915 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001916
1917 // We use this flag to suppress noisy callbacks above custom content state
1918 // from onResume.
1919 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001920 mWorkspace.post(new Runnable() {
1921 @Override
1922 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001923 if (mWorkspace != null) {
1924 mWorkspace.moveToDefaultScreen(true);
1925 }
Winson15f8b172015-08-19 11:02:39 -07001926 }
1927 });
1928 }
1929 }
1930
1931 if (DEBUG_RESUME_TIME) {
1932 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1933 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001934 }
1935
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001937 public void onRestoreInstanceState(Bundle state) {
1938 super.onRestoreInstanceState(state);
1939 for (int page: mSynchronouslyBoundPages) {
1940 mWorkspace.restoreInstanceStateForChild(page);
1941 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 }
1943
1944 @Override
1945 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001946 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001947 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1948 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001949 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001950 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951
Michael Jurka883f55b2010-10-21 15:47:14 -07001952 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001953 // We close any open folder since it will not be re-opened, and we need to make sure
1954 // this state is reflected.
Sunny Goyal935fca12015-10-13 10:19:01 -07001955 closeFolder(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956
Adam Cohendcd297f2013-06-18 13:13:40 -07001957 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001958 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001959 ContentValues itemValues = new ContentValues();
1960 mPendingAddInfo.writeToValues(itemValues);
1961 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001962 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001963 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 }
1965
Hyunyoung Song3f471442015-04-08 19:01:34 -07001966 // Save the current widgets tray?
1967 // TODO(hyunyoungs)
Adam Cohen9211d422014-10-07 18:14:53 -07001968
1969 if (mLauncherCallbacks != null) {
1970 mLauncherCallbacks.onSaveInstanceState(outState);
1971 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 }
1973
1974 @Override
1975 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001977
Winson Chunge7a03942011-08-05 15:05:12 -07001978 // Remove all pending runnables
1979 mHandler.removeMessages(ADVANCE_MSG);
1980 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001981 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001982
Winson Chungcd2b0142011-06-08 16:02:26 -07001983 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001984 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07001985
1986 // It's possible to receive onDestroy after a new Launcher activity has
1987 // been created. In this case, don't interfere with the new Launcher.
1988 if (mModel.isCurrentCallbacks(this)) {
1989 mModel.stopLoader();
1990 app.setLauncher(null);
1991 }
Winson Chungcd2b0142011-06-08 16:02:26 -07001992
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001994 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001996 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001998 mAppWidgetHost = null;
1999
2000 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001
2002 TextKeyListener.getInstance().release();
2003
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002004 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002005
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002006 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002007 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002008 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002009 mWorkspace = null;
2010 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002011
Michael Jurka2ecf9952012-06-18 12:52:28 -07002012 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002013
2014 if (mLauncherCallbacks != null) {
2015 mLauncherCallbacks.onDestroy();
2016 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 }
2018
Adam Cohena9cf38f2011-05-02 15:36:58 -07002019 public DragController getDragController() {
2020 return mDragController;
2021 }
2022
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 @Override
2024 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002025 onStartForResult(requestCode);
2026 super.startActivityForResult(intent, requestCode);
2027 }
2028
2029 @Override
2030 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2031 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2032 onStartForResult(requestCode);
2033 try {
2034 super.startIntentSenderForResult(intent, requestCode,
2035 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2036 } catch (IntentSender.SendIntentException e) {
2037 throw new ActivityNotFoundException();
2038 }
2039 }
2040
2041 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002042 if (requestCode >= 0) {
2043 setWaitingForResult(true);
2044 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 }
2046
Winson Chung70d72102011-08-12 11:24:35 -07002047 /**
2048 * Indicates that we want global search for this activity by setting the globalSearch
2049 * argument for {@link #startSearch} to true.
2050 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002052 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002054
Karl Rosaen138a0412009-04-23 19:00:21 -07002055 if (initialQuery == null) {
2056 // Use any text typed in the launcher as the initial query
2057 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002058 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 if (appSearchData == null) {
2060 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002061 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 }
Winson Chungadf0c182012-08-23 14:59:07 -07002063 Rect sourceBounds = new Rect();
2064 if (mSearchDropTargetBar != null) {
2065 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2066 }
Romain Guycbb89e42009-06-08 15:52:54 -07002067
Ian Parkinson047036e2014-09-01 15:40:53 +01002068 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002069 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002070 if (clearTextImmediately) {
2071 clearTypedText();
2072 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002073
2074 // We need to show the workspace after starting the search
2075 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002076 }
2077
Ian Parkinson047036e2014-09-01 15:40:53 +01002078 /**
2079 * Start a text search.
2080 *
2081 * @return {@code true} if the search will start immediately, so any further keypresses
2082 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2083 * to buffer keypresses.
2084 */
2085 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002086 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002087 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2088 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2089 sourceBounds);
2090 }
2091
Michael Jurkaa33411c2012-06-14 16:18:21 -07002092 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002093 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002094 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002095 }
2096
2097 /**
2098 * Starts the global search activity. This code is a copied from SearchManager
2099 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002100 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002101 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002102 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002103 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2104 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2105 if (globalSearchActivity == null) {
2106 Log.w(TAG, "No global search activity found.");
2107 return;
2108 }
2109 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2110 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2111 intent.setComponent(globalSearchActivity);
2112 // Make sure that we have a Bundle to put source in
2113 if (appSearchData == null) {
2114 appSearchData = new Bundle();
2115 } else {
2116 appSearchData = new Bundle(appSearchData);
2117 }
Adam Cohen9211d422014-10-07 18:14:53 -07002118 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002119 if (!appSearchData.containsKey("source")) {
2120 appSearchData.putString("source", getPackageName());
2121 }
2122 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2123 if (!TextUtils.isEmpty(initialQuery)) {
2124 intent.putExtra(SearchManager.QUERY, initialQuery);
2125 }
2126 if (selectInitialQuery) {
2127 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2128 }
2129 intent.setSourceBounds(sourceBounds);
2130 try {
2131 startActivity(intent);
2132 } catch (ActivityNotFoundException ex) {
2133 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2134 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 }
2136
Winson Chungbedf9232015-07-10 12:38:30 -07002137 public void startSearchFromAllApps(View v, Intent searchIntent, String searchQuery) {
2138 if (mLauncherCallbacks != null && mLauncherCallbacks.startSearchFromAllApps(searchQuery)) {
2139 return;
2140 }
2141
2142 // If not handled, then just start the provided search intent
2143 startActivitySafely(v, searchIntent, null);
2144 }
2145
Yura4f93ec62014-02-04 14:15:21 +00002146 public boolean isOnCustomContent() {
2147 return mWorkspace.isOnOrMovingToCustomContent();
2148 }
2149
Winson Chung70d72102011-08-12 11:24:35 -07002150 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002151 public boolean onPrepareOptionsMenu(Menu menu) {
2152 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002153 if (mLauncherCallbacks != null) {
2154 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2155 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002156 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002159 @Override
2160 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002161 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002162 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002163 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002164 }
2165
Joe Onorato9c1289c2009-08-17 11:03:03 -04002166 public boolean isWorkspaceLocked() {
2167 return mWorkspaceLoading || mWaitingForResult;
2168 }
2169
Adam Cohen517a7f52014-03-01 12:12:59 -08002170 public boolean isWorkspaceLoading() {
2171 return mWorkspaceLoading;
2172 }
2173
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002174 private void setWorkspaceLoading(boolean value) {
2175 boolean isLocked = isWorkspaceLocked();
2176 mWorkspaceLoading = value;
2177 if (isLocked != isWorkspaceLocked()) {
2178 onWorkspaceLockedChanged();
2179 }
2180 }
2181
2182 private void setWaitingForResult(boolean value) {
2183 boolean isLocked = isWorkspaceLocked();
2184 mWaitingForResult = value;
2185 if (isLocked != isWorkspaceLocked()) {
2186 onWorkspaceLockedChanged();
2187 }
2188 }
2189
Adam Cohen9211d422014-10-07 18:14:53 -07002190 protected void onWorkspaceLockedChanged() {
2191 if (mLauncherCallbacks != null) {
2192 mLauncherCallbacks.onWorkspaceLockedChanged();
2193 }
2194 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002195
Michael Jurka0280c3b2010-09-17 15:00:07 -07002196 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002197 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002198 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002199 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2200 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002201 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002202 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002203
Tony Wickhama0628cc2015-10-14 15:23:04 -07002204 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002205 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002206 if (LOGD) {
2207 Log.d(TAG, "Adding widget from drop");
2208 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002209 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2210 }
2211
Sunny Goyale6b63a32015-01-16 16:14:29 -08002212 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002213 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2214 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002215 if (appWidgetInfo.configure != null) {
2216 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002217 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002218
Bjorn Bringert7984c942009-12-09 15:38:25 +00002219 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002220 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2221 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2222
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002223 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002224 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002225 Runnable onComplete = new Runnable() {
2226 @Override
2227 public void run() {
2228 // Exit spring loaded mode if necessary after adding the widget
2229 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2230 null);
2231 }
2232 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002233 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002234 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002235 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002236 }
2237 }
Romain Guycbb89e42009-06-08 15:52:54 -07002238
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002239 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002240 // Close any folders that may be open.
2241 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002242 mWorkspace.moveToCustomContentScreen(animate);
2243 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002244
2245 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2246 int[] cell, int spanX, int spanY) {
2247 switch (info.itemType) {
2248 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2249 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2250 int span[] = new int[2];
2251 span[0] = spanX;
2252 span[1] = spanY;
2253 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2254 container, screenId, cell, span);
2255 break;
2256 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2257 processShortcutFromDrop(info.componentName, container, screenId, cell);
2258 break;
2259 default:
2260 throw new IllegalStateException("Unknown item type: " + info.itemType);
2261 }
2262 }
2263
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 /**
2265 * Process a shortcut drop.
2266 *
2267 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002268 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002270 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002271 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2272 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002273 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002274 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002275 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002276
2277 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002278 mPendingAddInfo.cellX = cell[0];
2279 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002280 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002281
2282 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2283 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002284 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002285 }
2286
Adam Cohenfbba09b2011-07-18 21:43:05 -07002287 /**
2288 * Process a widget drop.
2289 *
2290 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002291 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002292 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002293 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002294 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2295 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002296 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002297 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002298 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002299 mPendingAddInfo.minSpanX = info.minSpanX;
2300 mPendingAddInfo.minSpanY = info.minSpanY;
2301
Adam Cohenfbba09b2011-07-18 21:43:05 -07002302 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002303 mPendingAddInfo.cellX = cell[0];
2304 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002305 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002306 if (span != null) {
2307 mPendingAddInfo.spanX = span[0];
2308 mPendingAddInfo.spanY = span[1];
2309 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002310
Adam Cohened66b2b2012-01-23 17:28:51 -08002311 AppWidgetHostView hostView = info.boundWidget;
2312 int appWidgetId;
2313 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002314 // In the case where we've prebound the widget, we remove it from the DragLayer
2315 if (LOGD) {
2316 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2317 }
2318 getDragLayer().removeView(hostView);
2319
Adam Cohened66b2b2012-01-23 17:28:51 -08002320 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002321 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002322
2323 // Clear the boundWidget so that it doesn't get destroyed.
2324 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002325 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002326 // In this case, we either need to start an activity to get permission to bind
2327 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002328 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002329 Bundle options = info.bindOptions;
2330
Sunny Goyalffe83f12014-08-14 17:39:34 -07002331 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2332 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002333 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002334 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002335 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002336 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002337 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2338 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2339 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002340 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2341 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002342 // TODO: we need to make sure that this accounts for the options bundle.
2343 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002344 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2345 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002346 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002347 }
2348
Adam Cohendcd297f2013-06-18 13:13:40 -07002349 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002350 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002351 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002352 folderInfo.title = getText(R.string.folder_name);
2353
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002355 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2356 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002357 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358
2359 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002360 FolderIcon newFolder =
2361 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002362 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002363 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002364 // Force measure the new folder icon
2365 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2366 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002367 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002368 }
Romain Guycbb89e42009-06-08 15:52:54 -07002369
Winsonc0b52fe2015-09-09 16:38:15 -07002370 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002371 * Unbinds the view for the specified item, and removes the item and all its children.
2372 *
2373 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002374 * @param itemInfo the {@link ItemInfo} for this view.
2375 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002376 */
Winson2949fb52015-09-24 09:56:11 -07002377 public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002378 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002379 // Remove the shortcut from the folder before removing it from launcher
Winson2949fb52015-09-24 09:56:11 -07002380 FolderInfo folderInfo = sFolders.get(itemInfo.container);
2381 if (folderInfo != null) {
2382 folderInfo.remove((ShortcutInfo) itemInfo);
Winsonfa56b3f2015-09-14 12:01:13 -07002383 } else {
2384 mWorkspace.removeWorkspaceItem(v);
2385 }
Winsonc0b52fe2015-09-09 16:38:15 -07002386 if (deleteFromDb) {
2387 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2388 }
2389 } else if (itemInfo instanceof FolderInfo) {
2390 final FolderInfo folderInfo = (FolderInfo) itemInfo;
2391 unbindFolder(folderInfo);
2392 mWorkspace.removeWorkspaceItem(v);
2393 if (deleteFromDb) {
2394 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2395 }
2396 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2397 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002398 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal56c73602015-09-25 12:55:01 -07002399 removeWidgetToAutoAdvance(widgetInfo.hostView);
2400 widgetInfo.hostView = null;
Winsonc0b52fe2015-09-09 16:38:15 -07002401 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002402 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002403 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002404
Winsonc0b52fe2015-09-09 16:38:15 -07002405 } else {
2406 return false;
2407 }
2408 return true;
2409 }
2410
2411 /**
2412 * Unbinds any launcher references to the folder.
2413 */
2414 private void unbindFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002415 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002416 }
2417
Winsonc0b52fe2015-09-09 16:38:15 -07002418 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002419 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002420 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002421 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002422 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyal56c73602015-09-25 12:55:01 -07002423 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002424 // Deleting an app widget ID is a void call but writes to disk before returning
2425 // to the caller...
2426 new AsyncTask<Void, Void, Void>() {
2427 public Void doInBackground(Void ... args) {
2428 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2429 return null;
2430 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002431 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002432 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002433 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002434 }
2435
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436 @Override
2437 public boolean dispatchKeyEvent(KeyEvent event) {
2438 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2439 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002440 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002441 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002442 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002443 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002444 dumpState();
2445 return true;
2446 }
2447 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002448 }
2449 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2450 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002451 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002452 return true;
2453 }
2454 }
2455
2456 return super.dispatchKeyEvent(event);
2457 }
2458
Joe Onorato88ec0992009-11-19 13:16:06 -08002459 @Override
2460 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002461 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2462 return;
2463 }
2464
Sunny Goyal45478022015-06-08 16:52:41 -07002465 if (mDragController.isDragging()) {
2466 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002467 return;
2468 }
2469
Winson Chungb745afb2015-03-02 11:51:23 -08002470 if (isAppsViewVisible()) {
2471 showWorkspace(true);
2472 } else if (isWidgetsViewVisible()) {
2473 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002474 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002475 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002476 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002477 Folder openFolder = mWorkspace.getOpenFolder();
2478 if (openFolder.isEditingName()) {
2479 openFolder.dismissEditingName();
2480 } else {
2481 closeFolder();
2482 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002483 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002484 mWorkspace.exitWidgetResizeMode();
2485
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002486 // Back button is a no-op here, but give at least some feedback for the button press
2487 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002488 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002489 }
2490
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002491 /**
Sunny Goyal383c5072015-06-12 21:18:53 -07002492 * Re-listen when widget host is reset.
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002493 */
Sunny Goyal383c5072015-06-12 21:18:53 -07002494 @Override
2495 public void onAppWidgetHostReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002496 if (mAppWidgetHost != null) {
2497 mAppWidgetHost.startListening();
2498 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002499 }
2500
2501 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502 * Launches the intent referred by the clicked shortcut.
2503 *
2504 * @param v The view representing the clicked shortcut.
2505 */
2506 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002507 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2508 // view has detached (it's possible for this to happen if the view is removed mid touch).
2509 if (v.getWindowToken() == null) {
2510 return;
2511 }
2512
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002513 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002514 return;
2515 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002516
Adam Cohen1697b792013-09-17 19:08:21 -07002517 if (v instanceof Workspace) {
2518 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002519 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002520 }
2521 return;
2522 }
2523
2524 if (v instanceof CellLayout) {
2525 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002526 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2527 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002528 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002529 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002530 }
2531
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002532 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002533 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002534 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002535 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002536 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002537 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002538 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002539 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002540 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002541 } else if (tag instanceof AppInfo) {
2542 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002543 } else if (tag instanceof LauncherAppWidgetInfo) {
2544 if (v instanceof PendingAppWidgetHostView) {
2545 onClickPendingWidget((PendingAppWidgetHostView) v);
2546 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002547 }
2548 }
2549
Sunny Goyal70660032015-05-14 00:07:08 -07002550 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002551 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002552 return false;
2553 }
2554
Michael Jurkaaf442092010-06-10 17:01:57 -07002555 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002556 * Event handler for the app widget view which has not fully restored.
2557 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002558 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002559 if (mIsSafeModeEnabled) {
2560 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2561 return;
2562 }
2563
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002564 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002565 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002566 int widgetId = info.appWidgetId;
2567 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2568 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002569 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2570 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002571 mPendingAddInfo.copyFrom(info);
2572 mPendingAddWidgetId = widgetId;
2573
Sunny Goyalffe83f12014-08-14 17:39:34 -07002574 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2575 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002576 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002577 } else if (info.installProgress < 0) {
2578 // The install has not been queued
2579 final String packageName = info.providerName.getPackageName();
2580 showBrokenAppInstallDialog(packageName,
2581 new DialogInterface.OnClickListener() {
2582 public void onClick(DialogInterface dialog, int id) {
2583 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2584 }
2585 });
2586 } else {
2587 // Download has started.
2588 final String packageName = info.providerName.getPackageName();
2589 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002590 }
2591 }
2592
2593 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002594 * Event handler for the "grid" button that appears on the home screen, which
2595 * enters all apps mode.
2596 *
2597 * @param v The view that was clicked.
2598 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002599 protected void onClickAllAppsButton(View v) {
2600 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002601 if (!isAppsViewVisible()) {
Winson Chung4ac30062015-05-08 17:34:17 -07002602 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07002603 true /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungbedf9232015-07-10 12:38:30 -07002604
2605 if (mLauncherCallbacks != null) {
2606 mLauncherCallbacks.onClickAllAppsButton(v);
2607 }
Winson Chung76648c52015-07-10 14:33:23 -07002608 }
2609 }
2610
2611 protected void onLongClickAllAppsButton(View v) {
2612 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2613 if (!isAppsViewVisible()) {
2614 showAppsView(true /* animated */, false /* resetListToTop */,
2615 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002616 }
2617 }
2618
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002619 private void showBrokenAppInstallDialog(final String packageName,
2620 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002621 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002622 .setTitle(R.string.abandoned_promises_title)
2623 .setMessage(R.string.abandoned_promise_explanation)
2624 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2625 .setNeutralButton(R.string.abandoned_clean_this,
2626 new DialogInterface.OnClickListener() {
2627 public void onClick(DialogInterface dialog, int id) {
2628 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2629 mWorkspace.removeAbandonedPromise(packageName, user);
2630 }
2631 })
2632 .create().show();
2633 return;
2634 }
2635
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002636 /**
2637 * Event handler for an app shortcut click.
2638 *
2639 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2640 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002641 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002642 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2643 Object tag = v.getTag();
2644 if (!(tag instanceof ShortcutInfo)) {
2645 throw new IllegalArgumentException("Input must be a Shortcut");
2646 }
2647
2648 // Open shortcut
2649 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002650
2651 if (shortcut.isDisabled != 0) {
2652 int error = R.string.activity_not_available;
2653 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2654 error = R.string.safemode_shortcut_error;
2655 }
2656 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2657 return;
2658 }
2659
Chris Wren40c5ed32014-06-24 18:24:23 -04002660 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002661 if ((v instanceof BubbleTextView)
2662 && shortcut.isPromise()
2663 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002664 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002665 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002666 new DialogInterface.OnClickListener() {
2667 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002668 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002669 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002670 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002671 return;
2672 }
2673
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002674 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002675 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002676
2677 if (mLauncherCallbacks != null) {
2678 mLauncherCallbacks.onClickAppShortcut(v);
2679 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002680 }
2681
Adam Cohen091440a2015-03-18 14:16:05 -07002682 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002683 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002684 final ShortcutInfo shortcut;
2685 final Intent intent;
2686 if (tag instanceof ShortcutInfo) {
2687 shortcut = (ShortcutInfo) tag;
2688 intent = shortcut.intent;
2689 int[] pos = new int[2];
2690 v.getLocationOnScreen(pos);
2691 intent.setSourceBounds(new Rect(pos[0], pos[1],
2692 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002693
Sunny Goyal508da152014-08-14 10:53:27 -07002694 } else if (tag instanceof AppInfo) {
2695 shortcut = null;
2696 intent = ((AppInfo) tag).intent;
2697 } else {
2698 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2699 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002700
2701 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002702 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002703
2704 if (success && v instanceof BubbleTextView) {
2705 mWaitingForResume = (BubbleTextView) v;
2706 mWaitingForResume.setStayPressed(true);
2707 }
2708 }
2709
2710 /**
2711 * Event handler for a folder icon click.
2712 *
2713 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2714 */
2715 protected void onClickFolderIcon(View v) {
2716 if (LOGD) Log.d(TAG, "onClickFolder");
2717 if (!(v instanceof FolderIcon)){
2718 throw new IllegalArgumentException("Input must be a FolderIcon");
2719 }
2720
Sunny Goyal317698b2015-07-29 11:45:41 -07002721 // TODO(sunnygoyal): Re-evaluate this code.
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002722 FolderIcon folderIcon = (FolderIcon) v;
2723 final FolderInfo info = folderIcon.getFolderInfo();
2724 Folder openFolder = mWorkspace.getFolderForTag(info);
2725
2726 // If the folder info reports that the associated folder is open, then verify that
2727 // it is actually opened. There have been a few instances where this gets out of sync.
2728 if (info.opened && openFolder == null) {
2729 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2730 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2731 info.opened = false;
2732 }
2733
2734 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2735 // Close any open folder
2736 closeFolder();
2737 // Open the requested folder
2738 openFolder(folderIcon);
2739 } else {
2740 // Find the open folder...
2741 int folderScreen;
2742 if (openFolder != null) {
2743 folderScreen = mWorkspace.getPageForView(openFolder);
2744 // .. and close it
Sunny Goyal935fca12015-10-13 10:19:01 -07002745 closeFolder(openFolder, true);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002746 if (folderScreen != mWorkspace.getCurrentPage()) {
2747 // Close any folder open on the current screen
2748 closeFolder();
2749 // Pull the folder onto this screen
2750 openFolder(folderIcon);
2751 }
2752 }
2753 }
Adam Cohen9211d422014-10-07 18:14:53 -07002754
2755 if (mLauncherCallbacks != null) {
2756 mLauncherCallbacks.onClickFolderIcon(v);
2757 }
Michael Jurka5130e402011-10-13 04:55:35 -07002758 }
2759
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002760 /**
2761 * Event handler for the (Add) Widgets button that appears after a long press
2762 * on the home screen.
2763 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002764 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002765 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002766 if (mIsSafeModeEnabled) {
2767 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2768 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002769 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002770 if (mLauncherCallbacks != null) {
2771 mLauncherCallbacks.onClickAddWidgetButton(view);
2772 }
Adam Cohen9211d422014-10-07 18:14:53 -07002773 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002774 }
2775
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002776 /**
2777 * Event handler for the wallpaper picker button that appears after a long press
2778 * on the home screen.
2779 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002780 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002781 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Tony Wickham785f7a52015-08-31 17:28:32 -07002782 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2783 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
2784 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
2785 .putExtra(WallpaperPickerActivity.EXTRA_WALLPAPER_OFFSET, offset),
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002786 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002787
2788 if (mLauncherCallbacks != null) {
2789 mLauncherCallbacks.onClickWallpaperPicker(v);
2790 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002791 }
2792
2793 /**
2794 * Event handler for a click on the settings button that appears after a long press
2795 * on the home screen.
2796 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002797 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002798 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002799 if (mLauncherCallbacks != null) {
2800 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002801 } else {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002802 startActivity(new Intent(this, SettingsActivity.class));
Adam Cohen9211d422014-10-07 18:14:53 -07002803 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002804 }
2805
Adam Cohen61f560d2013-09-30 15:58:20 -07002806 public View.OnTouchListener getHapticFeedbackTouchListener() {
2807 if (mHapticFeedbackTouchListener == null) {
2808 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002809 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002810 @Override
2811 public boolean onTouch(View v, MotionEvent event) {
2812 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2813 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2814 }
2815 return false;
2816 }
2817 };
2818 }
2819 return mHapticFeedbackTouchListener;
2820 }
2821
Adam Cohen9211d422014-10-07 18:14:53 -07002822 public void onDragStarted(View view) {
2823 if (isOnCustomContent()) {
2824 // Custom content screen doesn't participate in drag and drop. If on custom
2825 // content screen, move to default.
2826 moveWorkspaceToDefaultScreen();
2827 }
2828
2829 if (mLauncherCallbacks != null) {
2830 mLauncherCallbacks.onDragStarted(view);
2831 }
2832 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002833
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002834 /**
2835 * Called when the user stops interacting with the launcher.
2836 * This implies that the user is now on the homescreen and is not doing housekeeping.
2837 */
Adam Cohen9211d422014-10-07 18:14:53 -07002838 protected void onInteractionEnd() {
2839 if (mLauncherCallbacks != null) {
2840 mLauncherCallbacks.onInteractionEnd();
2841 }
2842 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002843
2844 /**
2845 * Called when the user starts interacting with the launcher.
2846 * The possible interactions are:
2847 * - open all apps
2848 * - reorder an app shortcut, or a widget
2849 * - open the overview mode.
2850 * This is a good time to stop doing things that only make sense
2851 * when the user is on the homescreen and not doing housekeeping.
2852 */
Adam Cohen9211d422014-10-07 18:14:53 -07002853 protected void onInteractionBegin() {
2854 if (mLauncherCallbacks != null) {
2855 mLauncherCallbacks.onInteractionBegin();
2856 }
2857 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002858
Winson Chungcd99cd32015-04-29 11:03:24 -07002859 /** Updates the interaction state. */
2860 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002861 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002862 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002863 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2864 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002865 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002866 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002867 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002868 onInteractionEnd();
2869 }
2870 }
2871
Kenny Guyf07af7b2014-07-31 11:39:16 +01002872 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002873 try {
2874 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002875 launcherApps.showAppDetailsForProfile(componentName, user);
2876 } catch (SecurityException e) {
2877 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2878 Log.e(TAG, "Launcher does not have permission to launch settings");
2879 } catch (ActivityNotFoundException e) {
2880 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2881 Log.e(TAG, "Unable to launch settings");
2882 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002883 }
2884
Michael Jurka1e2f4652013-07-08 18:03:46 -07002885 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002886 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2887 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002888 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002889 // System applications cannot be installed. For now, show a toast explaining that.
2890 // We may give them the option of disabling apps this way.
2891 int messageId = R.string.uninstall_system_app_text;
2892 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002893 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002894 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002895 String packageName = componentName.getPackageName();
2896 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002897 Intent intent = new Intent(
2898 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002899 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2900 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002901 if (user != null) {
2902 user.addToIntent(intent, Intent.EXTRA_USER);
2903 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002904 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002905 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002906 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002907 }
2908
Winson Chung8f1eff72015-05-28 17:33:40 -07002909 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002910 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002911 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002912 // Only launch using the new animation if the shortcut has not opted out (this is a
2913 // private contract between launcher and may be ignored in the future).
2914 boolean useLaunchAnimation = (v != null) &&
2915 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002916 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2917 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002918
Kenny Guy1317e2d2014-05-08 18:52:50 +01002919 UserHandleCompat user = null;
2920 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2921 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2922 user = userManager.getUserForSerialNumber(serialNumber);
2923 }
2924
2925 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002926 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002927 ActivityOptions opts = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002928 if (Utilities.ATLEAST_MARSHMALLOW) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002929 int left = 0, top = 0;
2930 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2931 if (v instanceof TextView) {
2932 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002933 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2934 if (icon != null) {
2935 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002936 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002937 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002938 width = bounds.width();
2939 height = bounds.height();
2940 }
2941 }
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002942 opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
2943 } else if (!Utilities.ATLEAST_LOLLIPOP) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002944 // Below L, we use a scale up animation
Adam Cohen2e52c902015-04-06 13:11:28 -07002945 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002946 v.getMeasuredWidth(), v.getMeasuredHeight());
Sunny Goyal9fc953b2015-08-17 12:24:25 -07002947 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
Adam Cohen947e02b2015-05-22 19:23:34 -07002948 // On L devices, we use the device default slide-up transition.
2949 // On L MR1 devices, we a custom version of the slide-up transition which
2950 // doesn't have the delay present in the device default.
2951 opts = ActivityOptions.makeCustomAnimation(this,
2952 R.anim.task_open_enter, R.anim.no_anim);
Chet Haasea8f996d2015-02-17 12:56:04 -08002953 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002954 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002955 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002956
2957 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2958 // Could be launching some bookkeeping activity
2959 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002960 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002961 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002962 launcherApps.startActivityForProfile(intent.getComponent(), user,
2963 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002964 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002965 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002966 } catch (SecurityException e) {
Sunny Goyal28c6b962015-10-12 11:42:05 -07002967 if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
2968 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2969 // corresponding permission. Show the appropriate permission prompt if that
2970 // is the case.
2971 if (intent.getComponent() == null
2972 && Intent.ACTION_CALL.equals(intent.getAction())
2973 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2974 PackageManager.PERMISSION_GRANTED) {
2975 // TODO: Rename sPendingAddItem to a generic name.
2976 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2977 0, (ItemInfo) tag);
2978 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2979 REQUEST_PERMISSION_CALL_PHONE);
2980 return false;
2981 }
2982 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002983 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002984 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002985 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002986 "or use the exported attribute for this activity. "
2987 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002988 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002989 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002990 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002991
Winson Chungbedf9232015-07-10 12:38:30 -07002992 public boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07002993 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002994 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2995 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2996 return false;
2997 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002998 try {
2999 success = startActivity(v, intent, tag);
3000 } catch (ActivityNotFoundException e) {
3001 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
3002 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
3003 }
3004 return success;
3005 }
3006
Adam Cohen268c4752012-06-06 17:47:33 -07003007 /**
3008 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
3009 * in the DragLayer in the exact absolute location of the original FolderIcon.
3010 */
3011 private void copyFolderIconToImage(FolderIcon fi) {
3012 final int width = fi.getMeasuredWidth();
3013 final int height = fi.getMeasuredHeight();
3014
3015 // Lazy load ImageView, Bitmap and Canvas
3016 if (mFolderIconImageView == null) {
3017 mFolderIconImageView = new ImageView(this);
3018 }
3019 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3020 mFolderIconBitmap.getHeight() != height) {
3021 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3022 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3023 }
3024
3025 DragLayer.LayoutParams lp;
3026 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3027 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3028 } else {
3029 lp = new DragLayer.LayoutParams(width, height);
3030 }
3031
Adam Cohen307fe232012-08-16 17:55:58 -07003032 // The layout from which the folder is being opened may be scaled, adjust the starting
3033 // view size by this scale factor.
3034 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003035 lp.customPosition = true;
3036 lp.x = mRectForFolderAnimation.left;
3037 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003038 lp.width = (int) (scale * width);
3039 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003040
3041 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3042 fi.draw(mFolderIconCanvas);
3043 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003044 if (fi.getFolder() != null) {
3045 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3046 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003047 }
Adam Cohen268c4752012-06-06 17:47:33 -07003048 // Just in case this image view is still in the drag layer from a previous animation,
3049 // we remove it and re-add it.
3050 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3051 mDragLayer.removeView(mFolderIconImageView);
3052 }
3053 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003054 if (fi.getFolder() != null) {
3055 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003056 }
Adam Cohen268c4752012-06-06 17:47:33 -07003057 }
3058
Adam Cohen2801caf2011-05-13 20:57:39 -07003059 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003060 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003061 FolderInfo info = (FolderInfo) fi.getTag();
3062 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3063 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003064 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3065 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003066 }
3067
Adam Cohen268c4752012-06-06 17:47:33 -07003068 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3069 copyFolderIconToImage(fi);
3070 fi.setVisibility(View.INVISIBLE);
3071
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003072 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3073 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003074 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003075 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3076 }
3077 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003078 oa.start();
Tony Wickham112ac952015-11-12 12:31:50 -08003079 if (Utilities.isPowerSaverOn(this)) {
3080 // Animations are disabled in battery saver mode, so just skip to the end state.
3081 oa.end();
3082 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003083 }
3084
Sunny Goyal935fca12015-10-13 10:19:01 -07003085 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003086 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003087 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003088
Adam Cohen268c4752012-06-06 17:47:33 -07003089 // We remove and re-draw the FolderIcon in-case it has changed
3090 mDragLayer.removeView(mFolderIconImageView);
3091 copyFolderIconToImage(fi);
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003092 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003093 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003094 oa.addListener(new AnimatorListenerAdapter() {
3095 @Override
3096 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003097 if (cl != null) {
3098 cl.clearFolderLeaveBehind();
3099 // Remove the ImageView copy of the FolderIcon and make the original visible.
3100 mDragLayer.removeView(mFolderIconImageView);
3101 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003102 }
3103 }
3104 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003105 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003106 if (!animate) {
3107 oa.end();
3108 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003109 }
3110
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003111 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003112 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003113 * is animated relative to the specified View. If the View is null, no animation
3114 * is played.
3115 *
3116 * @param folderInfo The FolderInfo describing the folder to open.
3117 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003118 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003119 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003120 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3121 if (openFolder != null && openFolder != folder) {
3122 // Close any open folder before opening a folder.
3123 closeFolder();
3124 }
3125
Adam Cohena9cf38f2011-05-02 15:36:58 -07003126 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003127
Adam Cohena9cf38f2011-05-02 15:36:58 -07003128 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003129
Sunny Goyalf4066152015-04-15 09:42:19 -07003130 // While the folder is open, the position of the icon cannot change.
3131 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3132
Adam Cohen4554ee12011-08-03 16:13:21 -07003133 // Just verify that the folder hasn't already been added to the DragLayer.
3134 // There was a one-off crash where the folder had a parent already.
3135 if (folder.getParent() == null) {
3136 mDragLayer.addView(folder);
3137 mDragController.addDropTarget((DropTarget) folder);
3138 } else {
3139 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3140 folder.getParent() + ").");
3141 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003142 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003143 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003144
3145 // Notify the accessibility manager that this folder "window" has appeared and occluded
3146 // the workspace items
3147 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3148 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003149 }
3150
3151 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003152 closeFolder(true);
3153 }
3154
3155 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003156 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003157 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003158 if (folder.isEditingName()) {
3159 folder.dismissEditingName();
3160 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003161 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003162 }
3163 }
3164
Sunny Goyal935fca12015-10-13 10:19:01 -07003165 public void closeFolder(Folder folder, boolean animate) {
Adam Cohen4554ee12011-08-03 16:13:21 -07003166 folder.getInfo().opened = false;
3167
3168 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3169 if (parent != null) {
3170 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003171 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003172 if (fi != null) {
3173 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3174 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003175 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003176 if (animate) {
3177 folder.animateClosed();
3178 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003179 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003180 }
Winson Chung83ca4802013-04-12 15:10:52 -07003181
Sunny Goyal935fca12015-10-13 10:19:01 -07003182 // Notify the accessibility manager that this folder "window" has disappeared and no
3183 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003184 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003185 }
3186
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003187 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003188 if (!isDraggingEnabled()) return false;
3189 if (isWorkspaceLocked()) return false;
3190 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003191
Winson Chung76648c52015-07-10 14:33:23 -07003192 if (v == mAllAppsButton) {
3193 onLongClickAllAppsButton(v);
3194 return true;
3195 }
3196
Adam Cohen1697b792013-09-17 19:08:21 -07003197 if (v instanceof Workspace) {
3198 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003199 if (!mWorkspace.isTouchActive()) {
3200 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003201 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3202 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3203 return true;
3204 } else {
3205 return false;
3206 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003207 } else {
3208 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003209 }
Adam Cohen1697b792013-09-17 19:08:21 -07003210 }
3211
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003212 CellLayout.CellInfo longClickCellInfo = null;
3213 View itemUnderLongClick = null;
3214 if (v.getTag() instanceof ItemInfo) {
3215 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003216 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003217 itemUnderLongClick = longClickCellInfo.cell;
3218 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003219 }
3220
Winson Chung3d503fb2011-07-13 17:25:49 -07003221 // The hotseat touch handling does not go through Workspace, and we always allow long press
3222 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003223 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003224 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003225 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003226 // User long pressed on empty space
3227 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3228 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003229 if (mWorkspace.isInOverviewMode()) {
3230 mWorkspace.startReordering(v);
3231 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003232 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003233 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003234 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003235 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3236 mHotseat.getOrderInHotseat(
3237 longClickCellInfo.cellX,
3238 longClickCellInfo.cellY));
3239 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003240 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003241 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003242 }
3243 }
3244 }
3245 return true;
3246 }
3247
Winson Chung3d503fb2011-07-13 17:25:49 -07003248 boolean isHotseatLayout(View layout) {
3249 return mHotseat != null && layout != null &&
3250 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3251 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003252
Winson Chung3d503fb2011-07-13 17:25:49 -07003253 /**
3254 * Returns the CellLayout of the specified container at the specified screen.
3255 */
Sunny Goyal92820592015-03-02 11:31:35 -08003256 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003257 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3258 if (mHotseat != null) {
3259 return mHotseat.getLayout();
3260 } else {
3261 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003262 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003263 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003264 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003265 }
3266 }
3267
Winson Chungb745afb2015-03-02 11:51:23 -08003268 /**
3269 * For overridden classes.
3270 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003271 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003272 return isAppsViewVisible();
3273 }
3274
3275 public boolean isAppsViewVisible() {
3276 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3277 }
3278
3279 public boolean isWidgetsViewVisible() {
3280 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003281 }
3282
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003283 private void setWorkspaceBackground(int background) {
3284 switch (background) {
3285 case WORKSPACE_BACKGROUND_TRANSPARENT:
3286 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3287 break;
3288 case WORKSPACE_BACKGROUND_BLACK:
3289 getWindow().setBackgroundDrawable(null);
3290 break;
3291 default:
3292 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3293 }
Craig Mautner360310b2012-10-26 15:13:08 -07003294 }
3295
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003296 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003297 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3298 int curflags = getWindow().getAttributes().flags
3299 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3300 if (wpflags != curflags) {
3301 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3302 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003303 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003304 }
3305
Michael Jurkae326f182011-11-21 14:05:46 -08003306 @Override
3307 public void onTrimMemory(int level) {
3308 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003309 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3310 // The widget preview db can result in holding onto over
3311 // 3MB of memory for caching which isn't necessary.
3312 SQLiteDatabase.releaseMemory();
3313
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003314 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003315 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003316 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003317 if (mLauncherCallbacks != null) {
3318 mLauncherCallbacks.onTrimMemory(level);
3319 }
Michael Jurkae326f182011-11-21 14:05:46 -08003320 }
3321
Winson5c6bdbb2015-09-03 11:36:19 -07003322 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003323 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003324 }
3325
Winson5c6bdbb2015-09-03 11:36:19 -07003326 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003327 boolean changed = mState != State.WORKSPACE ||
3328 mWorkspace.getState() != Workspace.State.NORMAL;
3329 if (changed) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003330 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003331 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003332 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003333
Michael Jurkab3e22d92011-10-31 15:58:33 -07003334 // Set focus to the AppsCustomize button
3335 if (mAllAppsButton != null) {
3336 mAllAppsButton.requestFocus();
3337 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003338 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003339
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003340 // Change the state *after* we've called all the transition code
3341 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003342
Winson Chung5fb63472011-02-02 17:03:37 -08003343 // Resume the auto-advance of widgets
3344 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003345 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003346
Winson Chung0f785722015-04-08 10:27:49 -07003347 if (changed) {
3348 // Send an accessibility event to announce the context change
3349 getWindow().getDecorView()
3350 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003351 }
Winson5c6bdbb2015-09-03 11:36:19 -07003352 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003353 }
3354
Winsone9f27272015-10-13 10:47:51 -07003355 /**
3356 * Shows the overview button.
3357 */
Adam Cohened307df2013-10-02 09:37:31 -07003358 void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003359 showOverviewMode(animated, false);
3360 }
3361
3362 /**
3363 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3364 * onto one of the overview panel buttons.
3365 */
3366 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3367 Runnable postAnimRunnable = null;
3368 if (requestButtonFocus) {
3369 postAnimRunnable = new Runnable() {
3370 @Override
3371 public void run() {
3372 // Hitting the menu button when in touch mode does not trigger touch mode to
3373 // be disabled, so if requested, force focus on one of the overview panel
3374 // buttons.
3375 mOverviewPanel.requestFocusFromTouch();
3376 }
3377 };
3378 }
Adam Cohened307df2013-10-02 09:37:31 -07003379 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003380 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003381 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003382 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003383 }
3384
Winson Chungb745afb2015-03-02 11:51:23 -08003385 /**
3386 * Shows the apps view.
3387 */
Winson Chung76648c52015-07-10 14:33:23 -07003388 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps,
3389 boolean focusSearchBar) {
Winson Chungb745afb2015-03-02 11:51:23 -08003390 if (resetListToTop) {
3391 mAppsView.scrollToTop();
3392 }
Winson Chung4ac30062015-05-08 17:34:17 -07003393 if (updatePredictedApps) {
3394 tryAndUpdatePredictedApps();
3395 }
Winson Chung76648c52015-07-10 14:33:23 -07003396 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003397 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003398
Winson Chungb745afb2015-03-02 11:51:23 -08003399 /**
3400 * Shows the widgets view.
3401 */
3402 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003403 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003404 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003405 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003406 }
Winson Chung76648c52015-07-10 14:33:23 -07003407 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003408
3409 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003410 @Override
3411 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003412 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003413 }
3414 });
Winson Chungb745afb2015-03-02 11:51:23 -08003415 }
3416
3417 /**
3418 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003419 *
3420 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003421 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003422 // TODO: calling method should use the return value so that when {@code false} is returned
3423 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003424 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003425 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3426 mState != State.WIDGETS_SPRING_LOADED) {
3427 return false;
3428 }
3429 if (toState != State.APPS && toState != State.WIDGETS) {
3430 return false;
3431 }
Winson Chungb745afb2015-03-02 11:51:23 -08003432
3433 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003434 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3435 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003436 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003437 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003438 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003439
Michael Jurkab3e22d92011-10-31 15:58:33 -07003440 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003441 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003442
3443 // Pause the auto-advance of widgets until we are out of AllApps
3444 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003445 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003446 closeFolder();
3447
3448 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003449 getWindow().getDecorView()
3450 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003451 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003452 }
3453
Winson Chungcd99cd32015-04-29 11:03:24 -07003454 /**
3455 * Updates the workspace and interaction state on state change, and return the animation to this
3456 * new state.
3457 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003458 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003459 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003460 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003461 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003462 updateInteraction(fromState, toState);
3463 return anim;
3464 }
3465
Jun Mukaif0033da2015-08-04 18:34:30 -07003466 public void onLauncherClingShown() {
3467 // When a launcher cling appears, it should cover the underlying layers, so their focus
3468 // should be blocked.
3469 if (mDragLayer.getDescendantFocusability() != ViewGroup.FOCUS_BLOCK_DESCENDANTS) {
3470 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
3471 }
3472 }
3473
3474 public void onLauncherClingDismissed() {
3475 mDragLayer.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
3476 }
3477
Hyunyoung Song3f471442015-04-08 19:01:34 -07003478 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003479 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003480 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003481 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003482 }
Winson Chungb745afb2015-03-02 11:51:23 -08003483
Winson Chung006ee262015-08-03 14:40:11 -07003484 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003485 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003486 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003487
3488 if (isAppsViewVisible()) {
3489 mState = State.APPS_SPRING_LOADED;
3490 } else if (isWidgetsViewVisible()) {
3491 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003492 } else if (Workspace.IS_SPRING_LOADED) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003493 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003494 } else {
3495 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003496 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003497 }
Adam Cohen7777d962011-08-18 18:58:38 -07003498
Hyunyoung Song3f471442015-04-08 19:01:34 -07003499 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003500 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003501 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003502
Winson Chunge7a03942011-08-05 15:05:12 -07003503 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003504 @Override
3505 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003506 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003507 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3508 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003509 // Before we show workspace, hide all apps again because
3510 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3511 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003512 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003513 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003514 } else {
3515 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003516 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003517 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003518 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003519 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003520
Tony Wickham94e0d372015-09-11 12:17:48 -07003521 private boolean isStateSpringLoaded() {
3522 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3523 || mState == State.WIDGETS_SPRING_LOADED;
3524 }
3525
Michael Jurkad3ef3062010-11-23 16:23:58 -08003526 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003527 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003528 showAppsView(true /* animated */, false /* resetListToTop */,
Winson Chung76648c52015-07-10 14:33:23 -07003529 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003530 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003531 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003532 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3533 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003534 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003535 }
3536
Winson Chung4ac30062015-05-08 17:34:17 -07003537 /**
3538 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3539 * resumed.
3540 */
3541 private void tryAndUpdatePredictedApps() {
3542 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003543 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003544 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003545 mAppsView.setPredictedApps(apps);
3546 }
3547 }
3548 }
3549
Michael Jurkab3e22d92011-10-31 15:58:33 -07003550 void lockAllApps() {
3551 // TODO
3552 }
3553
3554 void unlockAllApps() {
3555 // TODO
3556 }
3557
Sunny Goyal594d76d2014-11-06 10:12:54 -08003558 protected void disableVoiceButtonProxy(boolean disable) {
3559 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003560 }
3561
Winsonf768d932015-09-25 16:12:35 -07003562 public boolean launcherCallbacksProvidesSearch() {
3563 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3564 }
3565
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003566 public View getOrCreateQsbBar() {
Winsonf768d932015-09-25 16:12:35 -07003567 if (launcherCallbacksProvidesSearch()) {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003568 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003569 }
3570
Adam Cohen24ce0b32014-01-14 16:18:14 -08003571 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003572 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3573 if (searchProvider == null) {
3574 return null;
3575 }
3576
3577 Bundle opts = new Bundle();
3578 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003579 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003580
Tony Wickham3a3517f2015-10-06 11:27:04 -07003581 // Determine the min and max dimensions of the widget.
3582 LauncherAppState app = LauncherAppState.getInstance();
3583 DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
3584 DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
3585 float density = getResources().getDisplayMetrics().density;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003586 Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources());
3587 int maxHeight = (int) (searchDimens.y / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003588 int minHeight = maxHeight;
Tony Wickhama3c74d12015-10-23 11:43:47 -07003589 int maxWidth = (int) (searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003590 int minWidth = maxWidth;
3591 if (!landscapeProfile.isVerticalBarLayout()) {
Tony Wickhama3c74d12015-10-23 11:43:47 -07003592 searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources());
3593 maxHeight = (int) Math.max(maxHeight, searchDimens.y / density);
3594 minHeight = (int) Math.min(minHeight, searchDimens.y / density);
3595 maxWidth = (int) Math.max(maxWidth, searchDimens.x / density);
3596 minWidth = (int) Math.min(minWidth, searchDimens.x / density);
Tony Wickham3a3517f2015-10-06 11:27:04 -07003597 }
3598 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
3599 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
3600 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
3601 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
Tony Wickhameef44322015-10-20 13:24:36 -07003602 if (LOGD) {
3603 Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight
3604 + " maxWidth=" + maxWidth + " minWidth=" + minWidth);
3605 }
Tony Wickham3a3517f2015-10-06 11:27:04 -07003606
Tony Wickham775455c2015-10-16 09:49:32 -07003607 if (mLauncherCallbacks != null) {
3608 opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
3609 }
3610
Sunny Goyalf7258242015-10-19 16:59:07 -07003611 int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003612 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003613 if (!searchProvider.provider.flattenToString().equals(
Sunny Goyalf7258242015-10-19 16:59:07 -07003614 mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003615 || (widgetInfo == null)
3616 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003617 // A valid widget is not already bound.
3618 if (widgetId > -1) {
3619 mAppWidgetHost.deleteAppWidgetId(widgetId);
3620 widgetId = -1;
3621 }
3622
3623 // Try to bind a new widget
3624 widgetId = mAppWidgetHost.allocateAppWidgetId();
3625
3626 if (!AppWidgetManagerCompat.getInstance(this)
3627 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3628 mAppWidgetHost.deleteAppWidgetId(widgetId);
3629 widgetId = -1;
3630 }
3631
Sunny Goyalf7258242015-10-19 16:59:07 -07003632 mSharedPrefs.edit()
Sunny Goyal594d76d2014-11-06 10:12:54 -08003633 .putInt(QSB_WIDGET_ID, widgetId)
3634 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
3635 .commit();
3636 }
3637
Sunny Goyal8d595092015-07-06 12:22:14 -07003638 mAppWidgetHost.setQsbWidgetId(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003639 if (widgetId != -1) {
3640 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
Sunny Goyalebfae6e2015-08-27 15:30:25 -07003641 mQsb.setId(R.id.qsb_widget);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003642 mQsb.updateAppWidgetOptions(opts);
3643 mQsb.setPadding(0, 0, 0, 0);
3644 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003645 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003646 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003647 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003648 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003649 }
3650
Sunny Goyal22235bc2015-04-03 09:23:43 -07003651 private void reinflateQSBIfNecessary() {
3652 if (mQsb instanceof LauncherAppWidgetHostView &&
3653 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3654 mSearchDropTargetBar.removeView(mQsb);
3655 mQsb = null;
3656 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3657 }
3658 }
3659
Michael Jurkad7c28052012-04-27 15:43:36 -07003660 @Override
3661 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003662 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003663 final List<CharSequence> text = event.getText();
3664 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003665 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003666 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003667 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003668 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003669 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003670 } else if (mWorkspace != null) {
3671 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003672 } else {
3673 text.add(getString(R.string.all_apps_home_button_label));
3674 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003675 return result;
3676 }
3677
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003678 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003679 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003680 */
Adam Cohen091440a2015-03-18 14:16:05 -07003681 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003682 @Override
3683 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003684 closeSystemDialogs();
3685 }
3686 }
3687
3688 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003689 * If the activity is currently paused, signal that we need to run the passed Runnable
3690 * in onResume.
3691 *
3692 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003693 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3694 * wrong when we're not running, and if the activity comes back to what the configuration was
3695 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003696 *
3697 * Implementation of the method from LauncherModel.Callbacks.
3698 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003699 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003700 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003701 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003702 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003703 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003704 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003705 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003706 }
3707 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003708 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003709 return true;
3710 } else {
3711 return false;
3712 }
3713 }
3714
Michael Jurkac402cd92013-05-20 15:49:32 +02003715 private boolean waitUntilResume(Runnable run) {
3716 return waitUntilResume(run, false);
3717 }
3718
Michael Jurka1e2f4652013-07-08 18:03:46 -07003719 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003720 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003721 }
3722
Michael Jurka7607c2f2013-04-03 14:33:19 -07003723 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003724 * If the activity is currently paused, signal that we need to re-run the loader
3725 * in onResume.
3726 *
3727 * This needs to be called from incoming places where resources might have been loaded
3728 * while we are paused. That is becaues the Configuration might be wrong
3729 * when we're not running, and if it comes back to what it was when we
3730 * were paused, we are not restarted.
3731 *
3732 * Implementation of the method from LauncherModel.Callbacks.
3733 *
3734 * @return true if we are currently paused. The caller might be able to
3735 * skip some work in that case since we will come back again.
3736 */
3737 public boolean setLoadOnResume() {
3738 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003739 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003740 mOnResumeNeedsLoad = true;
3741 return true;
3742 } else {
3743 return false;
3744 }
3745 }
3746
3747 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003748 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003749 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003750 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003751 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003752 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003753 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003754 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003755 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003756 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003757
Joe Onorato9c1289c2009-08-17 11:03:03 -04003758 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003759 * Clear any pending bind callbacks. This is called when is loader is planning to
3760 * perform a full rebind from scratch.
3761 */
3762 @Override
3763 public void clearPendingBinds() {
3764 mBindOnResumeCallbacks.clear();
3765 if (mPendingExecutor != null) {
3766 mPendingExecutor.markCompleted();
3767 mPendingExecutor = null;
3768 }
3769 }
3770
3771 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003772 * Refreshes the shortcuts shown on the workspace.
3773 *
3774 * Implementation of the method from LauncherModel.Callbacks.
3775 */
3776 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003777 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003778
Winson Chungd64d1762013-08-20 14:37:16 -07003779 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003780 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003781 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003782
Michael Jurka05bf644e2011-11-30 20:28:53 -08003783 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003784 if (mHotseat != null) {
3785 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003786 }
3787 }
3788
Adam Cohendcd297f2013-06-18 13:13:40 -07003789 @Override
3790 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003791 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003792
Adam Cohen5084cba2013-09-03 12:01:16 -07003793 // If there are no screens, we need to have an empty screen
3794 if (orderedScreenIds.size() == 0) {
3795 mWorkspace.addExtraEmptyScreen();
3796 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003797
3798 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003799 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003800 if (hasCustomContentToLeft()) {
3801 mWorkspace.createCustomContentContainer();
3802 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003803 }
Winson Chung64359a52013-07-08 17:17:08 -07003804 }
3805
3806 @Override
3807 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003808 int count = orderedScreenIds.size();
3809 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003810 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003811 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003812 }
3813
Winson Chungd64d1762013-08-20 14:37:16 -07003814 public void bindAppsAdded(final ArrayList<Long> newScreens,
3815 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003816 final ArrayList<ItemInfo> addAnimated,
3817 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003818 Runnable r = new Runnable() {
3819 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003820 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003821 }
3822 };
3823 if (waitUntilResume(r)) {
3824 return;
3825 }
3826
Winson Chungd64d1762013-08-20 14:37:16 -07003827 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003828 if (newScreens != null) {
3829 bindAddScreens(newScreens);
3830 }
Winson Chungd64d1762013-08-20 14:37:16 -07003831
3832 // We add the items without animation on non-visible pages, and with
3833 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003834 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003835 bindItems(addNotAnimated, 0,
3836 addNotAnimated.size(), false);
3837 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003838 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003839 bindItems(addAnimated, 0,
3840 addAnimated.size(), true);
3841 }
Winson Chungc58497e2013-09-03 17:48:37 -07003842
Winson Chung87412982013-10-03 18:34:14 -07003843 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003844 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003845
Winson Chungb745afb2015-03-02 11:51:23 -08003846 if (addedApps != null && mAppsView != null) {
3847 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003848 }
Winson Chungd64d1762013-08-20 14:37:16 -07003849 }
3850
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003851 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 * Bind the items start-end from the list.
3853 *
3854 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003855 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003856 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003857 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3858 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003859 Runnable r = new Runnable() {
3860 public void run() {
3861 bindItems(shortcuts, start, end, forceAnimateIcons);
3862 }
3863 };
3864 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003865 return;
3866 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003867
Winson Chungf0c6ae02012-03-21 16:10:31 -07003868 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003869 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3870 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003871 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003872 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003873 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003874 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003875 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003876
3877 // Short circuit if we are loading dock items for a configuration which has no dock
3878 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3879 mHotseat == null) {
3880 continue;
3881 }
3882
Sunny Goyal639e9062015-08-19 19:17:06 -07003883 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003884 switch (item.itemType) {
3885 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3886 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003887 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003888 view = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003889
Winson Chung64359a52013-07-08 17:17:08 -07003890 /*
3891 * TODO: FIX collision case
3892 */
Winson Chungce376632013-07-11 16:12:41 -07003893 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3894 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3895 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003896 View v = cl.getChildAt(item.cellX, item.cellY);
3897 Object tag = v.getTag();
3898 String desc = "Collision while binding workspace item: " + item
3899 + ". Collides with " + tag;
Sunny Goyal6c56c682015-07-16 14:09:05 -07003900 if (ProviderConfig.IS_DOGFOOD_BUILD) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003901 throw (new RuntimeException(desc));
3902 } else {
3903 Log.d(TAG, desc);
3904 }
Winson Chungce376632013-07-11 16:12:41 -07003905 }
Winson Chung64359a52013-07-08 17:17:08 -07003906 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003907 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003908 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003909 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003910 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003911 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003912 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003913 default:
3914 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003915 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003916
3917 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3918 item.cellY, 1, 1);
3919 if (animateIcons) {
3920 // Animate all the applications up now
3921 view.setAlpha(0f);
3922 view.setScaleX(0f);
3923 view.setScaleY(0f);
3924 bounceAnims.add(createNewAppBounceAnimation(view, i));
3925 newShortcutsScreenId = item.screenId;
3926 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003927 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003928
Winson Chung997a9232013-07-24 15:33:46 -07003929 if (animateIcons) {
3930 // Animate to the correct page
3931 if (newShortcutsScreenId > -1) {
3932 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003933 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003934 final Runnable startBounceAnimRunnable = new Runnable() {
3935 public void run() {
3936 anim.playTogether(bounceAnims);
3937 anim.start();
3938 }
3939 };
Winson Chung997a9232013-07-24 15:33:46 -07003940 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003941 // We post the animation slightly delayed to prevent slowdowns
3942 // when we are loading right after we return to launcher.
3943 mWorkspace.postDelayed(new Runnable() {
3944 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003945 if (mWorkspace != null) {
3946 mWorkspace.snapToPage(newScreenIndex);
3947 mWorkspace.postDelayed(startBounceAnimRunnable,
3948 NEW_APPS_ANIMATION_DELAY);
3949 }
Winson Chung94d67682013-09-25 16:29:40 -07003950 }
3951 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003952 } else {
3953 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003954 }
3955 }
Winson Chung64359a52013-07-08 17:17:08 -07003956 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003957 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003958 }
3959
Joe Onorato9c1289c2009-08-17 11:03:03 -04003960 /**
3961 * Implementation of the method from LauncherModel.Callbacks.
3962 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003963 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003964 Runnable r = new Runnable() {
3965 public void run() {
3966 bindFolders(folders);
3967 }
3968 };
3969 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003970 return;
3971 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003972 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003973 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003974
3975 /**
3976 * Add the views for a widget to the workspace.
3977 *
3978 * Implementation of the method from LauncherModel.Callbacks.
3979 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003980 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003981 Runnable r = new Runnable() {
3982 public void run() {
3983 bindAppWidget(item);
3984 }
3985 };
3986 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003987 return;
3988 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003989
Daniel Sandler843e8602010-06-07 14:59:01 -04003990 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3991 if (DEBUG_WIDGETS) {
3992 Log.d(TAG, "bindAppWidget: " + item);
3993 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003994 final Workspace workspace = mWorkspace;
3995
Adam Cohen59400422014-03-05 18:07:04 -08003996 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00003997 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08003998
Sunny Goyal9b4b0812014-10-08 10:47:28 -07003999 if (!mIsSafeModeEnabled
4000 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004001 && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
4002
Sunny Goyalff572272014-07-23 13:58:07 -07004003 if (appWidgetInfo == null) {
4004 if (DEBUG_WIDGETS) {
4005 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4006 + " belongs to component " + item.providerName
4007 + ", as the povider is null");
4008 }
4009 LauncherModel.deleteItemFromDatabase(this, item);
4010 return;
4011 }
Sunny Goyalff572272014-07-23 13:58:07 -07004012
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004013 // If we do not have a valid id, try to bind an id.
4014 if ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0) {
4015 // Note: This assumes that the id remap broadcast is received before this step.
4016 // If that is not the case, the id remap will be ignored and user may see the
4017 // click to setup view.
4018 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
4019 pendingInfo.spanX = item.spanX;
4020 pendingInfo.spanY = item.spanY;
4021 pendingInfo.minSpanX = item.minSpanX;
4022 pendingInfo.minSpanY = item.minSpanY;
4023 Bundle options = null;
4024 WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004025
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004026 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4027 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4028 newWidgetId, appWidgetInfo, options);
4029
4030 // TODO consider showing a permission dialog when the widget is clicked.
4031 if (!success) {
4032 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4033 if (DEBUG_WIDGETS) {
4034 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4035 + " belongs to component " + item.providerName
4036 + ", as the launcher is unable to bing a new widget id");
4037 }
4038 LauncherModel.deleteItemFromDatabase(this, item);
4039 return;
Sunny Goyalff572272014-07-23 13:58:07 -07004040 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07004041
4042 item.appWidgetId = newWidgetId;
4043
4044 // If the widget has a configure activity, it is still needs to set it up, otherwise
4045 // the widget is ready to go.
4046 item.restoreStatus = (appWidgetInfo.configure == null)
4047 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4048 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4049
4050 LauncherModel.updateItemInDatabase(this, item);
4051 } else if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0)
4052 && (appWidgetInfo.configure == null)) {
4053 // If the ID is already valid, verify if we need to configure or not.
4054 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4055 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07004056 }
Sunny Goyalff572272014-07-23 13:58:07 -07004057 }
4058
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004059 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004060 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004061 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004062 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4063 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004064 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004065
Sunny Goyal56c73602015-09-25 12:55:01 -07004066 // Verify that we own the widget
4067 AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4068 if (info == null || appWidgetInfo == null ||
4069 !info.provider.equals(appWidgetInfo.provider)) {
4070 Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
4071 deleteWidgetInfo(item);
4072 return;
4073 }
4074
Sunny Goyal651077b2014-06-30 14:15:31 -07004075 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Sunny Goyal233ee962015-08-03 13:05:01 -07004076 item.minSpanX = appWidgetInfo.minSpanX;
4077 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal651077b2014-06-30 14:15:31 -07004078 } else {
4079 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004080 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4081 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004082 view.updateIcon(mIconCache);
4083 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004084 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004085 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004086 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004087
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07004088 addAppWidgetToWorkspace(item, appWidgetInfo, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004089 workspace.requestLayout();
4090
Daniel Sandler843e8602010-06-07 14:59:01 -04004091 if (DEBUG_WIDGETS) {
4092 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4093 + (SystemClock.uptimeMillis()-start) + "ms");
4094 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004095 }
4096
Sunny Goyalff572272014-07-23 13:58:07 -07004097 /**
4098 * Restores a pending widget.
4099 *
4100 * @param appWidgetId The app widget id
4101 * @param cellInfo The position on screen where to create the widget.
4102 */
4103 private void completeRestoreAppWidget(final int appWidgetId) {
4104 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4105 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4106 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4107 return;
4108 }
4109
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004110 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004111 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4112
4113 mWorkspace.reinflateWidgetsIfNecessary();
4114 LauncherModel.updateItemInDatabase(this, info);
4115 }
4116
Adam Cohen1462de32012-07-24 22:34:36 -07004117 public void onPageBoundSynchronously(int page) {
4118 mSynchronouslyBoundPages.add(page);
4119 }
4120
Sunny Goyal527c7d32015-08-28 15:19:36 -07004121 @Override
4122 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4123 if (mPendingExecutor != null) {
4124 mPendingExecutor.markCompleted();
4125 }
4126 mPendingExecutor = executor;
4127 executor.attachTo(this);
4128 }
4129
4130 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4131 if (mPendingExecutor == executor) {
4132 mPendingExecutor = null;
4133 }
4134 }
4135
Joe Onorato9c1289c2009-08-17 11:03:03 -04004136 /**
4137 * Callback saying that there aren't any more items to bind.
4138 *
4139 * Implementation of the method from LauncherModel.Callbacks.
4140 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004141 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004142 Runnable r = new Runnable() {
4143 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004144 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004145 }
4146 };
4147 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004148 return;
4149 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004150 if (mSavedState != null) {
4151 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004152 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004153 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004154 mSavedState = null;
4155 }
4156
Adam Cohen1462de32012-07-24 22:34:36 -07004157 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004158
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004159 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004160 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004161
4162 // If we received the result of any pending adds while the loader was running (e.g. the
4163 // widget configuration forced an orientation change), process them now.
4164 if (sPendingAddItem != null) {
4165 final long screenId = completeAdd(sPendingAddItem);
4166
4167 // TODO: this moves the user to the page where the pending item was added. Ideally,
4168 // the screen would be guaranteed to exist after bind, and the page would be set through
4169 // the workspace restore process.
4170 mWorkspace.post(new Runnable() {
4171 @Override
4172 public void run() {
4173 mWorkspace.snapToScreenId(screenId);
4174 }
4175 });
4176 sPendingAddItem = null;
4177 }
4178
Sunny Goyal756adbc2015-04-16 15:20:51 -07004179 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004180
4181 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004182 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004183 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004184 }
4185
Adam Cohen3ed316a2014-07-23 18:21:20 -07004186 private void sendLoadingCompleteBroadcastIfNecessary() {
4187 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4188 String permission =
4189 getResources().getString(R.string.receive_first_load_broadcast_permission);
4190 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4191 sendBroadcast(intent, permission);
4192 SharedPreferences.Editor editor = mSharedPrefs.edit();
4193 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4194 editor.apply();
4195 }
4196 }
4197
Winson Chunga0b7e862013-09-05 16:03:15 -07004198 public boolean isAllAppsButtonRank(int rank) {
4199 if (mHotseat != null) {
4200 return mHotseat.isAllAppsButtonRank(rank);
4201 }
4202 return false;
4203 }
4204
Winson Chunga2413752012-04-03 14:22:34 -07004205 private boolean canRunNewAppsAnimation() {
4206 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Sunny Goyal639e9062015-08-19 19:17:06 -07004207 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000)
4208 && (mClings == null || !mClings.isVisible());
Winson Chunga2413752012-04-03 14:22:34 -07004209 }
4210
Winson Chungc9168342013-06-26 14:54:55 -07004211 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004212 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004213 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4214 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004215 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004216 return bounceAnim;
4217 }
4218
Adam Cohen27772732013-11-11 14:00:56 +00004219 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004220 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004221 }
4222
Tony Wickham3a3517f2015-10-06 11:27:04 -07004223 /** Returns the search bar bounds in pixels. */
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004224 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004225 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004226 }
4227
Tony Wickham55616cd2015-09-23 14:55:17 -07004228 public int getSearchBarHeight() {
4229 if (mLauncherCallbacks != null) {
4230 return mLauncherCallbacks.getSearchBarHeight();
4231 }
4232 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4233 }
4234
Winson Chung88fa7412015-08-03 14:25:28 -07004235 public void bindSearchProviderChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004236 if (mSearchDropTargetBar == null) {
4237 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004238 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004239 if (mQsb != null) {
4240 mSearchDropTargetBar.removeView(mQsb);
4241 mQsb = null;
4242 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004243 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004244 }
4245
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004246 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004247 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4248 * multiple calls to bind the same list.)
4249 */
4250 @Thunk ArrayList<AppInfo> mTmpAppsList;
4251 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4252 public void run() {
4253 bindAllApplications(mTmpAppsList);
4254 mTmpAppsList = null;
4255 }
4256 };
4257
4258 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004259 * Add the icons for all apps.
4260 *
4261 * Implementation of the method from LauncherModel.Callbacks.
4262 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004263 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004264 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4265 mTmpAppsList = apps;
4266 return;
4267 }
4268
Winson Chungb745afb2015-03-02 11:51:23 -08004269 if (mAppsView != null) {
4270 mAppsView.setApps(apps);
4271 }
Adam Cohen9211d422014-10-07 18:14:53 -07004272 if (mLauncherCallbacks != null) {
4273 mLauncherCallbacks.bindAllApplications(apps);
4274 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004275 }
4276
4277 /**
4278 * A package was updated.
4279 *
4280 * Implementation of the method from LauncherModel.Callbacks.
4281 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004282 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004283 Runnable r = new Runnable() {
4284 public void run() {
4285 bindAppsUpdated(apps);
4286 }
4287 };
4288 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004289 return;
4290 }
4291
Winson Chungb745afb2015-03-02 11:51:23 -08004292 if (mAppsView != null) {
4293 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004294 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004295 }
4296
Sunny Goyal4390ace2014-10-13 11:33:11 -07004297 @Override
4298 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4299 Runnable r = new Runnable() {
4300 public void run() {
4301 bindWidgetsRestored(widgets);
4302 }
4303 };
4304 if (waitUntilResume(r)) {
4305 return;
4306 }
4307 mWorkspace.widgetsRestored(widgets);
4308 }
4309
Joe Onorato9c1289c2009-08-17 11:03:03 -04004310 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004311 * Some shortcuts were updated in the background.
4312 *
4313 * Implementation of the method from LauncherModel.Callbacks.
4314 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004315 @Override
4316 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4317 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004318 Runnable r = new Runnable() {
4319 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004320 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004321 }
4322 };
4323 if (waitUntilResume(r)) {
4324 return;
4325 }
4326
Sunny Goyal4390ace2014-10-13 11:33:11 -07004327 if (!updated.isEmpty()) {
4328 mWorkspace.updateShortcuts(updated);
4329 }
4330
4331 if (!removed.isEmpty()) {
4332 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4333 for (ShortcutInfo si : removed) {
4334 removedComponents.add(si.getTargetComponent());
4335 }
4336 mWorkspace.removeItemsByComponentName(removedComponents, user);
4337 // Notify the drag controller
4338 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004339 }
4340 }
4341
4342 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004343 * Update the state of a package, typically related to install state.
4344 *
4345 * Implementation of the method from LauncherModel.Callbacks.
4346 */
Sunny Goyale755d462014-07-22 13:48:29 -07004347 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004348 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4349 Runnable r = new Runnable() {
4350 public void run() {
4351 bindRestoreItemsChange(updates);
4352 }
4353 };
4354 if (waitUntilResume(r)) {
4355 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004356 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004357
Sunny Goyal756adbc2015-04-16 15:20:51 -07004358 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004359 }
4360
4361 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004362 * A package was uninstalled. We take both the super set of packageNames
4363 * in addition to specific applications to remove, the reason being that
4364 * this can be called when a package is updated as well. In that scenario,
4365 * we only remove specific components from the workspace, where as
4366 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004367 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004368 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004369 * Implementation of the method from LauncherModel.Callbacks.
4370 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004371 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004372 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004373 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004374 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004375 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004376 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004377 }
Winson Chungd64d1762013-08-20 14:37:16 -07004378 };
4379 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004380 return;
4381 }
4382
Sunny Goyal1a745e82014-10-02 15:58:31 -07004383 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004384 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4385 for (AppInfo info : appInfos) {
4386 removedComponents.add(info.componentName);
4387 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004388 if (!packageNames.isEmpty()) {
4389 mWorkspace.removeItemsByPackageName(packageNames, user);
4390 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004391 if (!removedComponents.isEmpty()) {
4392 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004393 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004394 // Notify the drag controller
4395 mDragController.onAppsRemoved(packageNames, removedComponents);
4396
Sunny Goyal1a745e82014-10-02 15:58:31 -07004397 } else {
4398 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004399 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004400
Winson Chungdf95eb12013-10-16 14:57:07 -07004401 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004402 if (mAppsView != null) {
4403 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004404 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004405 }
Joe Onoratobe386092009-11-17 17:32:16 -08004406
Michael Jurkac402cd92013-05-20 15:49:32 +02004407 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004408 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004409 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004410 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004411 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004412
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004413 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004414 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004415 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004416 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004417 return;
4418 }
4419
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004420 if (mWidgetsView != null && model != null) {
4421 mWidgetsView.addWidgets(model);
4422 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004423 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004424 }
4425
Winson Chung400438b2011-01-16 17:53:48 -08004426 private int mapConfigurationOriActivityInfoOri(int configOri) {
4427 final Display d = getWindowManager().getDefaultDisplay();
4428 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4429 switch (d.getRotation()) {
4430 case Surface.ROTATION_0:
4431 case Surface.ROTATION_180:
4432 // We are currently in the same basic orientation as the natural orientation
4433 naturalOri = configOri;
4434 break;
4435 case Surface.ROTATION_90:
4436 case Surface.ROTATION_270:
4437 // We are currently in the other basic orientation to the natural orientation
4438 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4439 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4440 break;
4441 }
4442
4443 int[] oriMap = {
4444 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4445 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4446 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4447 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4448 };
4449 // Since the map starts at portrait, we need to offset if this device's natural orientation
4450 // is landscape.
4451 int indexOffset = 0;
4452 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4453 indexOffset = 1;
4454 }
4455 return oriMap[(d.getRotation() + indexOffset) % 4];
4456 }
Adam Cohen446e9402011-09-15 18:21:21 -07004457
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004458 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004459 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004460 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004461 if (Utilities.ATLEAST_JB_MR2) {
4462 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4463 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004464 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4465 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004466 }
Winson Chung4b919f82012-05-01 10:44:08 -07004467 }
4468 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004469
Winson Chung4b919f82012-05-01 10:44:08 -07004470 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004471 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004472 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004473 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004474 } else {
4475 mHandler.postDelayed(new Runnable() {
4476 public void run() {
4477 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4478 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004479 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004480 }
Winson Chung4b919f82012-05-01 10:44:08 -07004481 }
Winson Chung400438b2011-01-16 17:53:48 -08004482 }
4483
Winson Chunge43a1e72014-01-15 10:33:02 -08004484 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004485 if (mLauncherCallbacks != null) {
4486 return mLauncherCallbacks.isLauncherPreinstalled();
4487 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004488 PackageManager pm = getPackageManager();
4489 try {
4490 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4491 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4492 return true;
4493 } else {
4494 return false;
4495 }
4496 } catch (NameNotFoundException e) {
4497 e.printStackTrace();
4498 return false;
4499 }
4500 }
4501
Adam Cohenea90f832014-05-21 15:03:34 -07004502 /**
4503 * This method indicates whether or not we should suggest default wallpaper dimensions
4504 * when our wallpaper cropper was not yet used to set a wallpaper.
4505 */
4506 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004507 if (mLauncherCallbacks != null) {
4508 return mLauncherCallbacks.overrideWallpaperDimensions();
4509 }
Adam Cohenea90f832014-05-21 15:03:34 -07004510 return true;
4511 }
4512
Adam Cohen432609a2014-03-13 17:03:22 -07004513 /**
4514 * To be overridden by subclasses to indicate that there is an activity to launch
4515 * before showing the standard launcher experience.
4516 */
4517 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004518 if (mLauncherCallbacks != null) {
4519 return mLauncherCallbacks.hasFirstRunActivity();
4520 }
Adam Cohen432609a2014-03-13 17:03:22 -07004521 return false;
4522 }
4523
4524 /**
4525 * To be overridden by subclasses to launch any first run activity
4526 */
4527 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004528 if (mLauncherCallbacks != null) {
4529 return mLauncherCallbacks.getFirstRunActivity();
4530 }
Adam Cohen432609a2014-03-13 17:03:22 -07004531 return null;
4532 }
4533
Winson Chunga6945242014-01-08 14:04:34 -08004534 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004535 return !ActivityManager.isRunningInTestHarness() &&
4536 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004537 }
4538
Adam Cohen4a9423d2014-03-28 14:22:31 -07004539 protected boolean hasRunFirstRunActivity() {
4540 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4541 }
4542
Adam Cohen432609a2014-03-13 17:03:22 -07004543 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004544 if (shouldRunFirstRunActivity() &&
4545 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004546 Intent firstRunIntent = getFirstRunActivity();
4547 if (firstRunIntent != null) {
4548 startActivity(firstRunIntent);
4549 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004550 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004551 }
4552 }
Adam Cohen432609a2014-03-13 17:03:22 -07004553 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004554 }
4555
4556 private void markFirstRunActivityShown() {
4557 SharedPreferences.Editor editor = mSharedPrefs.edit();
4558 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4559 editor.apply();
4560 }
4561
Adam Cohen432609a2014-03-13 17:03:22 -07004562 /**
4563 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4564 * screen that must be displayed and dismissed.
4565 */
4566 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004567 if (mLauncherCallbacks != null) {
4568 return mLauncherCallbacks.hasDismissableIntroScreen();
4569 }
Adam Cohen432609a2014-03-13 17:03:22 -07004570 return false;
4571 }
4572
4573 /**
4574 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4575 */
4576 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004577 if (mLauncherCallbacks != null) {
4578 return mLauncherCallbacks.getIntroScreen();
4579 }
Adam Cohen432609a2014-03-13 17:03:22 -07004580 return null;
4581 }
4582
4583 /**
4584 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4585 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4586 */
4587 private boolean shouldShowIntroScreen() {
4588 return hasDismissableIntroScreen() &&
4589 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4590 }
4591
4592 protected void showIntroScreen() {
4593 View introScreen = getIntroScreen();
4594 changeWallpaperVisiblity(false);
4595 if (introScreen != null) {
4596 mDragLayer.showOverlayView(introScreen);
4597 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004598 if (mLauncherOverlayContainer != null) {
4599 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4600 }
Adam Cohen432609a2014-03-13 17:03:22 -07004601 }
4602
4603 public void dismissIntroScreen() {
4604 markIntroScreenDismissed();
4605 if (showFirstRunActivity()) {
4606 // We delay hiding the intro view until the first run activity is showing. This
4607 // avoids a blip.
4608 mWorkspace.postDelayed(new Runnable() {
4609 @Override
4610 public void run() {
4611 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004612 if (mLauncherOverlayContainer != null) {
4613 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4614 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004615 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004616 }
4617 }, ACTIVITY_START_DELAY);
4618 } else {
4619 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004620 if (mLauncherOverlayContainer != null) {
4621 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4622 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004623 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004624 }
4625 changeWallpaperVisiblity(true);
4626 }
4627
4628 private void markIntroScreenDismissed() {
4629 SharedPreferences.Editor editor = mSharedPrefs.edit();
4630 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4631 editor.apply();
4632 }
4633
Adam Cohen091440a2015-03-18 14:16:05 -07004634 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004635 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4636 // on the device, then we always show the first run cling experience (or if there is no
4637 // launcher2). Otherwise, we prompt the user upon started for migration
4638 LauncherClings launcherClings = new LauncherClings(this);
4639 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Sunny Goyal639e9062015-08-19 19:17:06 -07004640 mClings = launcherClings;
Sunny Goyal88d60f12014-09-08 03:47:29 -07004641 if (mModel.canMigrateFromOldLauncherDb(this)) {
4642 launcherClings.showMigrationCling();
4643 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004644 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004645 }
4646 }
4647 }
4648
Winson Chunga6945242014-01-08 14:04:34 -08004649 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004650 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4651 if (mHotseat != null) mHotseat.setAlpha(1f);
4652 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
Winson Chung006ee262015-08-03 14:40:11 -07004653 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4654 SearchDropTargetBar.State.SEARCH_BAR, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004655 }
4656
4657 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004658 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4659 if (mHotseat != null) mHotseat.setAlpha(0f);
4660 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
Winson Chung006ee262015-08-03 14:40:11 -07004661 if (mSearchDropTargetBar != null) mSearchDropTargetBar.animateToState(
4662 SearchDropTargetBar.State.INVISIBLE, 0);
Winson Chunga6945242014-01-08 14:04:34 -08004663 }
4664
Winson Chung5ffd51d2015-06-25 11:36:50 -07004665 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004666 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004667 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004668 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004669 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004670 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004671 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4672 if (userHandle != null) {
4673 user = UserHandleCompat.fromUser(userHandle);
4674 }
4675 }
4676 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004677 }
4678
4679 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004680 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004681 if (user == null) {
4682 user = UserHandleCompat.myUserHandle();
4683 }
4684
4685 // Called from search suggestion, add the profile extra to the intent to ensure that we
4686 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004687 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004688 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004689 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004690 return null;
4691 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004692 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004693 }
4694
Winson Chung5ffd51d2015-06-25 11:36:50 -07004695 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004696 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4697 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004698 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004699 UserHandleCompat.myUserHandle());
4700 }
4701
Winson Chung5ffd51d2015-06-25 11:36:50 -07004702 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004703 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4704 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004705 mWorkspace.onExternalDragStartedWithItem(dragView);
4706 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004707 }
4708
Winson Chung5ffd51d2015-06-25 11:36:50 -07004709 protected void moveWorkspaceToDefaultScreen() {
4710 mWorkspace.moveToDefaultScreen(false);
4711 }
4712
Anjali Koppalf5d29132014-02-28 13:33:27 -08004713 @Override
4714 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004715 if (mLauncherCallbacks != null) {
4716 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4717 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004718 }
4719
Winson Chung80baf5a2010-08-09 16:03:15 -07004720 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004721 * Returns a FastBitmapDrawable with the icon, accurately sized.
4722 */
4723 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4724 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4725 d.setFilterBitmap(true);
4726 resizeIconDrawable(d);
4727 return d;
4728 }
4729
4730 /**
4731 * Resizes an icon drawable to the correct icon size.
4732 */
Winson5fbe0742015-09-30 15:33:00 -07004733 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004734 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004735 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004736 }
4737
4738 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004739 * Prints out out state for debugging.
4740 */
4741 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004742 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004743 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004744 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4745 Log.d(TAG, "mRestoring=" + mRestoring);
4746 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004747 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004748 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004749 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004750
Daniel Sandler325dc232013-06-05 22:57:57 -04004751 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004752 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004753
4754 @Override
4755 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4756 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004757 // Dump workspace
4758 writer.println(prefix + "Workspace Items");
4759 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4760 writer.println(prefix + " Homescreen " + i);
4761
4762 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4763 for (int j = 0; j < layout.getChildCount(); j++) {
4764 Object tag = layout.getChildAt(j).getTag();
4765 if (tag != null) {
4766 writer.println(prefix + " " + tag.toString());
4767 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004768 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004769 }
Sunny Goyala1365452015-10-01 15:46:24 -07004770
4771 writer.println(prefix + " Hotseat");
4772 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4773 for (int j = 0; j < layout.getChildCount(); j++) {
4774 Object tag = layout.getChildAt(j).getTag();
4775 if (tag != null) {
4776 writer.println(prefix + " " + tag.toString());
4777 }
4778 }
4779
4780 synchronized (sDumpLogs) {
4781 writer.println();
4782 writer.println(prefix + "Debug logs");
4783 for (String log : sDumpLogs) {
4784 writer.println(prefix + " " + log);
4785 }
4786 }
4787
Adam Cohen9211d422014-10-07 18:14:53 -07004788 if (mLauncherCallbacks != null) {
4789 mLauncherCallbacks.dump(prefix, fd, writer, args);
4790 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004791 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004792
Sunny Goyala1365452015-10-01 15:46:24 -07004793 public static void addDumpLog(String tag, String log) {
4794 Log.d(tag, log);
4795 synchronized(sDumpLogs) {
Winson Chungede41292013-09-19 16:27:36 -07004796 sDateStamp.setTime(System.currentTimeMillis());
Sunny Goyala1365452015-10-01 15:46:24 -07004797 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Winson Chungede41292013-09-19 16:27:36 -07004798 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004799 }
4800
Adam Cohen59400422014-03-05 18:07:04 -08004801 public static CustomAppWidget getCustomAppWidget(String name) {
4802 return sCustomAppWidgets.get(name);
4803 }
4804
4805 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4806 return sCustomAppWidgets;
4807 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004808}
Michael Jurka2763be32011-02-24 11:19:57 -08004809
Dan Sandlerd5024042014-01-09 15:01:33 -05004810interface DebugIntents {
4811 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4812 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004813}